Home  >  Article  >  Database  >  利用shell+短信实现简单MySQL双向同步监控

利用shell+短信实现简单MySQL双向同步监控

WBOY
WBOYOriginal
2016-06-07 17:26:33920browse

原理、脚本都很简单,就是截取同步状态的Slave_IO_Running和Slave_SQL_Running两个值是否都为Yes。如果其中不是,就发短信报警。

原理、脚本都很简单,就是截取同步状态的Slave_IO_Running和Slave_SQL_Running两个值是否都为Yes。如果其中不是,,就发短信报警。

[root@mysqlb script]# cat Check_Mysql_Slave_Replication.sh
#!/bin/sh

. /etc/profile

db_user=reed
db_paasswd=reed
LogPath=/root/script/Check_Mysql_Slave_Replication_Log
[ ! -d $LogPath ] && mkdir -p $LogPath

cd $LogPath

Slave_IO_Running=$(/usr/local/mysql/bin/mysql -u$db_user -p$db_paasswd -e"show slave status \G"|grep 'Slave_IO_Running'|cut -d':' -f 2|cut -d' ' -f 2)
Slave_SQL_Running=$(//usr/local/mysql/bin/mysql -u$db_user -p$db_paasswd -e"show slave status \G"|grep 'Slave_SQL_Running'|cut -d':' -f 2|cut -d' ' -f 2)

FUNC()
{
echo "[INFO]$(date +'%F %T') begin to monitor mysql replication..."
if [ "$Slave_IO_Running" == "Yes" ] && [ "$Slave_SQL_Running" == "Yes" ];then
echo "[INFO]$(date +'%F %T') mysql replication is ok!"
else
echo "[ERROR]$(date +'%F %T') fuck!mysql24 replication is failed..."
#调用自己写的发短信脚本
/root/script/info_takeok.sh "fuck!mysql24 replication is failed"
fi
}
FUNC >>Check_Mysql_Slave_Replication$(date +'%F').log

最后写到crontab里面,一分钟检测一次。

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn