MySQL master-Slave synchronization monitoring script

Source: Internet
Author: User

MySQL master-Slave synchronization monitoring script, using MySQL from the library IO and SQL process and delay time to monitor the master-slave synchronization is normal, detailed shell script is as follows:

#!/bin/bash#author wangning#date 2017-7-17#qq 1198143315#email [email protected]##### ############################# define variable############################ #define_variable () {ip= ' ifconfig|sed -n  ' 2p ' |awk -f  "[:  ]+"   ' {print $4} ' code= (1158 1159  1008 1007 1062) status= (' Mysql -uroot -p123456 -s /data/3309/mysql.sock -e   "Show slave status\g" |egrep  "running| behind_master| Last_errno "|awk  ' {print $2} ')}############################ judge master ############ ########################## #judge_master () {Mysql -uroot -p123456 -s /data/3306/mysql.sock  -e  "Show databases"  &>/dev/nullif [ $? -ne 0 ];then    echo  "ip  $ip  the master mysql service is downed"  > /mail/mysql_master.log &&   mail -s  "Wangning tile"  [email protected] </mail/mysql_master.logelse    echo  "ip  $ip  the master mysql service is normal"  > /mail/mysql_master.log &&   mail -s  "Wangning tile"  [email  protected] </mail/mysql_master.logfi}################### judge io sql status  and delay time ############################### io_sql_delay () {if [  "${ Status[0]} " == " yes " -a " ${status[1 "}"  ==  "Yes"  -a ${status[3]} - le 60 ];then   echo  "the master and slave replication  Is normal " >/mail/mysql_slave.log &&   mail -s " wangning  tile " [email protected] </mail/mysql_slave.logelse    echo " the master and&Nbsp;slave replication is failed " >/mail/mysql_slave.log &&    mail -s  "Wangning tile"  [email protected] </mail/mysql_slave.logfi}#### ############################ judge error code ################################# #judge_ Error_code () {for  ((i=0;i<=${#status [*]};i++)) Doif [ ${status[2]} -eq ${code[i]}  ];then   mysql -uroot -p123456 -S /data/3309/mysql.sock -e  "Stop slave;set global sql_slave_skip_counter=1;start slave" Fidone}main () {while  Truedodefine_variablejudge_masterio_sql_delayjudge_error_codesleep 180done}main


This article is from the "Galloping Camel" blog, make sure to keep this source http://wn2100.blog.51cto.com/9915310/1948112

MySQL master-Slave synchronization monitoring script

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.