Linux论坛
直播中

氧化

7年用户 749经验值
擅长:可编程逻辑 嵌入式技术
私信 关注
[资料]

请问MySQL数据库如何监控主从故障是否正常?

写监控脚本 不同步时发送邮件
  1. #!/bin/bash
  2. . /etc/init.d/functions
  3. function check(){
  4. rep_file=/tmp/rep$(date +%F).txt
  5. while true
  6. do
  7. rep=(`/application/mysql/bin/mysql -e "show slave statusG"|awk '/Slave_SQL_Running:/{print $2};/Slave_IO_Running:/{print $2};$1~/Seconds_Behind_Master/{print $2}'|xargs`)
  8.   if [ "${rep[0]}" != "Yes" ]; then
  9.      echo "Slave_IO_Running: NO" >$rep_file
  10.      break 1
  11.   fi
  12.   if [ "${rep[1]}" != "Yes" ]; then
  13.      echo "Slave_SQL_Running: NO" >$rep_file
  14.   fi

  15.   if [ "${rep[2]}" -ne 0 ]; then
  16.      echo " Seconds_Behind_Master delay" >$rep_file
  17.      break 1
  18.   fi
  19.   sleep 3
  20. done
  21. }

  22. function main(){
  23.   while true
  24.   do
  25.      check
  26.      mail -s "replication false" 861740772@qq.com


更多回帖

发帖
×
20
完善资料,
赚取积分