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

本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/839868如需转载请自行联系原作者


yangzhimingg

上一篇:outlook使用技巧,问题不怕2,就怕自己基础不够扎实


下一篇:mysql数据备份及恢复详细操作