Daemon monitoring for MySQL master-slave server

Source: Internet
Author: User

Detects MYSLQ from library status, skips fixed error numbers, detects every 30 seconds, automatically skips if eligible, or restarts from library

1) Remove MySQL from the library keyword

 

1 [[email protected] scripts]# mysql-u root-p123qq.com3307-s/data/3307"show slave stat Us\g"| grep " running| seconds_behind_master| Last_sql_errno"| awk ' {print $NF} ' 2 Yes 3 Yes 4 0 5 0

 

2) define the error number in the array

3) while Ture

Debug the following script according to your thoughts

1 [email protected] scripts]# cat check_mysql_slave.sh2#/bin/Bash3 #Date:4 #Author:5#Mail:917667797@qq. com6#Function: This scripts Function isCheck MySQL slave isOK7#Version:1.18qq="[email protected]"9Cmd="mysql-u root-p123qq.com3307-s/data/3307/mysql.sock-e"TenIp= ' Ifconfig eth2|sed-n's#^.*ddr:\ (. *\) BC.*$#\1#GP'` OneSkip= ' $cmd"Stop Slave;set global sql_slave_skip_counter=1;start slave;"` AError_numb= (1158 1159 1008 1007 1062) -  while true -  Do theStatus= (' $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 +Echo"MySQL slave is ok" -        Else +             for((n=0; n<${#error_numb [*]};n++)) A             Do at               if["${status[3]}"=="${error_numb[n]}"];then - ${skip} -               Else -$cmd"stop Slave;start slave;" - fi -  Done inEcho"MySQL Salve is not ok" -Echo"${ip} mysql is not ok"|mail-s"MySQL slave error at ' date +%f%t '"$QQ to fi +Sleep3 -Done

  

The test results are as follows

[Email protected] scripts]# sh check_mysql_slave.sh

MySQL Salve is not ok

MySQL slave is ok

MySQL slave is ok

MySQL slave is ok

MySQL slave is ok

MySQL slave is ok

MySQL slave is ok

MySQL slave is ok

MySQL slave is ok

MySQL slave is ok

MySQL slave is ok

Daemon monitoring for MySQL master-slave server

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.