##==========================================##

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模式切换的日志


##==========================================##
在基于GTID模式下,不会进行Phase 3.2阶段,即尝试从原Master服务器中获取最新BINLOG。

使用GTID模式切换的日志:

Sun Jul   ::  - [info] MHA::MasterMonitor version 0.56.
Sun Jul :: - [info] GTID failover mode =
Sun Jul :: - [info] Dead Servers:
Sun Jul :: - [info] Alive Servers:
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:)
Sun Jul :: - [info] 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] 10.0.203.117(10.0.203.117:)
Sun Jul :: - [info] Alive Slaves:
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Primary candidate for the new Master (candidate_master is set)
Sun Jul :: - [info] 10.0.203.117(10.0.203.117:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Current Alive Master: 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Checking slave configurations..
Sun Jul :: - [info] read_only= is not set on slave 10.0.203.104(10.0.203.104:).
Sun Jul :: - [info] read_only= is not set on slave 10.0.203.117(10.0.203.117:).
Sun Jul :: - [info] Checking replication filtering settings..
Sun Jul :: - [info] binlog_do_db= , binlog_ignore_db=
Sun Jul :: - [info] Replication filtering check ok.
Sun Jul :: - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Sun Jul :: - [info] Checking SSH publickey authentication settings on the current master..
Sun Jul :: - [info] HealthCheck: SSH to 10.0.203.109 is reachable.
Sun Jul :: - [info]
10.0.203.109(10.0.203.109:) (current master)
+--10.0.203.104(10.0.203.104:)
+--10.0.203.117(10.0.203.117:) Sun Jul :: - [warning] master_ip_failover_script is not defined.
Sun Jul :: - [warning] shutdown_script is not defined.
Sun Jul :: - [info] Set master ping interval seconds.
Sun Jul :: - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Sun Jul :: - [info] Starting ping health check on 10.0.203.109(10.0.203.109:)..
Sun Jul :: - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
Sun Jul :: - [warning] Got error on MySQL select ping: (MySQL server has gone away)
Sun Jul :: - [info] Executing SSH check script: exit
Sun Jul :: - [info] HealthCheck: SSH to 10.0.203.109 is reachable.
Sun Jul :: - [warning] Got error on MySQL connect: (Lost connection to MySQL server at 'reading initial communication packet', system error: )
Sun Jul :: - [warning] Connection failed time(s)..
Sun Jul :: - [warning] Got error on MySQL connect: (Lost connection to MySQL server at 'reading initial communication packet', system error: )
Sun Jul :: - [warning] Connection failed time(s)..
Sun Jul :: - [warning] Got error on MySQL connect: (Lost connection to MySQL server at 'reading initial communication packet', system error: )
Sun Jul :: - [warning] Connection failed time(s)..
Sun Jul :: - [warning] Master is not reachable from health checker!
Sun Jul :: - [warning] Master 10.0.203.109(10.0.203.109:) is not reachable!
Sun Jul :: - [warning] SSH is reachable.
Sun Jul :: - [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 :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Jul :: - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Sun Jul :: - [info] Reading server configuration from /etc/masterha/app1.cnf..
Sun Jul :: - [info] GTID failover mode =
Sun Jul :: - [info] Dead Servers:
Sun Jul :: - [info] 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Alive Servers:
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:)
Sun Jul :: - [info] 10.0.203.117(10.0.203.117:)
Sun Jul :: - [info] Alive Slaves:
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Primary candidate for the new Master (candidate_master is set)
Sun Jul :: - [info] 10.0.203.117(10.0.203.117:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Checking slave configurations..
Sun Jul :: - [info] read_only= is not set on slave 10.0.203.104(10.0.203.104:).
Sun Jul :: - [info] read_only= is not set on slave 10.0.203.117(10.0.203.117:).
Sun Jul :: - [info] Checking replication filtering settings..
Sun Jul :: - [info] Replication filtering check ok.
Sun Jul :: - [info] Master is down!
Sun Jul :: - [info] Terminating monitoring script.
Sun Jul :: - [info] Got exit code (Master dead).
Sun Jul :: - [info] MHA::MasterFailover version 0.56.
Sun Jul :: - [info] Starting master failover.
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase : Configuration Check Phase..
Sun Jul :: - [info]
Sun Jul :: - [info] GTID failover mode =
Sun Jul :: - [info] Dead Servers:
Sun Jul :: - [info] 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Checking master reachability via MySQL(double check)...
Sun Jul :: - [info] ok.
Sun Jul :: - [info] Alive Servers:
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:)
Sun Jul :: - [info] 10.0.203.117(10.0.203.117:)
Sun Jul :: - [info] Alive Slaves:
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Primary candidate for the new Master (candidate_master is set)
Sun Jul :: - [info] 10.0.203.117(10.0.203.117:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Starting GTID based failover.
Sun Jul :: - [info]
Sun Jul :: - [info] ** Phase : Configuration Check Phase completed.
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase : Dead Master Shutdown Phase..
Sun Jul :: - [info]
Sun Jul :: - [info] Forcing shutdown so that applications never connect to the current master..
Sun Jul :: - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.
Sun Jul :: - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Sun Jul :: - [info] * Phase : Dead Master Shutdown Phase completed.
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase : Master Recovery Phase..
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase 3.1: Getting Latest Slaves Phase..
Sun Jul :: - [info]
Sun Jul :: - [info] The latest binary log file/position on all slaves is mysql-bin.:
Sun Jul :: - [info] Retrieved Gtid Set: 541e0f07--11e8--0800270b00d2:-
Sun Jul :: - [info] Latest slaves (Slaves that received relay log files to the latest):
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Primary candidate for the new Master (candidate_master is set)
Sun Jul :: - [info] 10.0.203.117(10.0.203.117:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] The oldest binary log file/position on all slaves is mysql-bin.:
Sun Jul :: - [info] Retrieved Gtid Set: 541e0f07--11e8--0800270b00d2:-
Sun Jul :: - [info] Oldest slaves:
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Primary candidate for the new Master (candidate_master is set)
Sun Jul :: - [info] 10.0.203.117(10.0.203.117:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase 3.3: Determining New Master Phase..
Sun Jul :: - [info]
Sun Jul :: - [info] Searching new master from slaves..
Sun Jul :: - [info] Candidate masters from the configuration file:
Sun Jul :: - [info] 10.0.203.104(10.0.203.104:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Sun Jul :: - [info] GTID ON
Sun Jul :: - [info] Replicating from 10.0.203.109(10.0.203.109:)
Sun Jul :: - [info] Primary candidate for the new Master (candidate_master is set)
Sun Jul :: - [info] Non-candidate masters:
Sun Jul :: - [info] Searching from candidate_master slaves which have received the latest relay log events..
Sun Jul :: - [info] New master is 10.0.203.104(10.0.203.104:)
Sun Jul :: - [info] Starting master failover..
Sun Jul :: - [info]
From:
10.0.203.109(10.0.203.109:) (current master)
+--10.0.203.104(10.0.203.104:)
+--10.0.203.117(10.0.203.117:) To:
10.0.203.104(10.0.203.104:) (new master)
+--10.0.203.117(10.0.203.117:)
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase 3.3: New Master Recovery Phase..
Sun Jul :: - [info]
Sun Jul :: - [info] Waiting all logs to be applied..
Sun Jul :: - [info] done.
Sun Jul :: - [info] Getting new master's binlog name and position..
Sun Jul :: - [info] mysql-bin.:
Sun Jul :: - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='10.0.203.104', MASTER_PORT=, MASTER_AUTO_POSITION=, MASTER_USER='replicater', MASTER_PASSWORD='xxx';
Sun Jul :: - [info] Master Recovery succeeded. File:Pos:Exec_Gtid_Set: mysql-bin., , 41d8a420--11e8--080027e837eb:-,
541e0f07--11e8--0800270b00d2:-
Sun Jul :: - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.
Sun Jul :: - [info] ** Finished master recovery successfully.
Sun Jul :: - [info] * Phase : Master Recovery Phase completed.
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase : Slaves Recovery Phase..
Sun Jul :: - [info]
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase 4.1: Starting Slaves in parallel..
Sun Jul :: - [info]
Sun Jul :: - [info] -- Slave recovery on host 10.0.203.117(10.0.203.117:) started, pid: . Check tmp log /var/log/masterha/app1/10.0..117_3358_20180708233601.log if it takes time..
Sun Jul :: - [info]
Sun Jul :: - [info] Log messages from 10.0.203.117 ...
Sun Jul :: - [info]
Sun Jul :: - [info] Resetting slave 10.0.203.117(10.0.203.117:) and starting replication from the new master 10.0.203.104(10.0.203.104:)..
Sun Jul :: - [info] Executed CHANGE MASTER.
Sun Jul :: - [info] Slave started.
Sun Jul :: - [info] gtid_wait(41d8a420--11e8--080027e837eb:-,
541e0f07--11e8--0800270b00d2:-) completed on 10.0.203.117(10.0.203.117:). Executed events.
Sun Jul :: - [info] End of log messages from 10.0.203.117.
Sun Jul :: - [info] -- Slave on host 10.0.203.117(10.0.203.117:) started.
Sun Jul :: - [info] All new slave servers recovered successfully.
Sun Jul :: - [info]
Sun Jul :: - [info] * Phase : New master cleanup phase..
Sun Jul :: - [info]
Sun Jul :: - [info] Resetting slave info on the new master..
Sun Jul :: - [info] 10.0.203.104: Resetting slave info succeeded.
Sun Jul :: - [info] Master failover to 10.0.203.104(10.0.203.104:) completed successfully.
Sun Jul :: - [info] ----- Failover Report ----- app1: MySQL Master failover 10.0.203.109(10.0.203.109:) to 10.0.203.104(10.0.203.104:) succeeded Master 10.0.203.109(10.0.203.109:) is down! Check MHA Manager logs at localhost.localdomain:/var/log/masterha/app1/manager.log for details. Started automated(non-interactive) failover.
Selected 10.0.203.104(10.0.203.104:) as a new master.
10.0.203.104(10.0.203.104:): OK: Applying all logs succeeded.
10.0.203.117(10.0.203.117:): OK: Slave started, replicating from 10.0.203.104(10.0.203.104:)
10.0.203.104(10.0.203.104:): Resetting slave info succeeded.
Master failover to 10.0.203.104(10.0.203.104:) completed successfully.

##==========================================##
MHA在检查时,使用SHOW SLAVE STATUS获取结构中Auto_Position的值来判断是否使用master_auto_position参数来搭建主从复制。

MHA在切换时,如果使用非GTID模式切换,则在CHANGE MASTER中不会带上参数master_auto_position=0,而如果该从库之前配置为master_auto_position=1,那么CHANGE MASTER会报错,无法正常进行切换。

因此不能简单修改Server.PM或DBHelper.pm文件来将基于GTID模式切换的群集修改为使用非GTID模式进行切换。

##==========================================##

如果群集因为某种原因导致主从节点上的Executed_Gtid_Set不同,如:

1、对从库进行直接授权,导致从库比主库拥有更多BINLOG,但该Binlog因各种原因被Purged掉

2、群集做过版本升级,从未使用GTID的版本升级到GTID版本,从库上曾一段时间内作为主库提供服务,但该时间段日志被Purged掉

有上诉类似问题时,将从库提升为主库并使用master_auto_position=1来配置复制,复制会因为新主库无法提供足够BINLOG事件而失败。

处理办法:

1、通过RESET MASTER和SET GLOBAL gtid_purged=''使得所有节点拥有相同的GTID 集合

2、将所有复制修改为基于POS点搭建的复制。

##==========================================##

MySQL--MHA与GTID的更多相关文章

  1. mysql MHA架构搭建过程

    [环境介绍] 系统环境:Red Hat Enterprise Linux 7 + 5.7.18 + MHA version 0.57 系统 IP 主机名 备注 版本 xx系统 192.168.142. ...

  2. CentOS6.8下MySQL MHA架构搭建笔记

    转载请注明出处,本文地址:http://www.cnblogs.com/ajiangg/p/6552855.html 以下是CentOS6.8下MySQL MHA架构搭建笔记 IP资源规划: 192. ...

  3. MHA failover GTID 专题

    https://yq.aliyun.com/articles/238882?spm=5176.8067842.tagmain.18.73PjU3 摘要: MHA failover GTID 专题 这里 ...

  4. MySQL MHA 搭建&测试(环境:CentOS7 + MySQL5.7.23)

    MySQL MHA架构介绍: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Face ...

  5. 基于Docker Compose构建的MySQL MHA集群

    Docker MySQL MHA 基于Docker 1.13.1之上构建的MySQL MHA Docker Compose Project 可快速启动GTID模式下的MasterHA集群, 主用于My ...

  6. MySQL MHA+Keepalived

    一.MHA的简单介绍MHA是由perl语言编写的,用外挂脚本的方式实现mysql主从复制的高可用性.MHA可以自动检测mysql是否宕机,如果宕机,在10-30s内完成new master的选举,应用 ...

  7. MySQL MHA相关测试

    接上篇文章,介绍了如何安装mysql mha,地址如下:http://blog.csdn.net/yiyuf/article/details/40340895 下面接着进行mha的相关测试: SSH  ...

  8. 基于MySQL+MHA+Haproxy部署高可用负载均衡集群

    一.MHA 概述 MHA(Master High Availability)是可以在MySQL上使用的一套高可用方案.所编写的语言为Perl 从名字上我们可以看到.MHA的目的就是为了维护Master ...

  9. 【线上测试之后的应用】基于MySQL+MHA+Haproxy构建高可用负载均衡数据库集群(详解)

    这里我们先介绍一下MHA是什么,其次就是它的应用与测试,同时为了大家呈现了数据备份案例,最后总结了使用情况以及注意事项和解决办法 一.MHA 概述 MHA(Master High Availabili ...

  10. MySQL MHA高可用集群部署及故障切换

    一.MHA概念MHA(MasterHigh Availability)是一套优秀的MySQL高可用环境下故障切换和主从复制的软件.MHA 的出现就是解决MySQL 单点的问题.MySQL故障切换过程中 ...

随机推荐

  1. [Mysql]一些知识点

    Mysql引擎类型 InnoDB: 行级锁->写性能略优:支持事务 MYISAM: 表级锁->读性能优:不支持事务 表示时间的类型 datetime 可表示时间范围大 1000-9999. ...

  2. Ubuntu ROS

    设置你的sources.list 将电脑设置为接受来自packages.ros.org的软件 sudo sh -c 'echo "deb http://packages.ros.org/ro ...

  3. Openssl asn1parse命令

    一.简介 asn1parse命令是一种用来诊断ASN.1结构的工具,也能用于从ASN1.1数据中提取数据 二.语法 openssl asn1parse [-inform PEM|DER] [-in f ...

  4. java 得到项目路径

    JavaEXTTomcatJSPWeb 一 相对路径的获得  说明:相对路径(即不写明时候到底相对谁)均可通过以下方式获得(不论是一般的java项目还是web项目)  String relativel ...

  5. apache-tomcat 部分中文.html .jsp 连接 404问题

    修改文件到 自己的安装目录:\apache-tomcat-7.0.79\conf 添加   Connector URIEncoding="utf-8" <Connector ...

  6. 【aardio】回车换行符

    回车换行符 在计算机还没有出现之前,有一种叫做电传打字机(Teletype Model 33)的玩意,每秒钟可以打10个字符.但是它有一个问题,就是打完一行换行的时候,要用去0.2秒,正好可以打两个字 ...

  7. tomcat修改banner,隐藏版本号

    为了避免黑客针对某些版本进行攻击,因此我们需要隐藏或者伪装 Tomcat 的版本信息.针对该信息的显示是由一个jar包控制的,该jar包存放在 Tomcat 安装目录下的lib目录下,名称为 cata ...

  8. spring Resource(转)

    http://blog.csdn.net/u011225629/article/details/47143075

  9. K/3 Cloud移动BOS开发技巧 -- K/3 Cloud多数据中心时如何支持发布到云之家.

    我们知道K/3 Cloud和云之家进行集成,在管理中心里面有个设置,移动账套启用,只能支持一个账套启用那么能不能支持两个账套部署到云之家中呢?其实移动BOS平台默认是支持,答案就在发布到云之家的菜单中 ...

  10. jhipster安装_Windows

    1:安装 Node.js lts版本的 https://nodejs.org/en/ 2:安装Yarn https://yarn.bootcss.com/docs/install.html 3:修改y ...