您好,登錄后才能下訂單哦!
nagios監控haproxy(借助腳本)
修改后的腳本如下(需添加指示燈的狀態)
# vi haproxy.sh
#!/bin/bash
Port=`netstat -ntpl | grep haproxy | awk -F[:" "]+ '{print $5}'`
if [ $Port == "1080" ];then
echo "OK - haproxy is running"
exit 0
else
echo "CRITICAL - haproxy is down"
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg
exit 2
fi
:wq
注:0 指的是狀態燈綠燈,2指的是紅燈,黃燈不用 并且宕了之后再次check時就能自動重啟
# cp haproxy.sh /usr/local/nagios/libexec
# chmod +x /usr/local/nagios/libexec/haproxy.sh
# mount /dev/cdrom /media/cdrom
# rpm -ivh sudo-1.6.9pl7-3.el5.i386.rpm
# visudo
#Defaults requiretty (注釋掉)
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/haproxy.sh (多個腳本的話設置多行)
:wq
# su - nagios -c 'sudo /usr/local/nagios/libexec/haproxy.sh' (看看執行是否成功)
# vi /usr/local/nagios/etc/nrpe.cfg
command[check_haproxy]=/usr/bin/sudo /usr/local/nagios/libexec/haproxy.sh
:wq
# killall nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# vi /usr/local/nagios/etc/objects/ming.cfg
define service{
use generic-service
host_name ming
service_description HA
check_command check_nrpe!check_haproxy
}
:wq
# service nagios restart
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。