开发nagios插件监控lvs中realserver
环境:
[root@long62]# ifconfig eth0|grep Mask|awk -F '[ :]' '{print $13}' 192.168.200.62
[root@long62]# uname -r 2.6.32-431.el6.x86_64
[root@long63]# ifconfig eth0|grep Mask|awk -F '[ :]' '{print $13}' 192.168.200.63
[root@long63]# uname -r 2.6.32-431.el6.x86_64
nagios监控主机兼SIP:192.168.200.62
VIP:192.168.200.66
RIP:192.168.200.63
操作步骤
注意:lvs的配置,nagios服务端和客户端安装及配置在此略过
第一步:在RIP机器/usr/local/nagios/libexec目录下建立check_lvs_lo,并授权755
[root@long63 libexec]# vi check_lvs_lo #!/bin/sh if [ `ifconfig|grep lo:|wc -l` -eq 1 ] then echo "`uname -n`'s lo:66 is ok" exit 0 else echo "`uname -n`'s lo:66 is not ok" exit 2 fi
[root@long63 libexec]# chmod 755 check_lvs_lo
第二步:在RIP机器/usr/local/nagios/etc/nrpe.cfg文件中添加下面一行,并重启nrpe
echo "command[check_rs]=/usr/local/nagios//libexec/check_lvs_lo">>/usr/local/nagios/etc/nrpe.cf
[root@long63 /]# ps -ef |grep nrpe nagios 31108 1 0 14:57 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/na gios/etc/nrpe.cfg -droot 31425 30935 0 16:21 pts/0 00:00:00 grep nrpe [root@long63 /]# pkill nrpe [root@long63 /]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d [root@long63 /]# ps -ef |grep nrpe nagios 31430 1 0 16:22 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d root 31432 30935 0 16:22 pts/0 00:00:00 grep nrpe
第三步:在监控主机192.168.200.62机器编辑sevices.cfg,在最后添加以下内容
define service{ use generic-service host_name 063-client01 check_command check_nrpe!check_rs service_description lvs_lo max_check_attempts 3 normal_check_interval 10 retry_check_interval 2 contact_groups admins notification_options w,u,c,r notification_interval 60 notification_period 24x7 check_period 24x7 }
第四步:重启nagios服务
[root@long62 ~]# /etc/init.d/nagios checkconfig Running configuration check... OK. [root@long62 ~]# /etc/init.d/nagios reload Running configuration check...done. Reloading nagios configuration...done
验证结果
对于一个有思想的人来说,没有地方是荒凉而遥远的