在被监控服务器(Linux/unix)上安装Nagios-plugins和nrpe
1、添加用户
1 2 | ; html-script: false ]/usr/sbin/useradd -m nagios passwd nagios |
2、解压安装nagios-plugins
1 2 3 4 | ; html-script: false ]cd /usr/local/src/tarbag wget http://downloads.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz?r=http%3A%2F%2Fwww.nagios.org%2Fdownload%2Fplugins%2F&ts=1331283502&use_mirror=ncu tar zxvf nagios-plugins-1.4.15.tar.gz -C ../software/ cd ../software/nagios-plugins-1.4.15 |
Nagios-plugins默认安装到/usr/local/nagios
1 2 3 | ; html-script: false ]./configure make make install |
更改目录属主
1 | ; html-script: false ]chown -R nagios.nagios /usr/local/nagios/ |
3、解压安装nrpe
1 2 3 4 5 6 | ; html-script: false ]cd /usr/local/src/tarbag wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz?r=http%3A%2F%2Fexchange.nagios.org%2Fdirectory%2FAddons%2FMonitoring-Agents%2FNRPE--2D-Nagios-Remote-Plugin-Executor%2Fdetails&ts=1331283624&use_mirror=nchc tar zxvf nrpe-2.13.tar.gz -C ../software/ cd ../software/nrpe-2.13 ./configure make all |
安装nrpe插件,本插件监控端可以不装
1 | ; html-script: false ]make install-plugin |
安装nrpe守护进程
1 | ; html-script: false ]make install-daemon |
安张nrpe配置文件
1 | ; html-script: false ]make install-daemon-config |
4、配置相关文件
修改nrpe配置文件,允许Nagios监控服务器(192.168.0.19)监控
1 2 | ; html-script: false ]cd /usr/local/nagios/etc/ vi nrpe.cfg |
多台机器用逗号隔开
1 | ; html-script: false ]allowed_hosts=127.0.0.1,192.168.0.19 |
以独立守护进程启动nrpe,也可以使用xinetd启动nrpe,具体清查看nrpe官方文档。
1 | ; html-script: false ]/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d |
开机自动启动nrpe,在rc.local中加入上面行
1 | ; html-script: false ]vi /etc/rc.local |
5、检查nrpe是否安装正常
1 | ; html-script: false ]/usr/local/nagios/libexec/check_nrpe -H localhost |
得到以下输出
NRPE v2.13
返回nrpe版本说明安装没问题。
查看启动端口
1 2 3 4 | ; html-script: false ]netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 27387/nrpe |
如果有防火墙应该开放5666端口:
1 | ; html-script: false ]iptables -I eth0 -p tcp -m tcp –dport 5666 -j ACCEPT |
6、定义监控项
注意:我们需要在/usr/local/nagios/etc/nrpe.cfg中定义我们用到的监控本地资源的命令。
下面的命令是默认定义的:
1 2 3 4 5 | ; html-script: false ]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_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1 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 150 -c 200 |
下面的命令是自己定义的:
监控交换分区的使用情况,使用超过20%时为警告状态,超过10%时为严重状态
1 | ; html-script: false ]command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10% |
监控根分区磁盘使用情况
1 | ; html-script: false ]command[check_disk_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p / |
修改完配置需要重启nrpe
先将nrpe进程kill掉
在执行
1 | ; html-script: false ]/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d |