MHA手动切换 原创1(主故障)

时间:2022-09-21 21:43:57

MHA提供了3种方式用于实现故障转移,分别自动故障转移,需要启用MHA监控;

在无监控的情况下的手动故障转移以及基于在线手动切换。

三种方式可以应对MySQL主从故障的任意场景。本文主要描述在无监控的情形是手动实现故障转移。供大家参考。

有关MHA的其他两种切换方式,可以参考:
            MHA 在线切换过程            MHA 自动故障转移步骤及过程剖析

1、手动故障转移的特点
    a、在监控节点未启用masterha_manager
    b、master库已经宕机或者转移到高性能服务器
    c、手动故障转移支持交互或非交互两种模式
    d、切换样例:$ masterha_master_switch --master_state=dead --conf=/etc/app1.cnf --dead_master_host=host1

2、masterha_master_switch切换的几个参数
--master_state=dead
      强制参数为"dead" 或者 "alive". dead为手动故障转移,alive为在线切换。
  
--dead_master_host=(hostname)
      强制参数为主机名,另2个--dead_master_ip --dead_master_port(缺省3306)可选。
  
--new_master_host=(hostname)
      可选参数,用于指定新master,如果未指定则按candidate_master参数设定值。
  
--interactive=(0|1)
      可选参数,指定是否交互。缺省为1,表明交互


