nagios监控slave(借助脚本)
?
nagios監控slave(借助腳本)
?
修改后的腳本如下(需添加指示燈的狀態)
# vi slave.sh
#!/bin/bash
IO_env=`/usr/local/mysql/bin/mysql -u root -p123456 -e "show slave status \G" | grep Slave_IO_Running | awk -F[:" "]+ '{print $3}'`
SQL_env=`/usr/local/mysql/bin/mysql -u root -p123456 -e "show slave status \G" | grep Slave_SQL_Running | awk -F[:" "]+ '{print $3}'`
if [ $IO_env == "Yes" -a $SQL_env == "Yes" ];then
echo "slave is running at time:`date +%y/%m/%d-%H:%M`"
exit 0
else
echo "slave is down at time:`date +%y/%m/%d-%H:%M`"
$(/sbin/mysql -u root -p123456 -e "stop slave")
$(/sbin/mysql -u root -p123456 -e "reset slave")
$(/sbin/mysql -u root -p123456 -e "start slave")
exit 2
fi
:wq
注:
1、0 指的是狀態燈綠燈,2指的是紅燈,黃燈不用
2、slave宕時執行重啟slave的命令,并顯示紅燈(注:命令執行后slave就已經正常了,顯示紅燈只是想告訴有這么個事件slave宕過)
# cp slave.sh? /usr/local/nagios/libexec
# chmod +x /usr/local/nagios/libexec/slave.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/slave.sh??? (多個腳本的話設置多行)
?
:wq
?
# su - nagios -c 'sudo /usr/local/nagios/libexec/slave.sh'??? (看看執行是否成功)
?
# vi /usr/local/nagios/etc/nrpe.cfg
?
command[check_slave]=/usr/bin/sudo /usr/local/nagios/libexec/slave.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 slave
????????? check_command????? check_nrpe!check_slave
????????? notifications_enabled?? 1
}
?
:wq
?
?
# service nagios restart
轉載于:https://blog.51cto.com/yangzhiming/839868
新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!總結
以上是生活随笔為你收集整理的nagios监控slave(借助脚本)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SVN-关于分支创建合并
- 下一篇: (转)一台服务器安装两个tomcat6