CHANGE MASTER TO MASTER_USER="rpl_user", MASTER_PASSWORD="asAS123456!" FOR CHANNEL 'group_replication_recovery';
# 开启组网数据同步
START GROUP_REPLICATION;
复制代码
当两个从节点都运行完毕后,运行下面SQL效果进行验证:
SELECT * FROM performance_schema.replication_group_members;
复制代码
出现以下情况,每个节点都是ONLINE状态,分析集群搭建成功:
3、MySQL MGR 故障转移
上面已经将MySQL MGR集群搭建完毕,并且节点都是ONLINE状态。
3.1、主节点n0下线,重新推选
首先,在主服务器n0上执行停止mysql命令,如下:
systemctl stop mysqld;
复制代码
此时,在从节点n1检察集群状态发现,n1被推选为主节点:
这是由于MGR集群推选策略为:
优先低版本节点
版本一样,优先权巨大的节点
版本与权重一样,按照 server uuid 的字母顺序选主
在n1从节点上,通过命令检察故障转移日志:
# 查看MySQL日志
tail -n 50 /var/log/mysqld.log
复制代码
n1日志解析如下:
# n0:3306(主节点n0)从组中被移除掉
[Warning] [MY-011499] [Repl] Plugin group_replication reported: 'Members removed from the group: n0:3306'
# 重新选举新的 Primary 主节点
[System] [MY-011500] [Repl] Plugin group_replication reported: 'Primary server with address n0:3306 left the group. Electing new Primary.'
# n1:3306(从节点n1)被选举为主节点,执行之前未完成的事务处理
[System] [MY-011507] [Repl] Plugin group_replication reported: 'A new primary with address n1:3306 was elected. The new primary will execute all previous group transactions before allowing writes.'
# 组成员目前只剩 n1:3306, n2:3306
[System] [MY-011503] [Repl] Plugin group_replication reported: 'Group membership changed to n1:3306, n2:3306 on view 17172171443362674:4.'
# 关闭 n1 节点的只读状态
[System] [MY-013731] [Repl] Plugin group_replication reported: 'The member action "mysql_disable_super_read_only_if_primary" for event "AFTER_PRIMARY_ELECTION" with priority "1" will be run.'
[System] [MY-011510] [Repl] Plugin group_replication reported: 'This server is working as primary member.'
复制代码
在n2从节点上,通过命令检察故障转移日志:
# 查看MySQL日志
tail -n 50 /var/log/mysqld.log
复制代码
n2日志解析如下:
# n0:3306(主节点n0)从组中被移除掉
[Warning] [MY-011499] [Repl] Plugin group_replication reported: 'Members removed from the group: n0:3306'
# 重新选举新的 Primary 主节点
[System] [MY-011500] [Repl] Plugin group_replication reported: 'Primary server with address n0:3306 left the group. Electing new Primary.'
# n1:3306(从节点n1)被选举为主节点,执行之前未完成的事务处理
[System] [MY-011507] [Repl] Plugin group_replication reported: 'A new primary with address n1:3306 was elected. The new primary will execute all previous group transactions before allowing writes.'
# 组成员目前只剩 n1:3306, n2:3306
[System] [MY-011503] [Repl] Plugin group_replication reported: 'Group membership changed to n1:3306, n2:3306 on view 17172171443362674:4.'
# 当前节点(n2)作为主节点(n1)的从成员身份工作
[System] [MY-011511] [Repl] Plugin group_replication reported: 'This server is working as secondary member with primary member address n1:3306.'