標籤:des style class blog code http
1在lvs 伺服器上安裝nrpe用戶端:
1.1,rpm方式安裝nrpe用戶端
:http://download.csdn.net/detail/mchdba/7493875
[[email protected] nagios]# ll總計 768-rw-r--r-- 1 root root 713389 12-16 12:08 nagios-plugins-1.4.11-1.x86_64.rpm-rw-r--r-- 1 root root 32706 12-16 12:09 nrpe-2.12-1.x86_64.rpm-rw-r--r-- 1 root root 18997 12-16 12:08 nrpe-plugin-2.12-1.x86_64.rpm[[email protected] nagios]# rpm -ivh *.rpm --nodeps --force
1.2 在設定檔最末尾,添加配置資訊以及監控主機伺服器ip地址
[[email protected] localhost nagios]# vim /etc/nagios/nrpe.cfg# add by tim on 2014-06-11command[check_users]=/usr/local/nagios/libexec/check_users -w 8 -c 15command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sdacommand[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 50 -c 80command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 750 -c 800command[check-host-alive]=/usr/local/nagios/libexec/check_ping -H localhost -w 3000.0,80% -c 5000.0,100% -p 5allowed_hosts = 127.0.0.1, 10.2xx.3.xx
check下命令是否生效:
[[email protected] nrpe-2.15]# /usr/local/nagios/libexec/check_users -w 8 -c 15USERS OK - 2 users currently logged in |users=2;8;15;0[[email protected] nrpe-2.15]#
看到已經USERS OK -….命令已經生效。
1.3 啟動nrpe報錯如下:
[[email protected] ~]# service nrpe restartShutting down nrpe: [失敗]Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory [失敗][[email protected] ~]#[[email protected] nagios_client]# service nrpe startStarting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory [失敗][[email protected] nagios_client]#
建立串連
[[email protected] nagios_client]# ln -s /usr/lib64/libssl.so /usr/lib64/libssl.so.6 (如果沒有libssl.so,就採用別的libssl.so.10來做軟串連,ln -s /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6)[[email protected] nagios_client]#
再重新啟動如下:
[[email protected] nagios_client]# service nrpe startStarting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory [失敗][[email protected] ~]# ll /usr/lib64/libcrypto.solrwxrwxrwx. 1 root root 18 10月 13 2013 /usr/lib64/libcrypto.so -> libcrypto.so.1.0.0[[email protected] nagios_client]#
再建連結:
[[email protected] nagios_client]# ln -s /usr/lib64/libcrypto.so /usr/lib64/libcrypto.so.6(或者如果沒有libcrypto.so,就採用libcrypto.so.10做軟串連, ln -s /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6)[[email protected] nagios_client]# service nrpe startStarting nrpe: [確定][[email protected] nagios_client]#
1.4 檢測下nrpe是否正常運行:
去nagios伺服器端check下
[[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H xx.xx3.xxNRPE v2.12[[email protected] ~]#
[[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H xx.xx3.xx
NRPE v2.12
[[email protected] ~]#
看到返回NRPE v2.15表示已經串連成功。
2 編寫shell指令碼實現lvs監控
2.1 監控指令碼
Nagios裡面沒有現成的監控lvs的狀態指令碼,所以需要去網上找一個簡單的監控指令碼check_lvs.sh,copy到/usr/lib/nagios/plugins/目錄,賦予nagios許可權,指令碼內容如下:
#!/bin/bash # http://www.ohlinux.com/archives/632/# add by tim on 20140613USAGE_Method=\"$(basename $0)[-h|--hostname] <Free ip or hostname> [-w|--warning] <Free integer> [-c|--critical] <Free integer>\"USAGE_Value=\"warning value must be small than critical value: `basename $0` $*\"STATE_OK=0STATE_WARNING=1STATE_CRITICAL=2STATE_UNKNOWN=3if [ $# -lt 4 ];then echo echo \"Usage: $USAGE_Method\" echo exit 0fiwhile [ $# -gt 0 ];do case \"$1\" in -w|--warning) shift warning=$1 ;; -c|--critical) shift critical=$1 ;; esac shiftdoneif [[ $warning == $critical || $warning -gt $critical ]]then #echo $warning #echo $critical echo \"$USAGE_Value\" echo \"Usage: $USAGE_Method\" exit 0fiACT_COUNT=0Inactive_count=0stat1=`sudo ipvsadm | grep http | grep Route|wc -l`if [ $stat1 -ne 0 ];then for NUM in `sudo ipvsadm | grep http | grep Route | awk \‘{print $5}\‘` do ACT_COUNT=$(($ACT_COUNT+ $NUM)) done for NUM in `sudo ipvsadm | grep http | grep Route | awk \‘{print $6}\‘` do Inactive_count=$(($Inactive_count+ $NUM)) doneelse echo \" stat1:$stat1, lvs critical,lvs is down now.\" exit 3fiif [[ \"$ACT_COUNT\" -gt \"$critical\" ]]then echo \"critical - lvs connetion is : $ACT_COUNT active\" exit 2fiif [[ \"$ACT_COUNT\" -gt \"$warning\" && \"$ACT_COUNT\" -lt \"$critical\" ]]then echo \"warning - lvs connetions is : $ACT_COUNT active\" exit 1fiif [[ \"$ACT_COUNT\" -lt \"$warning\" || $ACT_COUNT == 0 ]]then 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;\" exit 0fi
2.2 nrpe.cfg裡面配置如下
Vim /etc/nagios/nrpe.cfg,在裡面添加一行check_lvs命令:
command[check_lvs]=/usr/lib/nagios/plugins/check_lvs -w 300 -c 600
之後重啟nrpe
[[email protected]/root/nagios/check_lvs ~]# service nrpe restart;Shutting down nrpe: [確定]Starting nrpe: [確定][[email protected]/root/nagios/check_lvs ~]#service nrpe restart;
2.3 去nagios服務端check一下
[[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H 1x.xx4.x.x5 -c check_lvs lvs critical,lvs is down now.[[email protected] ~]#
看到check出來lvs服務已經處於down模式。
說明:由於check_lvs是要調用ipvsadm命令來擷取LVS狀態的,而ipvsadm命令是只能以root使用者來啟動並執行, 所以需要將nagios使用者佈建成可以無需密碼直接su成root,這樣就能以nagios使用者運行命令sudo /usr/lib/nagios/plugins/check_lvs 。在centos系統中,無法直接調用sudo命令,需要修改/etc/sudoers, 找到 #Defaults requiretty 並取消注釋,另外新增一行。表示nagios使用者不需要登陸終端就可以調用命令,如下所示:
Defaults requirettyDefaults:nagios !requiretty#添加nagios 請求sudo,允許特定指令時(可跟參數),不要求輸入密碼(如)。nagios ALL=(ALL) NOPASSWD: ALL
再去naigos伺服器上面check下,已經生效,如下所示:
[[email protected] etc]# /usr/local/nagios/libexec/check_nrpe -H 10.xx.xx.xx -c check_lvsLVS OK - LVS is running (conn: 16 active, 77 inactive)|active=16;69999;99999;0; inactive=77;69999;99999;0;[[email protected] etc]#
2.4 在nagios伺服器上添加配置
vim services.cfgdefine service{ host_name lvs-lan service_description Check lvs check_command check_nrpe!check_lvs max_check_attempts 5 normal_check_interval 3 retry_check_interval 2 check_period 24x7 notification_interval 10 notification_period 24x7 notification_options w,c,r contact_groups opsweb }vim objects/commands.cfgdefine command{ command_name check_lvs command_line $USER1$/check_lvs -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ }
之後重新載入nagios既完成了對lvs的監控服務。
[[email protected] etc]# service nagios reloadRunning configuration check...Reloading nagios configuration...done[[email protected] etc]#
至此,nagios下面對lvs服務的監控已經完成。
參考資料:http://c20031776.blog.163.com/blog/static/684716252013627506890/