1.server1:
service mysql.server stop 2.monitor:
[root@monitor tmp]# masterha_master_switch --master_state=dead --conf=/etc/masterha/app1.conf --dead_master_host=server1 --dead_master_port= --new_master_host=slave1 --new_master_port=
--dead_master_ip=<dead_master_ip> is not set. Using 10.24.220.232.
Mon May :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon May :: - [info] Reading application default configuration from /etc/masterha/app1.conf..
Mon May :: - [info] Reading server configuration from /etc/masterha/app1.conf..
Mon May :: - [info] MHA::MasterFailover version 0.56.
Mon May :: - [info] Starting master failover.
Mon May :: - [info]
Mon May :: - [info] * Phase : Configuration Check Phase..
Mon May :: - [info]
Mon May :: - [debug] Connecting to servers..
Mon May :: - [debug] Connected to: slave1(10.24.220.70:), user=root
Mon May :: - [debug] Number of slave worker threads on host slave1(10.24.220.70:):
Mon May :: - [debug] Connected to: slave2(10.169.214.33:), user=root
Mon May :: - [debug] Number of slave worker threads on host slave2(10.169.214.33:):
Mon May :: - [debug] Comparing MySQL versions..
Mon May :: - [debug] Comparing MySQL versions done.
Mon May :: - [debug] Connecting to servers done.
Mon May :: - [info] GTID failover mode =
Mon May :: - [info] Dead Servers:
Mon May :: - [info] server1(10.24.220.232:)
Mon May :: - [info] Checking master reachability via MySQL(double check)...
Mon May :: - [info] ok.
Mon May :: - [info] Alive Servers:
Mon May :: - [info] slave1(10.24.220.70:)
Mon May :: - [info] slave2(10.169.214.33:)
Mon May :: - [info] Alive Slaves:
Mon May :: - [info] slave1(10.24.220.70:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Mon May :: - [info] GTID ON
Mon May :: - [debug] Relay log info repository: FILE
Mon May :: - [info] Replicating from 10.24.220.232(10.24.220.232:)
Mon May :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon May :: - [info] slave2(10.169.214.33:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Mon May :: - [info] GTID ON
Mon May :: - [debug] Relay log info repository: FILE
Mon May :: - [info] Replicating from 10.24.220.232(10.24.220.232:)
Mon May :: - [info] Not candidate for the new Master (no_master is set)
Master server1(10.24.220.232:) is dead. Proceed? (yes/NO): yes
Mon May :: - [info] Starting GTID based failover.
Mon May :: - [info]
Mon May :: - [info] ** Phase : Configuration Check Phase completed.
Mon May :: - [info]
Mon May :: - [info] * Phase : Dead Master Shutdown Phase..
Mon May :: - [info]
Mon May :: - [debug] SSH connection test to server1, option -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o BatchMode=yes -o ConnectTimeout=, timeout
Mon May :: - [debug] Stopping IO thread on slave2(10.169.214.33:)..
Mon May :: - [debug] Stopping IO thread on slave1(10.24.220.70:)..
Mon May :: - [debug] Stop IO thread on slave2(10.169.214.33:) done.
Mon May :: - [debug] Stop IO thread on slave1(10.24.220.70:) done.
Mon May :: - [info] HealthCheck: SSH to server1 is reachable.
Mon May :: - [info] Forcing shutdown so that applications never connect to the current master..
Mon May :: - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.
Mon May :: - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Mon May :: - [info] * Phase : Dead Master Shutdown Phase completed.
Mon May :: - [info]
Mon May :: - [info] * Phase : Master Recovery Phase..
Mon May :: - [info]
Mon May :: - [info] * Phase 3.1: Getting Latest Slaves Phase..
Mon May :: - [info]
Mon May :: - [debug] Fetching current slave status..
Mon May :: - [debug] Fetching current slave status done.
Mon May :: - [info] The latest binary log file/position on all slaves is log.:
Mon May :: - [info] Retrieved Gtid Set: 191f7a9f-ffa2-11e5-a825-00163e00242a:-
Mon May :: - [info] Latest slaves (Slaves that received relay log files to the latest):
Mon May :: - [info] slave1(10.24.220.70:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Mon May :: - [info] GTID ON
Mon May :: - [debug] Relay log info repository: FILE
Mon May :: - [info] Replicating from 10.24.220.232(10.24.220.232:)
Mon May :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon May :: - [info] slave2(10.169.214.33:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Mon May :: - [info] GTID ON
Mon May :: - [debug] Relay log info repository: FILE
Mon May :: - [info] Replicating from 10.24.220.232(10.24.220.232:)
Mon May :: - [info] Not candidate for the new Master (no_master is set)
Mon May :: - [info] The oldest binary log file/position on all slaves is log.:
Mon May :: - [info] Retrieved Gtid Set: 191f7a9f-ffa2-11e5-a825-00163e00242a:-
Mon May :: - [info] Oldest slaves:
Mon May :: - [info] slave1(10.24.220.70:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Mon May :: - [info] GTID ON
Mon May :: - [debug] Relay log info repository: FILE
Mon May :: - [info] Replicating from 10.24.220.232(10.24.220.232:)
Mon May :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon May :: - [info] slave2(10.169.214.33:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Mon May :: - [info] GTID ON
Mon May :: - [debug] Relay log info repository: FILE
Mon May :: - [info] Replicating from 10.24.220.232(10.24.220.232:)
Mon May :: - [info] Not candidate for the new Master (no_master is set)
Mon May :: - [info]
Mon May :: - [info] * Phase 3.3: Determining New Master Phase..
Mon May :: - [info]
Mon May :: - [info] slave1 can be new master.
Mon May :: - [info] New master is slave1(10.24.220.70:)
Mon May :: - [info] Starting master failover..
Mon May :: - [info]
From:
server1(10.24.220.232:) (current master)
+--slave1(10.24.220.70:)
+--slave2(10.169.214.33:) To:
slave1(10.24.220.70:) (new master)
+--slave2(10.169.214.33:) Starting master switch from server1(10.24.220.232:) to slave1(10.24.220.70:)? (yes/NO): yes
Mon May :: - [info] New master decided manually is slave1(10.24.220.70:)
Mon May :: - [info]
Mon May :: - [info] * Phase 3.3: New Master Recovery Phase..
Mon May :: - [info]
Mon May :: - [info] Waiting all logs to be applied..
Mon May :: - [info] done.
Mon May :: - [debug] Stopping slave IO/SQL thread on slave1(10.24.220.70:)..
Mon May :: - [debug] done.
Mon May :: - [info] Getting new master's binlog name and position..
Mon May :: - [info] log.:
Mon May :: - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='slave1 or 10.24.220.70', MASTER_PORT=, MASTER_AUTO_POSITION=, MASTER_USER='repl', MASTER_PASSWORD='xxx';
Mon May :: - [info] Master Recovery succeeded. File:Pos:Exec_Gtid_Set: log., , 191f7a9f-ffa2-11e5-a825-00163e00242a:-
Mon May :: - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.
Mon May :: - [info] ** Finished master recovery successfully.
Mon May :: - [info] * Phase : Master Recovery Phase completed.
Mon May :: - [info]
Mon May :: - [info] * Phase : Slaves Recovery Phase..
Mon May :: - [info]
Mon May :: - [info]
Mon May :: - [info] * Phase 4.1: Starting Slaves in parallel..
Mon May :: - [info]
Mon May :: - [info] -- Slave recovery on host slave2(10.169.214.33:) started, pid: . Check tmp log /var/log/masterha/app1/slave2_3306_20160516091938.log if it takes time..
Mon May :: - [info]
Mon May :: - [info] Log messages from slave2 ...
Mon May :: - [info]
Mon May :: - [info] Resetting slave slave2(10.169.214.33:) and starting replication from the new master slave1(10.24.220.70:)..
Mon May :: - [debug] Stopping slave IO/SQL thread on slave2(10.169.214.33:)..
Mon May :: - [debug] done.
Mon May :: - [info] Executed CHANGE MASTER.
Mon May :: - [debug] Starting slave IO/SQL thread on slave2(10.169.214.33:)..
Mon May :: - [debug] done.
Mon May :: - [info] Slave started.
Mon May :: - [info] gtid_wait(191f7a9f-ffa2-11e5-a825-00163e00242a:-) completed on slave2(10.169.214.33:). Executed events.
Mon May :: - [info] End of log messages from slave2.
Mon May :: - [info] -- Slave on host slave2(10.169.214.33:) started.
Mon May :: - [info] All new slave servers recovered successfully.
Mon May :: - [info]
Mon May :: - [info] * Phase : New master cleanup phase..
Mon May :: - [info]
Mon May :: - [info] Resetting slave info on the new master..
Mon May :: - [debug] Clearing slave info..
Mon May :: - [debug] Stopping slave IO/SQL thread on slave1(10.24.220.70:)..
Mon May :: - [debug] done.
Mon May :: - [debug] SHOW SLAVE STATUS shows new master does not replicate from anywhere. OK.
Mon May :: - [info] slave1: Resetting slave info succeeded.
Mon May :: - [info] Master failover to slave1(10.24.220.70:) completed successfully.
Mon May :: - [debug] Disconnected from slave1(10.24.220.70:)
Mon May :: - [debug] Disconnected from slave2(10.169.214.33:)
Mon May :: - [info] ----- Failover Report ----- app1: MySQL Master failover server1(10.24.220.232:) to slave1(10.24.220.70:) succeeded Master server1(10.24.220.232:) is down! Check MHA Manager logs at monitor for details. Started manual(interactive) failover.
Selected slave1(10.24.220.70:) as a new master.
slave1(10.24.220.70:): OK: Applying all logs succeeded.
slave2(10.169.214.33:): OK: Slave started, replicating from slave1(10.24.220.70:)
slave1(10.24.220.70:): Resetting slave info succeeded.
Master failover to slave1(10.24.220.70:) completed successfully.

MHA手动切换 原创1(主故障)的更多相关文章

  1. MHA手动切换 原创2 (主参与复制&rpar;

    monitor 执行下面命令后, --orig_master_is_new_slave :原主变为新从,即server1变成了slave1的从.slave2跟据app1.conf中配制也变成了slav ...

  2. MHA手动切换 原创4 &lpar;非交互式切换)

    非交互式切换:不输 YES 或者 NO [root@monitor app1]# masterha_master_switch --conf=/etc/masterha/app1.conf --mas ...

  3. 关于mha手动切换的一些记录(mha方案来自网络)

    mha方案出自:http://www.cnblogs.com/xuanzhi201111/p/4231412.html 当主服务器故障时,人工手动调用MHA来进行故障切换操作,具体命令如下: 先停MH ...

  4. MHA 安装过程 原创

    root@monitor yum.repos.d]# cat CentOS-Base.repo [base]name=CentOS-$releasever - Basefailovermethod=p ...

  5. MHA在线切换过程

    MHA 在线切换是MHA除了自动监控切换换提供的另外一种方式,多用于诸如硬件升级,MySQL数据库迁移等等.该方式提供快速切换和优雅的阻塞写入,无关关闭原有服务器,整个切换过程在0.5-2s 的时间左 ...

  6. HA模式手动切换namenode状态

    查看状态 hdfs haadmin -getServiceState nn1 有时候通过网页访问两个namenode的http-address,看到默认的主namenode状态变成了standy,这时 ...

  7. MHA在线切换的步骤及原理

    在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...

  8. MySQL高可用方案MHA在线切换的步骤及原理

    在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...

  9. MySQL主库异常,从库手动切换为主库方案

    主库异常,从库手动切换为主库方案 1.登录从服务器,确认从服务器已经完成所有同步操作: mysql> stop slave io_thread mysql> show processlis ...

随机推荐

  1. Unit06 - 抽象类、接口和内部类(下) 、 面向对象汇总

    Unit06 - 抽象类.接口和内部类(下) . 面向对象汇总 1.多态:  1)意义:    1.1)同一类型的引用指向不同的对象时,有不同的实现        行为的多态:cut().run(). ...

  2. ImageView及其子类

    ImageView及其子类 (1)ImageView继承自View组件,任何Drawable对象都可以用ImageView来显示,ImageView派生出来了ImageButton.ZoomButto ...

  3. UVaLive 6805 Pantun Grader &lpar;恶心的模拟&rpar;

    题意:给定 n 首诗,然后让你给他打分,有四种规则,第一种是按音节打,如果音节在8-12之间,就加10,第二种就是按押韵打,如果13,24一个押韵就加20分. 第三种按音节数打,13,24有一个一样的 ...

  4. Install OpenCV on Ubuntu or Debian

    http://milq.github.io/install-OpenCV-ubuntu-debian/转注:就用第一个方法吧,第二个方法的那个sh文件执行失败,因为我价格kurento.org的源,在 ...

  5. AX2009 批处理作业中使用多线程---批量捆绑

    批量捆绑   由于Ax服务器中批处理线程是可以多个的,而实际批处理作业中线程往往只使用了一个 Class: /* 批量捆绑 */ /*class Code*/ public class DemoBat ...

  6. 正则表达式的一些探索&lpar;偏JavaScript&rpar;

    简单的探索下正则表达式的相关知识,首先先了解下正则表达式的引擎和匹配过程区别,再试着掌握如何在场景中编写正则表达式,再然后探索下根据上文已知的原理和编写过程怎么去优化正则表达式,最后给出一些js里正则 ...

  7. webpack&plus;vue&plus;vueRouter模块化构建完整项目实例详细步骤-入门篇

    新建项目 开始(确认已经安装node环境和npm包管理工具) 1.新建项目文件名为start_vuedemo 2.npm init -y 初始化项目,我的win7系统,工程在d盘的vue_test_p ...

  8. Doracle&period;jdbc&period;J2EE13Compliant&equals;true

    To make the Oracle driver behave in a Java EE-compliant manner, you must define the following JVM pr ...

  9. Java只给汉字转URLEncoder

    public static String encode(String str, String charset) throws UnsupportedEncodingException { Patter ...

  10. android wifi RSSI达到阈值自动断开

    设置wifi的RSSI达到阈值之后自动断开. wifi状态改变,会更新状态栏,在状态栏中更改. --- a/packages/SystemUI/src/com/android/systemui/sta ...