监控linux 主机
下载NRPE
http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
请先安装openssl 最好用yum [服务器和linux客户端都需要]
yum –y install openssl openssl-devel
否则会完成不了ssl 握手
1. 在nagios服务器端安装NRPE,
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --enable-ssl --with-ssl-lib
make all && make install-plugin && make install-daemon && make install-daemon-config
配置nrpe
#在commands.cfg中定义nrpe这个外部构件
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$
}
2.在nagios客户端安装NRPE,
/usr/sbin/useradd nagios
passwd nagios
安装插件9
tar -zxzf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios
make && make install
chown nagios.nagios /usr/local/nagios/
chown -R nagios.nagios /usr/local/nagios/libexec/
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
cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/bin
Vi /usr/local/nagios/etc/nrpe.cfg
修改nrpe.cfg allow_hosts 加上nagios服务器IP
启动NRPE
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
vi /etc/rc.local
可以把以上命令写入rc.local,开机自动启动,(vi /etc/rc.local)当然,要开放5666端口
3.验证
在被监控端/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.12
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
CHECK_NRPE: Error - Could not complete SSL handshake.
此时出现此错误表明客户端没有安装openssl 不能完成ssl握手
Connection refused by host
Nrpe进程没有启动
参考此链接http://www.588k.com/?p=36
在nagios服务器端
[root@nagios objects]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.44 此处填写客户端ip地址
NRPE v2.12
返回NRPE版本号,测试成功
测试不成功,下面就不要进行了
4.监控
在 /usr/local/nagios/etc/ 下新建servers目录,在该目录下新建一个被监控端主机的配置文件mylinux.cfg
vi /usr/local/nagios/etc/nagios.cfg 在linux 部分添加一行
cfg_file=/usr/local/nagios/etc/mylinux.cfg
文件位置并不重要,也可以放在/etc/object/下,注意要和nagios.cfg里面的路径一致即可
改变文件属组为nagios
Chown –R nagios.nagios /usr/local/nagios/etc/mylinux.cfg
复制如下配置文件到此文件中
define host{
use linux-server
host_name xxxhotel
alias xxxhotel
address 192.168.1.4
max_check_attempts 5
}
define service{
use generic-service
host_name xxxhotel
service_description HTTP
check_command check_http
}
监控linux的地址及相关的服务,
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
查看有没有错误报警,有可能是没有定义服务之类
Service nagios restart
重启nagios服务
到web页面查看效果
如果监控更多的服务如httpd ssh等等的话,只需要在配置文件中做相应的添加即可
更多请参考官方配置文档
http://nagios.sourceforge.net/docs/3_0/monitoring-publicservices.html