MySQL Master-slave monitoring

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.