日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Nagios监控lvs服务

發(fā)布時間:2024/6/18 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nagios监控lvs服务 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?1在lvs?server上安裝nrpe客戶端:

1.1,rpm方式安裝nrpe客戶端

下載地址:http://download.csdn.net/detail/mchdba/7493875

[root@localhost 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 [root@localhost nagios]# rpm -ivh *.rpm --nodeps --force

?

1.2?在配置文件最末尾,加入配置信息以及監(jiān)控主機serverip地址

[root@ localhost nagios]# vim /etc/nagios/nrpe.cfg # add by tim on 2014-06-11 command[check_users]=/usr/local/nagios/libexec/check_users -w 8 -c 15 command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20 command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda 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 50 -c 80 command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 750 -c 800 command[check-host-alive]=/usr/local/nagios/libexec/check_ping -H localhost -w 3000.0,80% -c 5000.0,100% -p 5 allowed_hosts = 127.0.0.1, 10.2xx.3.xx

check下命令是否生效:

[root@web-9 nrpe-2.15]# /usr/local/nagios/libexec/check_users -w 8 -c 15 USERS OK - 2 users currently logged in |users=2;8;15;0 [root@web-9 nrpe-2.15]#

看到已經USERS OK -….命令已經生效。

?

1.3?啟動nrpe報錯例如以下:

[root@web-9 ~]# service nrpe restart Shutting 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[失敗] [root@web-9 ~]# [root@db-m2-slave-1 nagios_client]# service nrpe start Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory[失敗] [root@db-m2-slave-1 nagios_client]#

建立連接

[root@db-m2-slave-1 nagios_client]# ln -s /usr/lib64/libssl.so /usr/lib64/libssl.so.6(假設沒有l(wèi)ibssl.so,就採用別的libssl.so.10來做軟連接,ln -s /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6) [root@db-m2-slave-1 nagios_client]#

再又一次啟動例如以下:

[root@db-m2-slave-1 nagios_client]# service nrpe start Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory[失敗] [root@web-10 ~]# ll /usr/lib64/libcrypto.so lrwxrwxrwx. 1 root root 18 10月 13 2013 /usr/lib64/libcrypto.so -> libcrypto.so.1.0.0 [root@db-m2-slave-1 nagios_client]#

再建鏈接:

[root@db-m2-slave-1 nagios_client]# ln -s /usr/lib64/libcrypto.so /usr/lib64/libcrypto.so.6 (或者假設沒有l(wèi)ibcrypto.so,就採用libcrypto.so.10做軟連接, ln -s /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6) [root@db-m2-slave-1 nagios_client]# service nrpe start Starting nrpe: [確定] [root@db-m2-slave-1 nagios_client]#

?

1.4?檢測下nrpe是否正常執(zhí)行:

去nagiosserver端check下

[root@cache-2 ~]# /usr/local/nagios/libexec/check_nrpe -H xx.xx3.xx NRPE v2.12 [root@cache-2 ~]#
[root@cache-2 ~]#? /usr/local/nagios/libexec/check_nrpe -H xx.xx3.xx

NRPE v2.12

[root@cache-2 ~]#

看到返回NRPE v2.15表示已經連接成功。

?

2?編寫shell腳本實現lvs監(jiān)控

2.1?監(jiān)控腳本
Nagios里面沒有現成的監(jiān)控lvs的狀態(tài)腳本,所以須要去網上找一個簡單的監(jiān)控腳本check_lvs.sh,copy到/usr/lib/nagios/plugins/文件夾,賦予nagios權限,腳本內容例如以下:

#!/bin/bash # http://www.ohlinux.com/archives/632/ # add by tim on 20140613 USAGE_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=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3if [ $# -lt 4 ];thenechoecho \"Usage: $USAGE_Method\"echoexit 0 fi while [ $# -gt 0 ]; docase \"$1\" in-w|--warning)shiftwarning=$1;;-c|--critical)shiftcritical=$1;;esacshift doneif [[ $warning == $critical || $warning -gt $critical ]] then#echo $warning#echo $criticalecho \"$USAGE_Value\"echo \"Usage: $USAGE_Method\"exit 0 fiACT_COUNT=0 Inactive_count=0 stat1=`sudo ipvsadm | grep http | grep Route|wc -l` if [ $stat1 -ne 0 ];thenfor NUM in `sudo ipvsadm | grep http | grep Route | awk \'{print $5}\'`doACT_COUNT=$(($ACT_COUNT+ $NUM))donefor NUM in `sudo ipvsadm | grep http | grep Route | awk \'{print $6}\'`doInactive_count=$(($Inactive_count+ $NUM))done elseecho \" stat1:$stat1, lvs critical,lvs is down now.\"exit 3 fiif [[ \"$ACT_COUNT\" -gt \"$critical\" ]] thenecho \"critical - lvs connetion is : $ACT_COUNT active\"exit 2 fi if [[ \"$ACT_COUNT\" -gt \"$warning\" && \"$ACT_COUNT\" -lt \"$critical\" ]] thenecho \"warning - lvs connetions is : $ACT_COUNT active\"exit 1 fi if [[ \"$ACT_COUNT\" -lt \"$warning\" || $ACT_COUNT == 0 ]] thenecho \"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 0 fi

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

[root@/root/nagios/check_lvs ~]# service nrpe restart; Shutting down nrpe: [確定] Starting nrpe: [確定] [root@/root/nagios/check_lvs ~]#service nrpe restart;

2.3?nagios服務端check一下

[root@cache-2 ~]# /usr/local/nagios/libexec/check_nrpe -H 1x.xx4.x.x5 -c check_lvslvs critical,lvs is down now. [root@cache-2 ~]#

看到check出來lvs服務已經處于down模式。

說明:因為check_lvs是要調用ipvsadm命令來獲取LVS狀態(tài)的,而ipvsadm命令是僅僅能以root用戶來執(zhí)行的, 所以須要將nagios用戶設置成能夠無需password直接su成root,這樣就能以nagios用戶執(zhí)行命令sudo /usr/lib/nagios/plugins/check_lvs?。在centos系統(tǒng)中,無法直接調用sudo命令,須要改動/etc/sudoers,?找到 #Defaults requiretty 并取消凝視,另外新增一行。表示nagios用戶不須要登陸終端就能夠調用命令,例如以下所看到的:

Defaults requiretty Defaults:nagios !requiretty #加入nagios 請求sudo,同意特定指令時(可跟參數),不須要password(如)。 nagios ALL=(ALL) NOPASSWD: ALL

?再去naigosserver上面check下,已經生效,例如以下所看到的:

[root@cache-2 etc]# /usr/local/nagios/libexec/check_nrpe -H 10.xx.xx.xx -c check_lvs LVS OK - LVS is running (conn: 16 active, 77 inactive)|active=16;69999;99999;0; inactive=77;69999;99999;0; [root@cache-2 etc]#?

2.4?nagiosserver上加入配置

vim services.cfg define service{host_name lvs-lanservice_description Check lvscheck_command check_nrpe!check_lvsmax_check_attempts 5normal_check_interval 3retry_check_interval 2check_period 24x7notification_interval 10notification_period 24x7notification_options w,c,rcontact_groups opsweb} vim objects/commands.cfg define command{command_name check_lvscommand_line $USER1$/check_lvs -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$}

之后又一次載入nagios既完畢了對lvs的監(jiān)控服務。

[root@cache-2 etc]# service nagios reload Running configuration check... Reloading nagios configuration... done [root@cache-2 etc]#

?至此,nagios以下對lvs服務的監(jiān)控已經完畢。

?

參考資料:http://c20031776.blog.163.com/blog/static/684716252013627506890/

轉載于:https://www.cnblogs.com/mengfanrong/p/4316431.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的Nagios监控lvs服务的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。