Nagios監控lvs服務
1在lvs 伺服器上安裝nrpe客戶端:
1.1,rpm方式安裝nrpe客戶端
下載地址:
-
[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 在配置檔案最末尾,新增配置資訊以及監控主機伺服器ip地址
-
[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
(如果沒有libssl.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]#
再建連結:
1.4 檢測下nrpe是否正常執行:
-
去nagios伺服器端check下
-
[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監控
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 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=3
-
-
if [ $# -lt 4 ];then
-
echo
-
echo \"Usage: $USAGE_Method\"
-
echo
-
exit 0
-
fi
-
while [ $# -gt 0 ];
-
do
-
case \"$1\" in
-
-w|--warning)
-
shift
-
warning=$1
-
;;
-
-c|--critical)
-
shift
-
critical=$1
-
;;
-
esac
-
shift
-
done
-
-
-
if [[ $warning == $critical || $warning -gt $critical ]]
-
then
-
#echo $warning
-
#echo $critical
-
echo \"$USAGE_Value\"
-
echo \"Usage: $USAGE_Method\"
-
exit 0
-
fi
-
-
-
ACT_COUNT=0
-
Inactive_count=0
-
stat1=`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))
-
done
-
else
-
echo \" stat1:$stat1, lvs critical,lvs is down now.\"
-
exit 3
-
fi
-
-
-
-
if [[ \"$ACT_COUNT\" -gt \"$critical\" ]]
-
then
-
echo \"critical - lvs connetion is : $ACT_COUNT active\"
-
exit 2
-
fi
-
if [[ \"$ACT_COUNT\" -gt \"$warning\" && \"$ACT_COUNT\" -lt \"$critical\" ]]
-
then
-
echo \"warning - lvs connetions is : $ACT_COUNT active\"
-
exit 1
-
fi
-
if [[ \"$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 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 ~]#
2.3 去nagios服務端check一下
-
[root@cache-2 ~]# /usr/local/nagios/libexec/check_nrpe -H 1x.xx4.x.x5 -c check_lvs
-
lvs critical,lvs is down now.
- [root@cache-2 ~]#
看到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 requiretty
Defaults:nagios !requiretty
#新增nagios 請求sudo,允許特定指令時(可跟引數),不需要密碼(如)。
nagios ALL=(ALL) NOPASSWD: ALL
再去nagios伺服器上面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 在nagios伺服器上新增配置
-
vim services.cfg
-
define 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.cfg
-
define command{
-
command_name check_lvs
-
command_line $USER1$/check_lvs -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
- }
之後重新載入nagios既完成了對lvs的監控服務。
-
[root@cache-2 etc]# service nagios reload
-
Running configuration check...
-
Reloading nagios configuration...
-
done
- [root@cache-2 etc]#
至此,nagios下面對lvs服務的監控已經完成。
參考資料:http://c20031776.blog.163.com/blog/static/684716252013627506890/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30633755/viewspace-2127703/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Nagios監控mongodb分片叢集服務實戰iOSMongoDB
- nagios監控例項 -- PostgreSQL監控iOSSQL
- nagios監控遠端主機服務可能出現的問題iOS
- Java後端分散式系統的服務監控:Zabbix與NagiosJava後端分散式iOS
- nagios批量新增監控iOS
- 使用nagios監控oracleiOSOracle
- Ubuntu下監控服務Ubuntu
- Nagios 裡面監控MySQL 監控事務夯住(RUNNING)報警通知iOSMySql
- nagios的配置(監控端和被監控端)iOS
- nagios監控例項 -- Windows伺服器監控iOSWindows伺服器
- 運維監控利器nagios運維iOS
- Nagios 監控ESXI指令碼iOS指令碼
- Nagios監控系統搭建iOS
- Nginx服務狀態監控Nginx
- APM效能監控軟體的監控型別服務及監控流程型別
- 容器監控—阿里雲&容器內部服務監控阿里
- nagios監控華為5700交換機iOS
- nagios監控drbd同步狀態iOS
- Nagios for Aix監控客戶端iOSAI客戶端
- 將Nagios監控資訊存入MySQLiOSMySql
- Grafana+Prometheus 監控 MySql服務GrafanaPrometheusMySql
- prometheus監控golang服務實踐PrometheusGolang
- nagios監控例項 -- 伺服器基本狀況監控iOS伺服器
- nagios監控linux主機監控記憶體指令碼iOSLinux記憶體指令碼
- nagios監控 ogg同步狀態iOS
- nginx下搭建nagios監控環境NginxiOS
- nagios-新增記憶體監控iOS記憶體
- Nagios使用check_mysql監控mysqliOSMySql
- nagios監控頻寬外掛薦iOS
- MySQL伺服器部署nagios監控MySql伺服器iOS
- shell監控服務程式是否啟動
- 「服務端」node服務的監控預警系統架構服務端架構
- Cacti+Nagios監控平臺完美整合iOS
- nagios監控linux磁碟io的bugiOSLinux
- nagios監控流量大小的外掛iOS
- nagios-新增oracle資料庫監控iOSOracle資料庫
- linux效能監控工具——NAGIOS和OVOLinuxiOS
- go-kit 微服務 服務監控 (prometheus 實現)Go微服務Prometheus