nagios监控服务器 安装配置方法


NAGIOS服务端安装

一、 主软件包:

1. nagios-3.0.x.tar.gz 主程序

2. nagios-plugins-1.4.x.tar.gz 插件

3. nrpe_2.8.x.tar.gz 外部构件

4. pnp -0.4.X 图形化工具

二、基本安装:

软件包准备:

服务端安装:

rpm -q gcc glibc glibc-common gd gd-devel xinetd openssl-devel httpd

安装步骤:

2.1 建立账号:

useradd nagios

passwd nagios

usermod -G nagios nagios

usermod -G nagios apache

2.2 安装nagios-3.0.x.tar.gz

./configure (不用跟参数,默认安装在/usr/local/nagios)

配置完毕按照提示安装

make all

====================

make install

====================

make install-init

====================

make install-config

====================

make install-commandmode

====================

make install-webconf #针对rpm版apache,source包apache配置见下 ====================

设置收信人地址

vi /usr/local/nagios/etc/objects/contacts.cfg

更改email地址nagiosadmin的联系人定义信息中的EMail信息为你的EMail信息以接收报警内容.

/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin

输入密码(这一步很重要)

2.3安装Nagios插件

2.3.1 nagios-plugins-1.4.X.tar.gz

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make

make install

chkconfig --add nagios

chkconfig nagios on

2.3.2 nrpe_2.8.x.tar.gz

./configure

make all

make install-plugins

make install-daemon

make install-daemon-config

make install-xinetd

三、 详细配置:

3.1 主机定义:

vi /usr/local/nagios/etc/objects/hosts.cfg

基本模板:

define host{

use linux-server # nagios server-name

host_name 主机名

alias 别名

address X.X.X

}

例:

define host {

host_name CentOS

use linux-server,host-pnp

alias nagios server

address 192.168.1.44

contact_groups nagcmd

check_command check-host-alive

max_check_attempts 5

notification_interval 10

notification_period 24x7

notification_options d,u,r

}

3.2 主机组定义:

vi /usr/local/nagios/etc/objects/hostgroup.cfg

基本模板:

define hostgroup{

hostgroup_name 组名

alias PAY-web

members 主机名1, 主机名2 # 须是定义过的

}

3.3 服务定义:

define service{

use generic-service ; Name of service template to use

hostgroup_name 主机组1, 主机组2

service_description Swap Usage

check_command check_nrpe!check_swap

}

例:define service {

host_name CentOS

use local-service,srv-pnp

service_description CPU

check_period 24x7

max_check_attempts 4

normal_check_interval 1

retry_check_interval 1

contact_groups nagcmd

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

check_command check_nrpe!check_cpu

}

四、 NAGIOS的图形化(PNP)

#基于LAMP平台

PNP 是基于PHP和PERL,利用rrdtool将Nagios采集的数据绘制成图表

软件包列表:

Perl

rrdtool 1.2.*

pnp-0.3.3.tar.gz

4.1 安装rrdtool-1.4.4.*

tar –xvf rrdtool-1.4.4*

./configure 进行配置 –-prefix=/usr/local/rrdtool

make;make install 然后再编译和安装

ls /usr/local/rrdtool-1.4.4.* 查看安装目录是否有

应该有这些目录才正至此rrdtool安装成功

4.2 安装pnp

tar xzvf pnp-X.r.gz 将pnp进行解压

cd pnp-X 进入pnp 目录

./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata/

make all

make install

make install-config

4.2.1 相关设置

首先要将Nagios的主配置文件nagios.cfg中相关的配置修改:

process_performance_data=1

service_perfdata_command=process-service-perfdata #默认此句被注释掉了

如果想要对某个监控对象做数据图表,则需在所对应的host或者service定义中(一般写在hosts.cfg或者services.cfg文件中),包含如下的定义:

process_perf_data 1

4.3 访问图表

http://IP/nagios/pnp/

这样访问比较麻烦

在服务、主机中添加

1. 在object 目录里commands.cfg定义这两个命令:

# 'process-host-perfdata' command definition

define command{

command_name process-host-perfdata

#command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$t$HOSTNAME$t$HOSTSTATE$t$HOSTATTEMPT$t$HOSTSTATETYPE$t$HOSTEXECUTIONTIME$t$HOSTOUTPUT$t$HOSTPERFDATA$n">>/usr/local/nagios/var/host-perfdata.out

command_line /usr/local/nagios/libexec/process_perfdata.pl

}

# 'process-service-perfdata' command definition

define command{

command_name process-service-perfdata

# command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$t$HOSTNAME$t$SERVICEDESC$t$SERVICESTATE$t$SERVICEATTEMPT$t$SERVICESTATETYPE$t$SERVICEEXECUTIONTIME$t$SERVICELATENCY$t$SERVICEOUTPUT$t$SERVICEPERFDATA$n" >> /usr/local/nagios/var/service-perfdata.out

command_line /usr/local/nagios/libexec/process_perfdata.pl

}

然后在hosts.cfg和services.cfg里面添加host-pnp, srv-pnp

添加之后重启nagios,然后到web下就可以看到

本文出自 “huangyu学习博客” 博客


相关链接