您的位置:首页 > 数据库 > MySQL

nagios监控mysql主从复制

2014-11-12 15:38 393 查看
环境: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
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: