码迷,mamicode.com
首页 > 数据库 > 详细

mysql主从关系监控,故障报警和恢复

时间:2016-07-25 16:35:31      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:mysql主从关系监控   故障报警和恢复   

#!/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   #日志文件路径,必须提前创建好


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 $2}‘`


Slave_SQL_Running=`echo $status | grep Slave_SQL_Running | awk ‘{print $2}‘`


if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ]


then echo "Slave is Running!"   >>  /opt/s.log

#mail -s "$ip  Slave is  running!(主从关系正常,放心使用啦。)"   243652136\@qq.com  <  /opt/s.log

else


echo " $datetime $slave_ip Slave is not running!" >> $mysql_slave_logfile

mail -s " Slave is  not running!(主从关系宕机啦,赶紧去修复吧。)"   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


本文出自 “系统网站运维” 博客,请务必保留此出处http://cgc243652136qq.blog.51cto.com/3989433/1829623

mysql主从关系监控,故障报警和恢复

标签:mysql主从关系监控   故障报警和恢复   

原文地址:http://cgc243652136qq.blog.51cto.com/3989433/1829623

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!