## ## MySQL 5.6版本引入GTID來解決主從切換時BINLOG位置點難定位的問題,MHA從0.56版本開始支持基於GTID的複製,在發生故障切換時判斷群集是否能採用基於GTID的方式進行切換 ## ##基於GTID進行故障切換的條件:1、所有節點開啟GTID模式,設置gtid_mode= ...
##==========================================##
MySQL 5.6版本引入GTID來解決主從切換時BINLOG位置點難定位的問題,MHA從0.56版本開始支持基於GTID的複製,在發生故障切換時判斷群集是否能採用基於GTID的方式進行切換
##==========================================##
基於GTID進行故障切換的條件:
1、所有節點開啟GTID模式,設置gtid_mode=1
2、所有節點上Executed_Gtid_Set不為空
3、至少一個節點使用Auto_Position=1
##==========================================##
基於GTID進行故障切換:
1、如果候選Master節點不擁有最新的Relay log,那麼將候選Master連接到擁有最新Relay log的Salve上進行日誌補償
2、如果群集中使用Binlog Server,則嘗試從Binlog Server上拉取缺失的Binlog並應用到候選Master上
3、候選Matser擁有最新數據,將其升級為新Master,將其他slave連接到新Master上進行數據同步,可以給masterha_master_switch傳入–wait_until_gtid_in_sync=1參數使其不等其它Slave完成數據同步,以加快切換速度。
##==========================================##
基於GTID模式進行故障切換時,無論原Master節點OS是否正常,都不會嘗試從原Master節點讀取BINLOG進行日誌補償。
基於GTID模式的MHA支持在複製拓撲中使用BINLOG Server來進行日誌補償,而非GTID模式的MHA會忽略BINLOG Server。
建議在基於GTID模式的群集中,不使用MHA進行"手動主從切換",該操作可能會導致原主庫上部分BINLOG丟失。
##==========================================##
在非GTID模式下,會先進行Phase 3.1階段,從擁有最新BINLOG的從庫上獲取差異日誌,再進行Phase 3.2階段,嘗試從原Master伺服器上獲取最新BINLOG。
使用非GTID模式切換的日誌
View Code##==========================================##
在基於GTID模式下,不會進行Phase 3.2階段,即嘗試從原Master伺服器中獲取最新BINLOG。
使用GTID模式切換的日誌:
Sun Jul 8 23:35:21 2018 - [info] MHA::MasterMonitor version 0.56. Sun Jul 8 23:35:21 2018 - [info] GTID failover mode = 1 Sun Jul 8 23:35:21 2018 - [info] Dead Servers: Sun Jul 8 23:35:21 2018 - [info] Alive Servers: Sun Jul 8 23:35:21 2018 - [info] 10.0.203.104(10.0.203.104:3358) Sun Jul 8 23:35:21 2018 - [info] 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:35:21 2018 - [info] 10.0.203.117(10.0.203.117:3358) Sun Jul 8 23:35:21 2018 - [info] Alive Slaves: Sun Jul 8 23:35:21 2018 - [info] 10.0.203.104(10.0.203.104:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:35:21 2018 - [info] GTID ON Sun Jul 8 23:35:21 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:35:21 2018 - [info] Primary candidate for the new Master (candidate_master is set) Sun Jul 8 23:35:21 2018 - [info] 10.0.203.117(10.0.203.117:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:35:21 2018 - [info] GTID ON Sun Jul 8 23:35:21 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:35:21 2018 - [info] Current Alive Master: 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:35:21 2018 - [info] Checking slave configurations.. Sun Jul 8 23:35:21 2018 - [info] read_only=1 is not set on slave 10.0.203.104(10.0.203.104:3358). Sun Jul 8 23:35:21 2018 - [info] read_only=1 is not set on slave 10.0.203.117(10.0.203.117:3358). Sun Jul 8 23:35:21 2018 - [info] Checking replication filtering settings.. Sun Jul 8 23:35:21 2018 - [info] binlog_do_db= , binlog_ignore_db= Sun Jul 8 23:35:21 2018 - [info] Replication filtering check ok. Sun Jul 8 23:35:21 2018 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking. Sun Jul 8 23:35:21 2018 - [info] Checking SSH publickey authentication settings on the current master.. Sun Jul 8 23:35:22 2018 - [info] HealthCheck: SSH to 10.0.203.109 is reachable. Sun Jul 8 23:35:22 2018 - [info] 10.0.203.109(10.0.203.109:3358) (current master) +--10.0.203.104(10.0.203.104:3358) +--10.0.203.117(10.0.203.117:3358) Sun Jul 8 23:35:22 2018 - [warning] master_ip_failover_script is not defined. Sun Jul 8 23:35:22 2018 - [warning] shutdown_script is not defined. Sun Jul 8 23:35:22 2018 - [info] Set master ping interval 1 seconds. Sun Jul 8 23:35:22 2018 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes. Sun Jul 8 23:35:22 2018 - [info] Starting ping health check on 10.0.203.109(10.0.203.109:3358).. Sun Jul 8 23:35:22 2018 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond.. Sun Jul 8 23:35:58 2018 - [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away) Sun Jul 8 23:35:58 2018 - [info] Executing SSH check script: exit 0 Sun Jul 8 23:35:58 2018 - [info] HealthCheck: SSH to 10.0.203.109 is reachable. Sun Jul 8 23:35:59 2018 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at 'reading initial communication packet', system error: 111) Sun Jul 8 23:35:59 2018 - [warning] Connection failed 2 time(s).. Sun Jul 8 23:36:00 2018 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at 'reading initial communication packet', system error: 111) Sun Jul 8 23:36:00 2018 - [warning] Connection failed 3 time(s).. Sun Jul 8 23:36:01 2018 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at 'reading initial communication packet', system error: 111) Sun Jul 8 23:36:01 2018 - [warning] Connection failed 4 time(s).. Sun Jul 8 23:36:01 2018 - [warning] Master is not reachable from health checker! Sun Jul 8 23:36:01 2018 - [warning] Master 10.0.203.109(10.0.203.109:3358) is not reachable! Sun Jul 8 23:36:01 2018 - [warning] SSH is reachable. Sun Jul 8 23:36:01 2018 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/masterha/app1.cnf again, and trying to connect to all servers to check server status.. Sun Jul 8 23:36:01 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Sun Jul 8 23:36:01 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf.. Sun Jul 8 23:36:01 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf.. Sun Jul 8 23:36:01 2018 - [info] GTID failover mode = 1 Sun Jul 8 23:36:01 2018 - [info] Dead Servers: Sun Jul 8 23:36:01 2018 - [info] 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Alive Servers: Sun Jul 8 23:36:01 2018 - [info] 10.0.203.104(10.0.203.104:3358) Sun Jul 8 23:36:01 2018 - [info] 10.0.203.117(10.0.203.117:3358) Sun Jul 8 23:36:01 2018 - [info] Alive Slaves: Sun Jul 8 23:36:01 2018 - [info] 10.0.203.104(10.0.203.104:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Primary candidate for the new Master (candidate_master is set) Sun Jul 8 23:36:01 2018 - [info] 10.0.203.117(10.0.203.117:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Checking slave configurations.. Sun Jul 8 23:36:01 2018 - [info] read_only=1 is not set on slave 10.0.203.104(10.0.203.104:3358). Sun Jul 8 23:36:01 2018 - [info] read_only=1 is not set on slave 10.0.203.117(10.0.203.117:3358). Sun Jul 8 23:36:01 2018 - [info] Checking replication filtering settings.. Sun Jul 8 23:36:01 2018 - [info] Replication filtering check ok. Sun Jul 8 23:36:01 2018 - [info] Master is down! Sun Jul 8 23:36:01 2018 - [info] Terminating monitoring script. Sun Jul 8 23:36:01 2018 - [info] Got exit code 20 (Master dead). Sun Jul 8 23:36:01 2018 - [info] MHA::MasterFailover version 0.56. Sun Jul 8 23:36:01 2018 - [info] Starting master failover. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] * Phase 1: Configuration Check Phase.. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] GTID failover mode = 1 Sun Jul 8 23:36:01 2018 - [info] Dead Servers: Sun Jul 8 23:36:01 2018 - [info] 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Checking master reachability via MySQL(double check)... Sun Jul 8 23:36:01 2018 - [info] ok. Sun Jul 8 23:36:01 2018 - [info] Alive Servers: Sun Jul 8 23:36:01 2018 - [info] 10.0.203.104(10.0.203.104:3358) Sun Jul 8 23:36:01 2018 - [info] 10.0.203.117(10.0.203.117:3358) Sun Jul 8 23:36:01 2018 - [info] Alive Slaves: Sun Jul 8 23:36:01 2018 - [info] 10.0.203.104(10.0.203.104:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Primary candidate for the new Master (candidate_master is set) Sun Jul 8 23:36:01 2018 - [info] 10.0.203.117(10.0.203.117:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Starting GTID based failover. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] ** Phase 1: Configuration Check Phase completed. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] * Phase 2: Dead Master Shutdown Phase.. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] Forcing shutdown so that applications never connect to the current master.. Sun Jul 8 23:36:01 2018 - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address. Sun Jul 8 23:36:01 2018 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master. Sun Jul 8 23:36:01 2018 - [info] * Phase 2: Dead Master Shutdown Phase completed. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] * Phase 3: Master Recovery Phase.. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] * Phase 3.1: Getting Latest Slaves Phase.. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] The latest binary log file/position on all slaves is mysql-bin.000008:6689 Sun Jul 8 23:36:01 2018 - [info] Retrieved Gtid Set: 541e0f07-8047-11e8-8434-0800270b00d2:49-69 Sun Jul 8 23:36:01 2018 - [info] Latest slaves (Slaves that received relay log files to the latest): Sun Jul 8 23:36:01 2018 - [info] 10.0.203.104(10.0.203.104:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Primary candidate for the new Master (candidate_master is set) Sun Jul 8 23:36:01 2018 - [info] 10.0.203.117(10.0.203.117:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] The oldest binary log file/position on all slaves is mysql-bin.000008:6689 Sun Jul 8 23:36:01 2018 - [info] Retrieved Gtid Set: 541e0f07-8047-11e8-8434-0800270b00d2:49-69 Sun Jul 8 23:36:01 2018 - [info] Oldest slaves: Sun Jul 8 23:36:01 2018 - [info] 10.0.203.104(10.0.203.104:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Primary candidate for the new Master (candidate_master is set) Sun Jul 8 23:36:01 2018 - [info] 10.0.203.117(10.0.203.117:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] * Phase 3.3: Determining New Master Phase.. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] Searching new master from slaves.. Sun Jul 8 23:36:01 2018 - [info] Candidate masters from the configuration file: Sun Jul 8 23:36:01 2018 - [info] 10.0.203.104(10.0.203.104:3358) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled Sun Jul 8 23:36:01 2018 - [info] GTID ON Sun Jul 8 23:36:01 2018 - [info] Replicating from 10.0.203.109(10.0.203.109:3358) Sun Jul 8 23:36:01 2018 - [info] Primary candidate for the new Master (candidate_master is set) Sun Jul 8 23:36:01 2018 - [info] Non-candidate masters: Sun Jul 8 23:36:01 2018 - [info] Searching from candidate_master slaves which have received the latest relay log events.. Sun Jul 8 23:36:01 2018 - [info] New master is 10.0.203.104(10.0.203.104:3358) Sun Jul 8 23:36:01 2018 - [info] Starting master failover.. Sun Jul 8 23:36:01 2018 - [info] From: 10.0.203.109(10.0.203.109:3358) (current master) +--10.0.203.104(10.0.203.104:3358) +--10.0.203.117(10.0.203.117:3358) To: 10.0.203.104(10.0.203.104:3358) (new master) +--10.0.203.117(10.0.203.117:3358) Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] * Phase 3.3: New Master Recovery Phase.. Sun Jul 8 23:36:01 2018 - [info] Sun Jul 8 23:36:01 2018 - [info] Waiting all logs to be applied.. Sun Jul 8 23:36:01 2018 - [info] done. Sun Jul 8 23:36:01 2018 - [info] Getting new master's binlog name and position.. Sun Jul 8 23: