0116MYSQL master-slave Replication Monitoring

Source: Internet
Author: User

How to automate monitoring MySQL master-slave Service
--First step to create a directory
Mkdir-p/tmp/mysql/masterslave #日志存放目录
Create the SH directory below/root #存放执行的SHELL脚本

--second step to write the shell file
#!/bin/sh
# 2017-01-16
# Send mail to [email protected]

# Defined Variables
Mysqluser=root
mysqlpass=111111
mysqlport=3306
errorno= (1158 1159 1008 1007 1062)
Errorlog=/tmp/mysql/masterslave/error_skip.log
Rightlog=/tmp/mysql/masterslave/right.log
Mysqlcmd= "/usr/bin/mysql-u$mysqluser-p$mysqlpass"

# Defined Skip Error Functions
function Error_skip () {
Local flag
Flag=0
For num in ${errorno[@]}
Do
If ["$" = = "$num"];then
$MYSQLCMD-E ' stop slave;set global sql_slave_skip_counter=1;start slave; '
echo "$ (date +%f_%r) $" >> $errorlog
Else
echo "$ (date +%f_%r) $" >> $errorlog
((flag++))
Fi
Done
["$flag" = = "${#ErrorNo [@]}"] &&{
Uniq $errorlog |mail-s "MySQL Slave is error" [email protected]
}
}

# Defined Check Slave Functions
function Check_slave () {
myresult= ' $MYSQLCMD-e ' show slave status\g ' |egrep ' _running| behind_master| Sql_errno ' |awk ' {print $NF} '
Array= ($MyResult)
If ["${array[0]}" = = "Yes"-a "${array[1]}" = = "Yes"-"${array[2]}" = = "0"]
Then
echo "$ (date +%f_%r) $" >> $rightlog
Else
Error_skip ${array[3]}
Fi
}

# Defined Main Functions
function Main () {
While True
Do
Check_slave
Done
}
Main

--The third step is to execute the shell file repeatedly using a timed task
--Updated every 10 minutes
0-59/10 * * * */root/sh/jk2.sh

0116MYSQL master-slave Replication Monitoring

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.