利用shell+短信實現簡單mysql雙向同步監控

 原理、腳本都很簡單,就是截取同步狀態的Slave_IO_Running和Slave_SQL_Running兩個值是否都爲Yes。若是其中不是,就發短信報警。mysql

 

  
  
  
  
  1. [root@mysqlb script]# cat Check_Mysql_Slave_Replication.sh  
  2. #!/bin/sh 
  3.  
  4. . /etc/profile 
  5.  
  6. db_user=reed 
  7. db_paasswd=reed 
  8. LogPath=/root/script/Check_Mysql_Slave_Replication_Log 
  9. [ ! -d $LogPath ] && mkdir -p $LogPath 
  10.  
  11. cd $LogPath 
  12.  
  13. 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) 
  14. 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) 
  15.  
  16. FUNC() 
  17.         echo "[INFO]$(date +'%F %T') begin to monitor mysql replication..." 
  18.         if [ "$Slave_IO_Running" == "Yes" ] && [ "$Slave_SQL_Running" == "Yes" ];then 
  19.                 echo "[INFO]$(date +'%F %T') mysql replication is ok!" 
  20.         else 
  21.                 echo "[ERROR]$(date +'%F %T') fuck!mysql24 replication is failed..." 
  22.                 #調用本身寫的發短信腳本 
  23.                 /root/script/info_takeok.sh "fuck!mysql24 replication is failed" 
  24.         fi 
  25. FUNC >>Check_Mysql_Slave_Replication$(date +'%F').log 

最後寫到crontab裏面,一分鐘檢測一次sql

相關文章
相關標籤/搜索