监控mysql主从同步状态脚本

监控mysql主从同步状态脚本

示例一:
cat check_mysql_health #!/bin/sh
slave_is=($(mysql -S /tmp/mysql3307.sock -uroot -e "show slave status\G"|grep "Slave_.*_Running" |awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ]
then
echo "OK SDK-slave3307 connect master3306 is running"
exit
else
echo "Critical SDK-slave3307 connect master3306 is not running"
exit
fi
示例二:
[root@slavedb test]# cat Check_Mysql_Synchronization.sh
#!/bin/bash
MYUSER=root
MYSOCKET=/tmp/mysql3306.sock
MYPASSWD=
MYLOGIN="mysql -S $MYSOCKET -u$MYUSER "
ERROR=( )
check_status(){
STATUS=($($MYLOGIN -e "show slave status\G"|egrep "Slave_SQL_Running|Slave_IO_Running|Seconds_Behind_Master|Last_SQL_Errno"|awk '{print $NF}'))
if [ "${STATUS[0]}" = "Yes" -a "${STATUS[1]}" = "Yes" -a "${STATUS[2]} = 0" ];then
echo "Mysql Slave is Ok!"
CHECK_NUM=
return $CHECK_NUM
else
CHECK_NUM=
return $CHECK_NUM
fi
} check_error(){
check_status
if [ $? -eq ];then
for ((i=;i<${#ERROR[*]};i++));do
if [ "${ERROR[i]}" == "${STATUS[3]}" ];then
$MYLOGIN -e "stop slave;"
$MYLOGIN -e "set global sql_slave_skip_counter=1"
$MYLOGIN -e "start slave;"
fi
done
fi
} check_again(){
STATUS=($($MYLOGIN -e "show slave status\G"|egrep "Slave_SQL_Running|Slave_IO_Running|Seconds_Behind_Master|Last_SQL_Errno"|awk '{print $NF}'))
check_status >/dev/null &>
if [ $? -eq ];then
echo "Mysql slave is fail $(date +%F)"
fi
}
main(){
while true;do
check_error
check_again
sleep
done
}
main

监控mysql主从同步状态脚本

作者:唐胜伟
出处:http://www.cnblogs.com/tangshengwei/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。

上一篇:MySQL主从同步几个文件


下一篇:mysql主从同步+mycat读写分离+.NET程序连接mycat代理