自动监控主从MySQL同步的SHELL脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动监控主从MySQL同步的SHELL脚本相关的知识,希望对你有一定的参考价值。

写了一个mysql的主从复制的监控的脚本,欢迎一起讨论学习,qq1290518248

#!/bin/bash
#check MySQL_Slave Status
#crontab time 00:10
MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ {print $4}`
MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ {print $4}`
STATUS=$(/usr/local/mysql/bin/mysql -u root -p000000 -S /tmp/mysql.sock -e "show slave status\G" | grep -i "running")
IO_env=`echo $STATUS | grep IO | awk   {print $2}`
SQL_env=`echo $STATUS | grep SQL | awk  {print $2}`
DATA=`date +"%y-%m-%d %H:%M:%S"`
if [ "$MYSQLPORT" == "3306" ]
then
  echo "mysql is running"
else
  /usr/local/bin/sendEmail -f [email protected]163.com  -t 1290517248@qq.com    -s smtp.163.com -u "mysql is not running " -o message-content-type=html     -o message-charset=utf8 -xu [email protected]163.com -xp Syhy2yH -m "warn!server: $MYSQLIP mysql is down"
fi
if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ]
then
  echo "Slave is running!"
else
  echo "####### $DATA #########">> /data/data/check_mysql_slave.log
  echo "Slave is not running!" >>    /data/data/check_mysql_slave.log
  echo "Slave is not running!" | /usr/local/bin/sendEmail -f [email protected]163.com  -t 1290517248@qq.com    -s smtp.163.com -u "slave is not running!" -o message-content-type=html     -o message-charset=utf8 -xu [email protected]163.com -xp Syhy2yH -m "warn!server: $MYSQLIP mysql is down"
fi

 

以上是关于自动监控主从MySQL同步的SHELL脚本的主要内容,如果未能解决你的问题,请参考以下文章

实现Shell脚本监控MySql主从同步

实现Shell脚本监控MySql主从同步

Shell开发MySQL主从监控脚本

web服务文件更新自动同步数据库主从复制shell脚本实现网站代码备份和mysql备份

mysql主从同步监控脚本

Linux运维之Shell编程------监控MySQL错误码及主从复制同步异常