文档章节

MHA切换过程--面试大招

IT--小哥
 IT--小哥
发布于 2017/03/28 18:05
字数 2455
阅读 199
收藏 1

前言:面试中,有部分人比较喜欢问MHA的流程和切换过程,前面一直想自己总结点,但是感觉都不是很到位,今天来放个大招,如果再有人这么问,你就这么回答

 

=================================================================================================
Tue Mar 28 15:55:38 2017 - [warning] Got error on MySQL select ping: 2013 (Lost connection to MySQL server during query)
Tue Mar 28 15:55:38 2017 - [info] Executing SSH check script: save_binary_logs --command=test --start_pos=4 --binlog_dir= --output_file= --manager_version=0.56 --binlog_prefix=mysql-bin
Tue Mar 28 15:55:38 2017 - [info] HealthCheck: SSH to  is reachable.
=================================================================================================
Tue Mar 28 15:55:41 2017 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '' (111))
Tue Mar 28 15:55:41 2017 - [warning] Connection failed 2 time(s)..
Tue Mar 28 15:55:44 2017 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '' (111))
Tue Mar 28 15:55:44 2017 - [warning] Connection failed 3 time(s)..
Tue Mar 28 15:55:47 2017 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '' (111))
Tue Mar 28 15:55:47 2017 - [warning] Connection failed 4 time(s)..
Tue Mar 28 15:55:47 2017 - [warning] Master is not reachable from health checker!
Tue Mar 28 15:55:47 2017 - [warning] Master  is not reachable!
Tue Mar 28 15:55:47 2017 - [warning] SSH is reachable.
=================================================================================================
Tue Mar 28 15:55:47 2017 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/masterha/appl.cnf again, and trying to connect to all servers to check server status..
Tue Mar 28 15:55:47 2017 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Mar 28 15:55:47 2017 - [info] Reading application default configuration from /etc/masterha/appl.cnf..
Tue Mar 28 15:55:47 2017 - [info] Reading server configuration from /etc/masterha/appl.cnf..
Tue Mar 28 15:55:47 2017 - [info] GTID failover mode = 0
Tue Mar 28 15:55:47 2017 - [info] Dead Servers:
Tue Mar 28 15:55:47 2017 - [info]   
Tue Mar 28 15:55:47 2017 - [info] Alive Servers:
Tue Mar 28 15:55:47 2017 - [info]   
Tue Mar 28 15:55:47 2017 - [info] Alive Slaves:
Tue Mar 28 15:55:47 2017 - [info] Version= (oldest major version between slaves) log-bin:enabled
Tue Mar 28 15:55:47 2017 - [info]     Replicating from 
Tue Mar 28 15:55:47 2017 - [info] Checking slave configurations..
Tue Mar 28 15:55:47 2017 - [info]  read_only=1 is not set on slave 
Tue Mar 28 15:55:47 2017 - [warning]  relay_log_purge=0 is not set on slave 
Tue Mar 28 15:55:47 2017 - [info] Checking replication filtering settings..
Tue Mar 28 15:55:47 2017 - [info]  Replication filtering check ok.
Tue Mar 28 15:55:47 2017 - [info] Master is down!
Tue Mar 28 15:55:47 2017 - [info] Terminating monitoring script.
Tue Mar 28 15:55:47 2017 - [info] Got exit code 20 (Master dead).
Tue Mar 28 15:55:47 2017 - [info] MHA::MasterFailover version 0.56.
Tue Mar 28 15:55:47 2017 - [info] Starting master failover.
=================================================================================================
Tue Mar 28 15:55:47 2017 - [info] * Phase 1: Configuration Check Phase..
Tue Mar 28 15:55:47 2017 - [info] 
Tue Mar 28 15:55:47 2017 - [info] GTID failover mode = 0
Tue Mar 28 15:55:47 2017 - [info] Dead Servers:
Tue Mar 28 15:55:47 2017 - [info]   
Tue Mar 28 15:55:47 2017 - [info] Checking master reachability via MySQL(double check)...
Tue Mar 28 15:55:47 2017 - [info]  ok.
Tue Mar 28 15:55:47 2017 - [info] Alive Servers:
Tue Mar 28 15:55:47 2017 - [info]   
Tue Mar 28 15:55:47 2017 - [info] Alive Slaves:
Tue Mar 28 15:55:47 2017 - [info] Version= (oldest major version between slaves) log-bin:enabled
Tue Mar 28 15:55:47 2017 - [info]     Replicating from 
Tue Mar 28 15:55:47 2017 - [info] Starting Non-GTID based failover.
Tue Mar 28 15:55:47 2017 - [info] 
Tue Mar 28 15:55:47 2017 - [info] ** Phase 1: Configuration Check Phase completed.
=================================================================================================
Tue Mar 28 15:55:47 2017 - [info] * Phase 2: Dead Master Shutdown Phase..
Tue Mar 28 15:55:47 2017 - [info] 
Tue Mar 28 15:55:47 2017 - [info] Forcing shutdown so that applications never connect to the current master..
Tue Mar 28 15:55:47 2017 - [info] Executing master IP deactivation script:
Tue Mar 28 15:55:47 2017 - [info]   /usr/local/bin/master_ip_failover --orig_master_host= --orig_master_ip= --orig_master_port= --command=stopssh --ssh_user=  
Tue Mar 28 15:55:47 2017 - [info]  done.
Tue Mar 28 15:55:47 2017 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Tue Mar 28 15:55:47 2017 - [info] * Phase 2: Dead Master Shutdown Phase completed.
=================================================================================================
Tue Mar 28 15:55:47 2017 - [info] * Phase 3: Master Recovery Phase..
Tue Mar 28 15:55:47 2017 - [info] 
Tue Mar 28 15:55:47 2017 - [info] * Phase 3.1: Getting Latest Slaves Phase..
Tue Mar 28 15:55:47 2017 - [info] 
Tue Mar 28 15:55:47 2017 - [info] The latest binary log file/position on all slaves is mysql-bin.000035:17275196
Tue Mar 28 15:55:47 2017 - [info] Latest slaves (Slaves that received relay log files to the latest):
Tue Mar 28 15:55:47 2017 - [info] Version= (oldest major version between slaves) log-bin:enabled
Tue Mar 28 15:55:47 2017 - [info] Replicating from 
Tue Mar 28 15:55:47 2017 - [info] The oldest binary log file/position on all slaves is mysql-bin.000035:17275196
Tue Mar 28 15:55:47 2017 - [info] Oldest slaves:
Tue Mar 28 15:55:47 2017 - [info] Version= (oldest major version between slaves) log-bin:enabled
Tue Mar 28 15:55:47 2017 - [info] Replicating from 
=================================================================================================
Tue Mar 28 15:55:47 2017 - [info] * Phase 3.2: Saving Dead Master's Binlog Phase..
Tue Mar 28 15:55:47 2017 - [info] 
Tue Mar 28 15:55:48 2017 - [info] Fetching dead master's binary logs..
Tue Mar 28 15:55:48 2017 - [info] Executing command on the dead master: save_binary_logs --command=save --start_file=  --start_pos= --binlog_dir= --output_file= --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.56
###############################################################################
##                                !!! ALERT !!!                                #
##                    You are entering into a secured area!                    #
##                                                                             #
##             Your IP, login time and username has been noted and             #
##                  has been sent to the server administrator!                 #
##                                                                             #
##            This service is restricted to authorized users only.             #
##                  All activities on this system are logged.                  #
##                                                                             #
##             Unauthorized access will be fully investigated and              #
##            reported to the appropriate law enforcement agencies.            #
################################################################################

  Creating /tmp if not exists..    ok.
 Concat binary/relay logs from mysql-bin.000035 pos 17275196 to mysql-bin.000035 EOF into /tmp/
 Binlog Checksum enabled
  Dumping binlog format description event, from position 0 to 154.. ok.
  Dumping effective binlog data from  position 17275196 to tail(17275219).. ok.
 Binlog Checksum enabled
 Concat succeeded.
