MHA手动切换 原创1(主故障)
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(主故障)的更多相关文章
- MHA手动切换 原创2 (主参与复制)
monitor 执行下面命令后, --orig_master_is_new_slave :原主变为新从,即server1变成了slave1的从.slave2跟据app1.conf中配制也变成了slav ...
- MHA手动切换 原创4 (非交互式切换)
非交互式切换:不输 YES 或者 NO [root@monitor app1]# masterha_master_switch --conf=/etc/masterha/app1.conf --mas ...
- 关于mha手动切换的一些记录(mha方案来自网络)
mha方案出自:http://www.cnblogs.com/xuanzhi201111/p/4231412.html 当主服务器故障时,人工手动调用MHA来进行故障切换操作,具体命令如下: 先停MH ...
- MHA 安装过程 原创
root@monitor yum.repos.d]# cat CentOS-Base.repo [base]name=CentOS-$releasever - Basefailovermethod=p ...
- MHA在线切换过程
MHA 在线切换是MHA除了自动监控切换换提供的另外一种方式,多用于诸如硬件升级,MySQL数据库迁移等等.该方式提供快速切换和优雅的阻塞写入,无关关闭原有服务器,整个切换过程在0.5-2s 的时间左 ...
- 一个月后,我们又从 MySQL 双主切换成了主 - 从!
这是悟空的第 157 篇原创文章 官网:www.passjava.cn 你好,我是悟空. 一.遇到的坑 一个月前,我们在测试环境部署了一套 MySQL 高可用架构,也就是 MySQL 双主 + Kee ...
- HA模式手动切换namenode状态
查看状态 hdfs haadmin -getServiceState nn1 有时候通过网页访问两个namenode的http-address,看到默认的主namenode状态变成了standy,这时 ...
- MHA在线切换的步骤及原理
在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...
- MySQL高可用方案MHA在线切换的步骤及原理
在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...
随机推荐
- 查看系统或者Jmeter的Properties
工作台-非测试元件-Property Display,可以显示系统或者Jmeter的Properties
- 酷派8150S(移动定制版)可用的第三方Recovery备份数据、刷机并精简系统内置APK经验
希望使用的第三方Recovery下载地址: ClockworkMod ROM Manager - Recoveries http://clockworkmod.com/rommanager 适配的型号 ...
- IAR编译信息分析
1.怎么设置可以查看单片的内存(消耗)使用状况? IAR的菜单栏 -->Tools -->IDE Options -->Messages -->Show build messa ...
- Python常用模块的安装方法
http://blog.163.com/yang_jianli/blog/static/161990006201162152724339/
- wuzhicms访问统计实现方法
实现目标:程序实现了对整站页面pv的统计文件的位置:coreframe/app/content/pv.php代码预览: /** * 总站访问次数统计 */ defined('IN_WZ') or ex ...
- Javascript异步请求你能捕获到异常吗?
Javascript异步请求你能捕获到异常吗? 异常处理是程序发布之前必须要解决的问题,不经过异常处理的应用会让用户对产品失去信心.在异常处理中,我们一贯的做法是按照函数调用的次序,将异常从数据访问层 ...
- lucene学习笔记:二,Lucene的框架
Lucene总的来说是: 一个高效的,可扩展的,全文检索库. 全部用Java实现,无须配置. 仅支持纯文本文件的索引(Indexing)和搜索(Search). 不负责由其他格式的文件抽取纯文本文件, ...
- InputFormat,OutputFormat,InputSplit,RecordRead(一些常见面试题),使用yum安装64位Mysql
列举出hadoop常用的一些InputFormat InputFormat是用来对我们的输入数据进行格式化的.TextInputFormat是默认的. InputFormat有哪些类型? DBInpu ...
- 设置sonar 界面为中文环境
sonar 默认是英文的界面 1.下载http://repository.codehaus.org/org/codehaus/sonar-plugins/l10n/sonar-l10n-zh-plug ...
- javaScript 类型判断
直接上例子: 1 判断是否为数组类型 2 判断是否为字符串类型 3 判断是否为数值类型 4 判断是否为日期类型 5 判断是否为函数 6 判断是否为对象 1 判断是否为数组类型 linenum < ...