MHA切换过程--面试大招

前言:面试中,有部分人比较喜欢问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。喜欢技术的一起来交流吧

转载于:https://my.oschina.net/u/3023401/blog/869408

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值