Requirements: Detect MYSLQ from the library status, skip fixed error number, detect every 30 seconds, if eligible to automatically skip or restart from library 1) remove MySQL from the library keyword [[email protected] scripts]# mysql-u root- P123qq.com3307-s/data/3307/mysql.sock-e "show slave Status\g" |grep-e "running| seconds_behind_master| Last_sql_errno "|awk ' {print $NF} ' YesYes002) defines the error number in the array 3) while ture debugs the following script according to the idea ..... [[email protected] scripts]# cat check_mysql_slave.sh #/bin/bash#date: 2015-12-14 22:37#author: Create by Li Xingli #mail: [email protected]# Function:this scripts function is check for MySQL slave is ok#version: 1.1qq= "[email protected]" cmd= "MySQL -U root-p123qq.com3307-s/data/3307/mysql.sock-e "ip= ' ifconfig eth2|sed-n ' s#^.*ddr:\ (. *\) bc.*$#\1#gp ' skip= ' $cmd" Stop Slave;set global sql_slave_skip_counter=1;start slave; " ' Error_numb= (1158 1159 1008 1007 1062) while truedostatus= (' $cmd "show slave Status\g" |grep-e "running| seconds_behind_master| Last_sql_errno "|awk ' {print $NF} ') if [" ${staTus[0]} " = =" Yes "-a" ${status[1]} "= =" Yes "-a" ${status[2]} "= =" 0 "] Then&nbs p; echo "MySQL slave is OK" else for ((n=0;n<${#error_numb [*]};n+ +)) do if ["${status[3]}" = = "${error_numb[n]}"];then ${skip} else $cmd "Stop Slave;start Slave;" fi done echo "MySQL salve is not OK" echo "${ip} MySQL is not OK" |mail-s "mysql slave error @ ' date +%f%t '" $qq fisleep 3done[[email protected] scripts]# test results are as follows [[email protected] scripts]# sh check_mysql_slave.sh mysql salve is Not okmysql slave are okmysql slave is okmysql slave are okmysql slave is okmysql slave are okmysql slave are okmysql slave is Okmysql slave is okmysql slave are okmysql slave is OK
For more information, please visit Li Hing Lee Blog
MySQL Master-slave monitoring