###############################################################################
##                                !!! ALERT !!!                                #
##                    You are entering into a secured area!                    #
##                                                                             #
##             Your IP, login time and username has been noted and             #
##                  has been sent to the server administrator!                 #
##                                                                             #
##            This service is restricted to authorized users only.             #
##                  All activities on this system are logged.                  #
##                                                                             #
##             Unauthorized access will be fully investigated and              #
##            reported to the appropriate law enforcement agencies.            #
################################################################################

Tue Mar 28 15:55:50 2017 - [info] scp from :/tmp/ to local:/var/log/masterha/appl/ succeeded.
Tue Mar 28 15:55:50 2017 - [info] HealthCheck: SSH to  is reachable.
=================================================================================================
Tue Mar 28 15:55:51 2017 - [info] * Phase 3.3: Determining New Master Phase..
Tue Mar 28 15:55:51 2017 - [info] 
Tue Mar 28 15:55:51 2017 - [info] Finding the latest slave that has all relay logs for recovering other slaves..
Tue Mar 28 15:55:51 2017 - [info] All slaves received relay logs to the same position. No need to resync each other.
Tue Mar 28 15:55:51 2017 - [info] Searching new master from slaves..
Tue Mar 28 15:55:51 2017 - [info]  Candidate masters from the configuration file:
Tue Mar 28 15:55:51 2017 - [info]  Non-candidate masters:
Tue Mar 28 15:55:51 2017 - [info] New master is 
Tue Mar 28 15:55:51 2017 - [info] Starting master failover..
Tue Mar 28 15:55:51 2017 - [info] 
From:
 (current master)
 +--

