一、首先,在被监控机(lvs服务器)安装与配置
复制代码代码示例:
#!/bin/bash
#Author: ly_cyz #www.jbxue.com ACT_COUNT=0 Inactive_count=0 stat1=`sudo ipvsadm | grep http | grep Masq|wc -l` if [ $stat1 -ne 0 ];then for NUM in `sudo ipvsadm | grep http | grep Masq | awk '{print $5}'` do ACT_COUNT=$(($ACT_COUNT+ $NUM)) done for NUM in `sudo ipvsadm | grep http | grep Masq | awk '{print $6}'` do Inactive_count=$(($Inactive_count+ $NUM)) done else echo "LVS CRITICAL, "LVS is Down"" exit 2 fi if [ $ACT_COUNT == 0 ];then echo "LVS ok, "0 active connection"" exit 1 else echo "LVS OK - LVS is running (conn: $ACT_COUNT active, $Inactive_count inactive)|active=$ACT_COUNT;69999;99999;0; inactive=$Inactive_count;69999;99999;0;" fi 说明:由于check_lvs是要调用ipvsadm命令来获取LVS状态的,而ipvsadm命令是只能以root用户来运行的, 所以需要将nagios用户设置成可以无需密码直接su成root,这样就能以nagios用户运行命令sudo /usr/local/nagios/libexec/check_lvs ,设置方法参照第二步。
#定义监控命令
复制代码代码示例:
Defaults requiretty
Defaults:nagios !requiretty #添加nagios 请求sudo,允许特定指令时(可跟参数),不需要密码(如)。
复制代码代码示例:
nagios ALL=(ALL) NOPASSWD: ALL
二、Nagios服务端配置:
复制代码代码示例:
/usr/local/nagios/libexec/check_nrpe -H 211.XXX.XXX.XXX -c check_lvs
能正常输出结果即可。 |