Mysql master-slave replication monitoring shell script

Source: Internet
Author: User
####### The script application in the production environment is based on the use of mysql Master/Slave ####### vimysqlm-s.sh #! /Bin/baship = 'ifconfigeth0 | sed-n2p | awk & #39; {print $2} & #39; | awk-F: & #39; {print $2} & #39; 'port = 'netstat-anl | grep3306 | sed-n

####### This script is used in the production environment on the basis of mysql Master/Slave ########

Vi mysqlm-s.sh
#! /Bin/bash

Ip = 'ifconfig eth0 | sed-n 2p | awk '{print $2}' | awk-F: '{print $2 }''

Port = 'netstat-anl | grep 3306 | sed-n '1p' | awk' {print $4} '| awk-F:' {print $2 }''

Array = ($ (mysql-uUSER-pPASSWD-e "show slave status \ G" | grep "Running" | awk '{print $2 }'))

If ["$ port" == "3306"]
Then
If ["$ {array [0]}" = "Yes"] | ["$ {array [1]}" = "Yes"]
Then
Echo "slave is OK"
Else
/Home/shell/sendEmail-f XXX @ XXX-t XXX @ XXX-s smtp. XXX-u "mysql Master/slave replication error"-xu user-xp passwd-m "$ {ip}: slave is error"
Fi

Else
/Home/shell/sendEmail-f XXX @ XXX-t XXX @ XXX-s smtp. XXX-u "mysql stops running"-xu user-xp passwd-m "$ {ip}: mysql is shutdown and slave error"

Fi

########### ########################

$ Ip is used to obtain the IP address of the Local Machine

$ Port is used to determine whether the mysql service is running normally.

$ Array is an array, $ array [0] is the first parameter in the array, and $ array [1] is the second parameter in the array.

If... then... fi can be monitored based on the obtained parameters.

$ {Ip}: mysql is shutdown and slave error # note that the master node fails to replicate because mysql is not running normally.

######################################## ###############################

Finally, grant the executable permission to the script and run it every 15 minutes using crontab-e.

*/15 */home/shell/mysqm-s.sh

This article from the "game technology blog" blog, please be sure to keep this source http://youzao.blog.51cto.com/3946111/743328


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.