zoukankan      html  css  js  c++  java
  • MHA 故障库恢复到集群脚本

    #!/bin/bash

    #注 请把故障库启动后再执行此脚本

    #1.获取mha日志中change语句
    stmt=$(ssh exsddb3 'cat /var/log/masterha/app1/app1.log'|grep 'All other slaves'|grep "`date +%d|cut -d'0' -f2` "|cut -d':' -f4|awk '{sub(/^[ ]+/, "")};1')

    ip=`echo $stmt|cut -d' ' -f6|cut -d"'" -f1`
      pass=`echo $stmt|cut -d'=' -f6|cut -d"'" -f2` #复制用户
        dd='CHANGE MASTER TO MASTER_HOST'
          logfile=`echo $stmt|cut -d'=' -f4|cut -d"'" -f2`
        logpos=`echo $stmt|cut -d'=' -f5|cut -d',' -f1`
      user="MASTER_USER='replication'"
    user='root'
    passw='exsd2017727_SZ8*'

    #2.转换成标准change语句
    change=$(printf "$dd"'='"'""$ip""'","$user",'MASTER_PASSWORD='"'""$pass""'",'MASTER_LOG_FILE='"'""$logfile""'",'MASTER_LOG_POS='"$logpos")
      /usr/local/mysql/bin/mysql -u"$user" -p"$passw" -e 'show slave statusG'
    sleep 1;printf ' '"%s %s "


    #3.在故意库中change到新主库,并启动slave,查看salve状态
    /usr/local/mysql/bin/mysql -u"$user" -p"$passw" -e "$change"
      /usr/local/mysql/bin/mysql -u"$user" -p"$passw" -e "start slave"
    /usr/local/mysql/bin/mysql -u"$user" -p"$passw" -e 'show slave statusG'
    sleep 2

    #4.在manager节点上检查MHA复制状态
    ssh exsddb3 '/usr/bin/masterha_check_repl --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf' >/tmp/check_repl

    a=`cat /tmp/check_repl |grep 'MySQL Replication Health is OK.'`
    #5.判断MHA集群是否OK,若OK就启动manager进程对MHA进行监控,然后查看MHA集群状态
    if [[ "$a" = 'MySQL Replication Health is OK.' ]];then
      echo ' '
        echo ' '
          ssh exsddb3 'sh /sh/mha_start.sh'
       sleep 2
    ssh exsddb3 '/usr/bin/masterha_check_status --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf'
    else
      echo ' '
       echo ' '
    echo 'MySQL Replication Health is not OK!'

    #@_@ 欢迎交流!联系人 广西宾阳 阿桂 qq149951292

  • 相关阅读:
    FPGA-中值滤波
    FPGA-中值滤波
    FPGA-shift_ram代码
    FPGA实现-shift_ram_3x3矩阵实现
    图像处理-中值滤波
    python-str
    ignore-certificate-errors(chrome)
    selenium-python-Cookie跳过登录验证码
    Angular2
    Angular2
  • 原文地址:https://www.cnblogs.com/hmysql/p/7285251.html
Copyright © 2011-2022 走看看