To:
 (new master)
=================================================================================================
Tue Mar 28 15:55:51 2017 - [info] * Phase 3.3: New Master Diff Log Generation Phase..
Tue Mar 28 15:55:51 2017 - [info] 
Tue Mar 28 15:55:51 2017 - [info]  This server has all relay logs. No need to generate diff files from the latest slave.
Tue Mar 28 15:55:51 2017 - [info] Sending binlog..
###############################################################################
##                                !!! ALERT !!!                                #
##                    You are entering into a secured area!                    #
##                                                                             #
##             Your IP, login time and username has been noted and             #
##                  has been sent to the server administrator!                 #
##                                                                             #
##            This service is restricted to authorized users only.             #
##                  All activities on this system are logged.                  #
##                                                                             #
##             Unauthorized access will be fully investigated and              #
##            reported to the appropriate law enforcement agencies.            #
################################################################################

Tue Mar 28 15:55:52 2017 - [info] scp from local:/var/log/masterha/appl/ to root@10.32.136.140:/tmp/ succeeded.
=================================================================================================
Tue Mar 28 15:55:52 2017 - [info] * Phase 3.4: Master Log Apply Phase..
Tue Mar 28 15:55:52 2017 - [info] 
Tue Mar 28 15:55:52 2017 - [info] *NOTICE: If any error happens from this phase, manual recovery is needed.
Tue Mar 28 15:55:52 2017 - [info] Starting recovery on 
Tue Mar 28 15:55:52 2017 - [info]  Generating diffs succeeded.
Tue Mar 28 15:55:52 2017 - [info] Waiting until all relay logs are applied.
Tue Mar 28 15:55:52 2017 - [info]  done.
Tue Mar 28 15:55:52 2017 - [info] Getting slave status..
Tue Mar 28 15:55:52 2017 - [info] This slave's Exec_Master_Log_Pos equals to Read_Master_Log_Pos. No need to recover from Exec_Master_Log_Pos.
Tue Mar 28 15:55:52 2017 - [info] Connecting to the target slave host , running recover script..
Tue Mar 28 15:55:52 2017 - [info] Executing command: apply_diff_relay_logs --command=apply --slave_user= --slave_host= --slave_ip= --slave_port= --apply_files=/tmp/ --workdir=/tmp --target_version= --timestamp=20170328155547 --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.56 --slave_pass=xxx
Tue Mar 28 15:55:53 2017 - [info] 
###############################################################################
##                                !!! ALERT !!!                                #
##                    You are entering into a secured area!                    #
##                                                                             #
##             Your IP, login time and username has been noted and             #
##                  has been sent to the server administrator!                 #
##                                                                             #
##            This service is restricted to authorized users only.             #
##                  All activities on this system are logged.                  #
##                                                                             #
##             Unauthorized access will be fully investigated and              #
##            reported to the appropriate law enforcement agencies.            #
################################################################################

