Nagios监控-Linux客户端的配置

一、实验环境

监控服务器(nagios服务器--192.168.1.3)
CentOS5.5(64位) + nagios-3.2.3 + nagios-plugins-1.4.15 + nrpe-2.12

被监控客户端(linux客户端--192.168.1.188)
CentOS5.5(64位) + nagios-plugins-1.4.15 + nrpe-2.12
二、nrpe插件
1、nrpe插件的组成
NRPE总共由两部分组成:
(1)check_nrpe:它是运行在监控主机上
(2)NRPE daemon:它是运行在远程的linux主机上(通常就是被监控机)

2、nrpe的工作原理

当Nagios需要监控某个远程linux主机的服务或者资源情况时
第一步:nagios服务器运行check_nrpe插件,我们要在nagios配置文件中告诉它要检查什么
第二步:check_nrpe插件会通过SSL连接到远程的被监控的Linux客户端上的NRPE daemon
第三步:被监控的Linux客户端上的NRPE daemon会运行相应的nagios插件来执行检查本地资源或服务
第四步:被监控的Linux客户端上的NRPE daemon的NRPE daemon将检查的结果返回给check_nrpe插件,插件将其递交给进行nagios做处理
注意:NRPE daemon需要nagios-plugin插件安装在远程被监控linux主机上,否则NRPE daemon不能做任何的监控;别外因为它们间的通信是加密的SSL,所以在编译安装时都要加上选项:/configure --enable-ssl --with-ssl-lib=/lib/,否则会出错

三、配置被监控的Linux主机(Linux客户端)

1、安装所需的软件(nagios-plugins、nrpe)
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
1)安装nagios-plugins
#增加一个用户
useradd nagios
passwd nagios
#解压并安装
tar zvxf nagios-plugins-1.4.15.tar.gz && cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios && make && make install
chown -R nagios:nagios /usr/local/nagios
2)安装nrpe
tar -zxvf nrpe-2.12.tar.gz && cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib (前提是已经安装了openssl与openssl-devel)
make all && make install-plugin && make install-daemon && make install-daemon-config
3)配置nrpe
#配置nrpe信息
vi /usr/local/nagios/etc/nrpe.cfg,查找并修改如下一行
allowed_hosts=192.168.1.3,127.0.0.1   #注意修改为nagios服务器的IP:192.168.1.3
#配置监控对象
说明:由监控原理可知被监控端做监控,然后将数据传给监控服务器绘总,设置监控详细参数主要是设置被监控端的nrpe.cfg文件,可以看到里面监控对象
vi /usr/local/nagios/etc/nrpe.cfg,查找并修改如下一行
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 10% -c 5%
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 500 -c 550
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_ping]=/usr/local/nagios/libexec/check_ping -H 192.168.1.1 -w 100.0,20% -c 500.0,60%
............................................#自已添加.......................................................... 
#command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1 -w 10 -c 20
#command[check_ssh]=/usr/local/nagios/libexec/check_ssh -4 127.0.0.1

4)启动nrpe,并测试
启动:/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
添加启动:echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d &> /dev/null' >> /etc/rc.local
检查nrpe是否启动:netstat -atulnp | grep 'nrpe'
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      3308/nrpe
检查nrpe版本:/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12
5)nrpe常见故障
错误一:/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
CHECK_NRPE: Error - Could not complete SSL handshake
解析办法:配置allowed_hosts=192.168.1.3,127.0.0.1,然后kill进程再重启就OK了
错误二:/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
Connection refused by host
解析办法:Nrpe进程没有启动
四、配置监控服务器(Nagios服务器)
1、安装所需的软件(nagios、nagios-plugins、nrpe)
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
2、安装nagios与nagios-plugins
1)nagios与nagios-plugins的安装
查看:http://hi.baidu.com/9812658/blog/item/ae3632edd4f5afe2ce1b3e0e.html
2)安装nrpe
tar -zxvf nrpe-2.12.tar.gz && cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib (前提是已经安装了openssl与openssl-devel)
make all && make install-plugin && make install-daemon && make install-daemon-config
3)配置nrpe
#在commands.cfg中定义nrpe这个外部构件
vi /usr/local/nagios/etc/nagios.cfg,打开下面这一行
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
vi /usr/local/nagios/etc/objects/commands.cfg,增加如下一行
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
#配置要监控的linux主机
vi /usr/local/nagios/etc/nagios.cfg,加入如下一行
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
touch  /usr/local/nagios/etc/objects/mylinux.cfg,增加如下内容
define host{
use         linux-server
host_name   mylinux
alias       mylinux
address     192.168.1.188
}
define service{
use                 generic-service #使用的是/usr/local/nagios /etc/objects/templates.cfg中所定义的
host_name           mylinux
service_description Swap Usage
check_command       check_nrpe!check_swap
}
define service{
use                 generic-service
host_name           mylinux
service_description Current Load
check_command       check_nrpe!check_load
}
define service{
use                 generic-service
host_name           mylinux
service_description Partition Usage
check_command       check_nrpe!check_disk
}
define service{
use                 generic-service
host_name           mylinux
service_description Current Users  
check_command       check_nrpe!check_users
}
define service{
use                 generic-service
host_name           mylinux
service_description Total Processes
check_command       check_nrpe!check_total_procs
}
define service{
use                 generic-service
host_name           mylinux
service_description PING
check_command       check_nrpe!check_ping
}
5)启动nrpc,并测试
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d &> /dev/null' >> /etc/rc.local
netstat -atulnp | grep 'nrpe'
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      3308/nrpe
/usr/local/nagios/libexec/check_nrpe -H 192.168.1.188   #linux客户端的IP地址:192.168.1.188
NRPE v2.12
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart
http://nagios_ip_address/nagios

你可能感兴趣的:(linux,服务器,客户端,nagios,休闲)