MySQL master-slave status monitoring script

Source: Internet
Author: User

Objective: To monitor MySQL's status from the library, if you copy the exception from the Library and alarm

Ideas:

1, first find MySQL from the library of 4 parameter values (show slave status according to this command), respectively, the IO thread from the library, SQL thread, replication delay time (this script in the following is useless, you can write a script to the delay alarm), error code

2, the function mysql_status judgment, to the IO thread, the SQL thread, the error code three logic and the judgment

3, if False then execute function mysql_errno

4. For MySQL error code 1158 1159 1008 1007 1062 We can stop slave, skip the current number of copies, and proceed to the next copy


[email protected] script]# cat mysql_check.sh

#!/bin/bash

#

#2017.5.8

#mysql状态监测告警

. /etc/init.d/functions

mysql_io_cmd= ' mysql-h 10.222.1.5-uroot-p123456-e ' show slave status\g ' |grep slave_io_running |awk ' {print $NF} '

mysql_sql_cmd= ' mysql-h 10.222.1.5-uroot-p123456-e ' show slave status\g ' |grep slave_sql_running |awk ' {print $NF} '

mysql_be_cmd= ' mysql-h 10.222.1.5-uroot-p123456-e ' show slave status\g ' |grep seconds_behind_master |awk ' {print $NF} '

mysql_errno_cmd= ' mysql-h 10.222.1.5-uroot-p123456-e ' show slave status\g ' |grep last_sql_errno |awk ' {print $NF} '

errorno= (1158 1159 1008 1007 1062)

# #判断mysql复制的错误码

Mysql_errno () {

For sum in $ErrorNo

Do

If ["$Mysql _errno_cmd" = = "$sum"];then

echo "$ (date +%f_%r) Error status code: $Mysql _errno_cmd" >>/tmp/mysql_error.log

Mysql-h 10.222.1.5-uroot-p123456-e ' Stop slave;set global sql_slave_skip_counter=1;start slave; '

Echo ' sort-r/tmp/mysql_error.log ' |mail-s "MySQL Slave is error" [email protected]

Else

echo "$ (date +%f_%r) Error status code: $Mysql _errno_cmd" >>/tmp/mysql_error.log

#echo ' sort-r/tmp/mysql_error.log ' |mail-s "MySQL Slave is error" [email protected]

Uniq/tmp/mysql_error.log |mail-s "MySQL Slave is error" [email protected]

Fi

Done

}

# #监测mysql状态函数

Mysql_status () {

If ["$Mysql _io_cmd" = = "Yes"-a "$Mysql _sql_cmd" = = "Yes"-"$Mysql _errno_cmd" = = "0"];then

Echo

Action "MySQL status"/bin/true

Else

Echo

Action "MySQL status"/bin/false

Mysql_errno

Fi

}

Mysql_status


This article is from "think one or two" blog, please be sure to keep this source http://250919938.blog.51cto.com/962010/1923784

MySQL master-slave status 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.