MySQL client version is . Using --binary-mode.
Applying differential binary/relay log files /tmp/ on . This may take long time...
Applying log files succeeded.
Tue Mar 28 15:55:53 2017 - [info]  All relay logs were successfully applied.
Tue Mar 28 15:55:53 2017 - [info] Getting new master's binlog name and position..
Tue Mar 28 15:55:53 2017 - [info]  mysql-bin.000014:5504969
Tue Mar 28 15:55:53 2017 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000014', MASTER_LOG_POS=5504969, MASTER_USER=, MASTER_PASSWORD=;
Tue Mar 28 15:55:53 2017 - [info] Executing master IP activate script:
Tue Mar 28 15:55:53 2017 - [info]   /usr/local/bin/master_ip_failover --command=start --ssh_user= --orig_master_host=--orig_master_ip= --orig_master_port=3306 --new_master_host= --new_master_ip= --new_master_port=3306 --new_master_user= --new_master_password=  
Set read_only=0 on the new master.
###############################################################################
##                                !!! ALERT !!!                                #
##                    You are entering into a secured area!                    #
##                                                                             #
##             Your IP, login time and username has been noted and             #
##                  has been sent to the server administrator!                 #
##                                                                             #
##            This service is restricted to authorized users only.             #
##                  All activities on this system are logged.                  #
##                                                                             #
##             Unauthorized access will be fully investigated and              #
##            reported to the appropriate law enforcement agencies.            #
################################################################################

Warning: Executing wildcard deletion to stay compatible with old scripts.
         Explicitly specify the prefix length () to avoid this warning.
         This special behaviour is likely to disappear in further releases,
         fix your scripts!
###############################################################################
##                                !!! ALERT !!!                                #
##                    You are entering into a secured area!                    #
##                                                                             #
##             Your IP, login time and username has been noted and             #
##                  has been sent to the server administrator!                 #
##                                                                             #
##            This service is restricted to authorized users only.             #
##                  All activities on this system are logged.                  #
##                                                                             #
##             Unauthorized access will be fully investigated and              #
##            reported to the appropriate law enforcement agencies.            #
################################################################################

###############################################################################
##                                !!! ALERT !!!                                #
##                    You are entering into a secured area!                    #
##                                                                             #
##             Your IP, login time and username has been noted and             #
##                  has been sent to the server administrator!                 #
##                                                                             #
##            This service is restricted to authorized users only.             #
##                  All activities on this system are logged.                  #
##                                                                             #
##             Unauthorized access will be fully investigated and              #
##            reported to the appropriate law enforcement agencies.            #
################################################################################

