• MHA 故障库恢复到集群 python脚本


    #!/usr/bin/env python
    #! _*_ coding:utf-8 _*_

    import os,re,time

    #注 请把故障库启动后再执行此脚本
    #1.获取mha日志中change语句
    stmt = os.popen("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'").read().strip(' ')

    ddd = 'CHANGE MASTER TO MASTER_HOST='
    ip = re.findall(r'd+.d+.d+.d+',stmt)[0]
    userf = 'replication'
    passwf = 'replication'
    logfile = re.findall(r"MASTER_LOG_FILE='(.*)', MASTER_LOG",stmt)[0]
    logpos = re.findall(r"MASTER_LOG_POS=(.*), MASTER_USER=",stmt)[0]
    user = 'root'
    passw = 'abc123'
    mysqlbase = '/usr/local/mysql/bin/'

    #2.转换成标准change语句
    change = "%s'%s',MASTER_PASSWORD='%s',MASTER_PORT=%s,MASTER_LOG_FILE='%s',MASTER_LOG_POS=%s,MASTER_USER='%s'" %(ddd,ip,passwf,'3306',logfile,logpos,userf)
    status = os.popen("%smysql -u'%s' -p'%s' -e 'show slave statusG'" %(mysqlbase,user,passw)).read()
    print(' ')

    #3.在故障库中change到新主库,并启动slave,查看salve状态
    os.system("%smysql -u'%s' -p'%s' -e '%s'" %(mysqlbase,user,passw,change))
    os.system("%smysql -u'%s' -p'%s' -e 'start slave'" %(mysqlbase,user,passw))
    os.system("%smysql -u'%s' -p'%s' -e 'show slave statusG'" %(mysqlbase,user,passw))

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

    print(' ')
    print(' ')
    ifok = os.popen("cat /tmp/check_repl |grep 'MySQL Replication Health is OK.'").read().strip(' ')
    #5.判断MHA集群是否OK,若OK就启动manager进程对MHA进行监控,然后查看MHA集群状态
    if ifok == 'MySQL Replication Health is OK.':
         print(' ')
         os.system("ssh exsddb3 'sh /sh/mha_start.sh'")
         time.sleep(2)
         os.system("ssh exsddb3 '/usr/bin/masterha_check_status --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf'")
    else:
         print(' ')
         print('MySQL Replication Health is not OK!')

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

  • 相关阅读:
    115.子集和的目标值(大数据的01背包)
    116. 张程易,编程易(01背包)
    110.科技庄园(多重背包)(未结题)
    113.失恋28天-缝补礼物(多重背包)
    109.关路灯(区间dp)
    107.01背包变式题型:传纸条
    cojs.tk(所有题目来源) 树状数组专练
    在线评测的网站
    108.方格取数
    106.运输装备(二维01背包)
  • 原文地址:https://www.cnblogs.com/hmysql/p/7286352.html
Copyright © 2020-2023  润新知