如何监控主从故障是否正常?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 "replicationfalse" [email protected] </tmp/rep$(date +%F).txt





猜你喜欢

转载自blog.csdn.net/lmseo5hy/article/details/80829646