且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

nagios监控mysql主从复制

更新时间:2022-10-03 19:27:33

 环境:

Centos5.6 mysql只做同步指定库,没有同步mysql库用户数据

登陆从服务器mysql,添加验证的用户

 

grant replication client on *.* to 'slave'@localhost identified by '123456';

flush privileges;

 

查看是否添加成功

select user,host from mysql.user

 

在从服务器安装 nrpe,然后在配置文件nrpe.cfg加入一行

 

command[check_mysql_slave]=/usr/local/nagios/libexec/check_mysql_slave


添加这个文件内容:

vi /usr/local/nagios/libexec/check_mysql_slave 

 

 #!/bin/sh 

declare -a slave_is

slave_is=($(/usr/local/mysql/bin/mysql -uslave -p123456 -e "show slave status\G"|grep Running |awk '{print $2}'))

if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ]

     then

     echo "OK -slave is running" 

     exit 0

else

     echo "Critical -slave is error" 

     exit 2

fi

 

再执行这个脚本,观察输出情况

 

/usr/local/nagios/libexec/check_nrpe -H 192.168.10.231

 

/usr/local/nagios/libexec/check_nrpe -H 192.168.10.231 -c check_mysql_slave

 

在主监控服务里面添加了重启

 

define service {

host_name 192.168.10.232

service_description check_mysql_slave

check_period 24x7

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

contact_groups mygroup

notification_interval 5

notification_period 24x7

notification_options w,u,c,r

check_command check_nrpe!check_mysql_slave

}

本文转自奔跑在路上博客51CTO博客,原文链接http://blog.51cto.com/qiangsh/1575726如需转载请自行联系原作者


qianghong000