zoukankan      html  css  js  c++  java
  • 监控MySQL服务器主从同步异常的脚本,出现异常,报警

    监控主从复制的指标有:

    Slave_IO_Running: Yes 
    Slave_SQL_Running: Yes 
    Seconds_Behind_Master: 0 (从服务器与主服务器延时多少秒)


    #! /bin/bash
    # 指定用户
    USER=root
    # 指定密码
    PASS=123456
    # 指定主机地址
    HOST=localhost
     
    declare -i thread_err=0
    declare -i repl_delay=0
     
    # 将 yes yes 0 赋值 给一个arguments数组
    arguments=(`mysql -u$USER -h$HOST -p$PASS -e "show slave statusG" | awk -F: '/_Running | _Behind_/{print $NF}'`)
     
    # 从数组中取出对应的值,判断是否复制有错误
    for((i=0;i<${#arguments[*]};i++));do
     
    if [ "${arguments[${i}]}" != "Yes" ];then
     
    let thread_err+=1
     
    elif [ "${arguments[${i}]}" != "0" ];then
     
    let repl_delay+=1
     
    else
     
    continue
     
    fi
     
     
    done
     
    # 对于不同的错误进行不同的处理,例如
    if [ $thread_err -gt 0 ];then
     
    echo " IO_THREAD or SQL_THREAD is wrong"
     
    elif [ $repl_delay -gt 0 ];then
     
    echo " replication is delayed"
     
    else
    echo " replication is health !"
     
    fi
  • 相关阅读:
    20210603
    20210602
    20210601
    20210531-已编辑
    2021053101
    操作系统笔记(一)
    尘埃落定,扬帆起航
    RTL级低功耗设计
    关于毛刺
    电路级拾珍
  • 原文地址:https://www.cnblogs.com/liu1026/p/7844236.html
Copyright © 2011-2022 走看看