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

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. route的简单使用

    route [add|del] [-net|-host] target [netmask Nm] [gw Gw] [[dev] If] add : 添加一条路由规则del : 删除一条路由规则-net ...

  2. angular4模块中标签添加背景图

    一.现象 一个全屏的“走马灯”每项需要添加背景图,在循环标签里需要动态添加行内样式 二.解决 1.首先有一个图片数组,如: export class AppComponent { array = [& ...

  3. Oracle 12c 创建新的数据库实例、用户

    前提:安装好了Oracle 12c数据库,已有一个数据库实例xe,登录用户/密码:system/oralce 我用的是docker安装的Oracle 12c的实例: docker run --name ...

  4. element-ui

    配合vue的前端样式组建   element-ui 1,基础布局 <el-row> <el-col :span="8"></el-col> &l ...

  5. Pytorch之训练器设置

    Pytorch之训练器设置 引言 深度学习训练的时候有很多技巧, 但是实际用起来效果如何, 还是得亲自尝试. 这里记录了一些个人尝试不同技巧的代码. tensorboardX 说起tensorflow ...

  6. 优美序列(sequence)

    问题描述 Lxy养了N头奶牛,他把N头奶牛用1..N编号,第i头奶牛编号为i.为了让奶牛多产奶,每天早上他都会让奶牛们排成一排做早操.奶牛们是随机排列的.在奶牛排列中,如果一段区间[L,R]中的数从小 ...

  7. 1,fiddler的工作原理和安装

    1,工作原理就是通过设置代理监控客户端和服务端的协议 2,fiddler的安装 1,官方的下载地址:https://www.telerik.com/download/fiddler 一步步安装即可 2 ...

  8. 关于tomcat7配置maxPostSize=“0”时,后台无法接收前台参数的问题

    Post提交参数时,如果参数值的长度太长,后台通过Map<String, String[]> requestParameterMap=request.getParameterMap();获 ...

  9. 【MyBatis-Spring】Mybatis和并入Spring框架

    1.参考书籍:<深入浅出MyBatis技术原理与实战> 2.知识基础:Spring.Mybatis.Spring MVC. 配置数据源 配置SqlSessionFactory SqlSes ...

  10. RNQOJ PID28 / [Stupid]愚蠢的宠物

    勉勉强强够着点并查集的边,题目吧他分类到并查集也无可厚非,这里与常规的并查集的区别在于要做一个mark数组进行一下标记,展开来说就是对于要查询的A,B,先对A进行处理,把A所有的前驱也就是双亲节点进行 ...