Tue Mar 28 15:55:55 2017 - [info]  OK.
Tue Mar 28 15:55:55 2017 - [info] ** Finished master recovery successfully.
Tue Mar 28 15:55:55 2017 - [info] * Phase 3: Master Recovery Phase completed.
=================================================================================================
Tue Mar 28 15:55:55 2017 - [info] * Phase 4: Slaves Recovery Phase..
=================================================================================================
Tue Mar 28 15:55:55 2017 - [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..
Tue Mar 28 15:55:55 2017 - [info] 
Tue Mar 28 15:55:55 2017 - [info] Generating relay diff files from the latest slave succeeded.
=================================================================================================
Tue Mar 28 15:55:55 2017 - [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..
Tue Mar 28 15:55:55 2017 - [info] 
Tue Mar 28 15:55:55 2017 - [info] All new slave servers recovered successfully.
=================================================================================================
Tue Mar 28 15:55:55 2017 - [info] * Phase 5: New master cleanup phase..
Tue Mar 28 15:55:55 2017 - [info] 
Tue Mar 28 15:55:55 2017 - [info] Resetting slave info on the new master..
Tue Mar 28 15:55:55 2017 - [info]  : Resetting slave info succeeded.
Tue Mar 28 15:55:55 2017 - [info] Master failover to  completed successfully.
=================================================================================================

----- Failover Report -----

appl: MySQL Master failover  to  succeeded

Master  is down!

Check MHA Manager logs at :/var/log/masterha/appl/manager.log for details.

Started automated(non-interactive) failover.
Invalidated master IP address on 
The latest slave  has all relay logs for recovery.
Selected  as a new master.
: OK: Applying all logs succeeded.
: OK: Activated master IP address.
Generating relay diff files from the latest slave succeeded.
: Resetting slave info succeeded.
Master failover to completed successfully.

 

为了方便大家交流,本人开通了微信公众号,和QQ群291519319。喜欢技术的一起来交流吧

© 著作权归作者所有

IT--小哥
粉丝 47
博文 152
码字总数 156670
作品 0
东城
数据库管理员
私信 提问
加载中

评论(4)

IT--小哥
IT--小哥 博主

引用来自“Caelebs”的评论

0.0
:bowtie:
IT--小哥
IT--小哥 博主

引用来自“大哈ha”的评论

我是没看懂。。。
。。。
股神
股神
我是没看懂。。。
OSCHINA首席渣男
OSCHINA首席渣男
0.0
MHA+MySQL实现mysql的高可用

1. MHA的简单介绍 简介 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作为MyS...

wdw王大为
2018/05/25
0
0
MHA+MySQL实现mysql高可用

1. MHA的简单介绍 简介 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作为MyS...

wdw王大为
2018/05/28
0
0
MySQL 高可用解决方案--MHA

MHA(Master High Availability)目前在 MySQL 高可用方面是一个相对成熟的解决方案,它由日本 DeNA 公司的 youshimaton(现就职于 Facebook 公司)开发,是一套优秀的作为 MySQL 高可用性环...

匿名
2017/04/18
3.9K
3
MySQL高可用架构之MHA

简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作为MySQL高可用性环境下...

yanfeilai528
2017/05/22
0
0
Mysql MHA高可用集群架构

记得之前发过一篇文章,名字叫《浅析MySQL高可用架构》,之后一直有很多小伙伴在公众号后台或其它渠道问我,何时有相关的深入配置管理文章出来,因此,民工哥,也将对前面的各类架构逐一进行...

民工哥
2018/01/12
0
0

没有更多内容

加载失败,请刷新页面

加载更多

java通过ServerSocket与Socket实现通信

首先说一下ServerSocket与Socket. 1.ServerSocket ServerSocket是用来监听客户端Socket连接的类,如果没有连接会一直处于等待状态. ServetSocket有三个构造方法: (1) ServerSocket(int port);...

Blueeeeeee
今天
6
0
用 Sphinx 搭建博客时,如何自定义插件?

之前有不少同学看过我的个人博客(http://python-online.cn),也根据我写的教程完成了自己个人站点的搭建。 点此:使用 Python 30分钟 教你快速搭建一个博客 为防有的同学不清楚 Sphinx ,这...

王炳明
昨天
5
0
黑客之道-40本书籍助你快速入门黑客技术免费下载

场景 黑客是一个中文词语,皆源自英文hacker,随着灰鸽子的出现,灰鸽子成为了很多假借黑客名义控制他人电脑的黑客技术,于是出现了“骇客”与"黑客"分家。2012年电影频道节目中心出品的电影...

badaoliumang
昨天
14
0
很遗憾,没有一篇文章能讲清楚线程的生命周期!

(手机横屏看源码更方便) 注:java源码分析部分如无特殊说明均基于 java8 版本。 简介 大家都知道线程是有生命周期,但是彤哥可以认真负责地告诉你网上几乎没有一篇文章讲得是完全正确的。 ...

彤哥读源码
昨天
15
0
jquery--DOM操作基础

本文转载于:专业的前端网站➭jquery--DOM操作基础 元素的访问 元素属性操作 获取:attr(name);$("#my").attr("src"); 设置:attr(name,value);$("#myImg").attr("src","images/1.jpg"); ......

前端老手
昨天
7
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部