MySQL master-slave relationship monitoring, fault alarm and recovery

Source: Internet
Author: User

#!/bin/sh

#check_mysql_slave status


Ip=eth1 #网卡名称


Mysql_binfile=/usr/local/mysql/bin/mysql


Mysql_user=root #MySQL数据库账号


mysql_pass=123456 #密码


Mysql_sockfile=/tmp/mysql.sock


Datetime= ' date + '%y-%m-%d/%h:%m:%s ' #获取当前时间


Mysql_slave_logfile=/opt/slave.log #日志文件路径 must be created in advance.


slave_ip= ' ifconfig $ip |grep "inet addr" | awk-f[: ""]+ ' {print $4} '


status=$ ($mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "show slave status\g" | grep-i "Running")


Slave_io_running= ' echo $status | grep slave_io_running | awk ' {print $} '


Slave_sql_running= ' echo $status | grep slave_sql_running | awk ' {print $} '


If ["$Slave _io_running" = "yes"-a "$Slave _sql_running" = "yes"]


Then echo "Slave is running!" >>/opt/s.log

#mail-S "$ip Slave is running! (The master-slave relationship is normal and safe to use.) ) "243652136\ @qq. com </opt/s.log

Else


echo "$datetime $slave _ip slave is not running!" >> $mysql _slave_logfile

Mail-s "Slave is not running! (Master-slave relationship down, hurry to repair it.) ) "243652136\ @qq. com < $mysql _slave_logfile

$mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "Stop slave;"


$mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "set global sql_slave_skip_counter=1;"


$mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "start slave;"


$mysql _binfile-u$mysql_user-p$mysql_pass-s $mysql _sockfile-e "Exit"


Fi


This article is from the "System website Operations" blog, please be sure to keep this source http://cgc243652136qq.blog.51cto.com/3989433/1829623

MySQL master-slave relationship monitoring, fault alarm and recovery

Related Article

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.