如何監控主從故障是否正常?MySQL數據庫學習

寫監控腳本 不同步時發送郵件

#!/bin/bash

. /etc/init.d/functions

function check(){

rep_file=/tmp/rep$(date +%F).txt

while true

 do

rep=(`/application/mysql/bin/mysql -e "show slave status\G"|awk '/Slave_SQL_Running:/{print $2};/Slave_IO_Running:/{print $2};$1~/Seconds_Behind_Master/{print $2}'|xargs`)

  if [ "${rep[0]}" != "Yes" ]; then

     echo "Slave_IO_Running: NO" >$rep_file

     break 1

  fi

  if [ "${rep[1]}" != "Yes" ]; then

     echo "Slave_SQL_Running: NO" >$rep_file

  fi

  if [ "${rep[2]}" -ne 0 ]; then

     echo " Seconds_Behind_Master delay" >$rep_file

     break 1

  fi

  sleep 3

done

}

function main(){

  while true

  do

     check

     mail -s "replication false" [email protected] </tmp/rep$(date +%F).txt

互聯網企業大多用的數據庫是MySQL的,想要衆多的IT工作者中脫穎而出,就需要擁有高深的技術,學習增值是必不可少的。學習之路,是貴在堅持的。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章