环境信息

IP port role info
192.168.188.51 4000 node1 master
192.168.188.52 4000 node2 slave1
192.168.188.53 4000 node3 slave2
  • CentOS Linux release 7.8.2003 (Core)
  • mysql-5.7.30-linux-glibc2.12-x86_64

软件位置

在三个节点上部署好MySQL

搭建复制环境,并开启增强半同步

  • 所有节点配置
mysql> set global super_read_only=0;
Query OK, 0 rows affected (0.00 sec) mysql> create user 'rep'@'192.168.188.%' identified by 'rep';
Query OK, 0 rows affected (0.03 sec) mysql> grant replication slave on *.* to 'rep'@'192.168.188.%';
Query OK, 0 rows affected (0.12 sec) mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.04 sec) mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.07 sec)
  • master节点配置
mysql> set global rpl_semi_sync_master_enabled=ON;
Query OK, 0 rows affected (0.00 sec) mysql> show global variables like '%semi%';
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | ON |
| rpl_semi_sync_master_timeout | 10000 |
| rpl_semi_sync_master_trace_level | 32 |
| rpl_semi_sync_master_wait_for_slave_count | 1 |
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
| rpl_semi_sync_slave_enabled | OFF |
| rpl_semi_sync_slave_trace_level | 32 |
+-------------------------------------------+------------+
8 rows in set (0.05 sec) mysql> reset master;
Query OK, 0 rows affected (0.14 sec)
  • slave节点配置
mysql> set global rpl_semi_sync_slave_enabled=ON;
Query OK, 0 rows affected (0.00 sec) mysql> change master to master_host='192.168.188.51',master_port=4000,master_user='rep',master_password='rep',master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.64 sec) mysql> reset master;
Query OK, 0 rows affected (0.23 sec)
  • slave 启动复制
mysql>  start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
  • master查看半同步状态
mysql> show global status like '%semi%';
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 2 |
| Rpl_semi_sync_master_net_avg_wait_time | 0 |
| Rpl_semi_sync_master_net_wait_time | 0 |
| Rpl_semi_sync_master_net_waits | 0 |
| Rpl_semi_sync_master_no_times | 0 |
| Rpl_semi_sync_master_no_tx | 0 |
| Rpl_semi_sync_master_status | ON |
| Rpl_semi_sync_master_timefunc_failures | 0 |
| Rpl_semi_sync_master_tx_avg_wait_time | 0 |
| Rpl_semi_sync_master_tx_wait_time | 0 |
| Rpl_semi_sync_master_tx_waits | 0 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 0 |
| Rpl_semi_sync_slave_status | OFF |
+--------------------------------------------+-------+
15 rows in set (0.00 sec)

模拟业务,使用脚本产生事务

  • 建表
mysql> create database kk;
Query OK, 1 row affected (0.12 sec) mysql> use kk
Database changed
mysql> create table k1 ( id int auto_increment primary key , dtl varchar(20) default 'abc');
Query OK, 0 rows affected (0.51 sec)
  • 开启一个session,运行脚本产生事务
[14:13:16] root@ms51:~ # while :; do  echo "insert into kk.k1(dtl) values('duangduangduang');" | mysql -S /data/mysql/mysql4000/tmp/mysql.sock; sleep 1;done

手动配置MGR

配置Master,将Master转为MGR

  • 配置参数
mysql> install plugin group_replication soname 'group_replication.so';
Query OK, 0 rows affected (0.15 sec) mysql> set global binlog_checksum=NONE;
Query OK, 0 rows affected (0.18 sec) mysql> set global transaction_write_set_extraction=XXHASH64;
Query OK, 0 rows affected (0.00 sec) mysql> select uuid();
+--------------------------------------+
| uuid() |
+--------------------------------------+
| a3e8c286-e375-11ea-868b-0242c0a8bc33 |
+--------------------------------------+
1 row in set (0.01 sec) mysql> set global group_replication_group_name='a3e8c286-e375-11ea-868b-0242c0a8bc33';
Query OK, 0 rows affected (0.00 sec) mysql> set global group_replication_local_address="192.168.188.51:13306"
-> ;
Query OK, 0 rows affected (0.00 sec) mysql> set global group_replication_group_seeds="192.168.188.51:13306,192.168.188.52:13306,192.168.188.53:13306";
Query OK, 0 rows affected (0.01 sec) mysql> set global group_replication_start_on_boot=off;
Query OK, 0 rows affected (0.00 sec) mysql> set global group_replication_bootstrap_group=on;
Query OK, 0 rows affected (0.00 sec) mysql> start group_replication;
Query OK, 0 rows affected (2.82 sec) mysql> set global group_replication_bootstrap_group=off;
Query OK, 0 rows affected (0.00 sec) mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | e630ab09-e372-11ea-8a64-0242c0a8bc33 | ms51 | 4000 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
1 row in set (0.00 sec) 补充,还有这关键的一步(原因见文末):
mysql> change master to master_user='rep',master_password='rep' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.05 sec)

由于MySQL 5.7 不支持参数持久化语法 set persist,因此MGR相关的参数我们要手动合并到master实例的my.cnf文件

binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name='a3e8c286-e375-11ea-868b-0242c0a8bc33'
loose-group_replication_local_address="192.168.188.51:13306"
loose-group_replication_group_seeds="192.168.188.51:13306,192.168.188.52:13306,192.168.188.53:13306"
loose-group_replication_bootstrap_group=off
loose-group_replication_start_on_boot=off

去配置slave1 ,转换为MGR

mysql> install plugin group_replication soname 'group_replication.so';
Query OK, 0 rows affected (0.04 sec) mysql> set global binlog_checksum=NONE;
Query OK, 0 rows affected (0.23 sec) mysql> set global transaction_write_set_extraction=XXHASH64;
Query OK, 0 rows affected (0.00 sec) mysql> set global group_replication_group_name='a3e8c286-e375-11ea-868b-0242c0a8bc33';
Query OK, 0 rows affected (0.00 sec) mysql> set global group_replication_local_address="192.168.188.52:13306";
Query OK, 0 rows affected (0.00 sec) mysql> set global group_replication_group_seeds="192.168.188.51:13306,192.168.188.52:13306,192.168.188.53:13306";
Query OK, 0 rows affected (0.01 sec) mysql> change master to master_user='rep',master_password='rep' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.47 sec) mysql> start group_replication;
ERROR 3092 (HY000): The server is not configured properly to be an active member of the group. Please see more details on error log.
mysql> exit

启动MGR失败,按照提示去检查errorlog,原来复制进行时无法启动MGR

[14:50:50] root@ms52:~ # less /data/mysql/mysql4000/logs/error.log
...
2020-08-21T14:50:43.791879+08:00 2 [Note] Plugin group_replication reported: 'Member configuration: member_id: 524000; member_uuid: "aee85149-e379-11ea-8c01-0242c0a8bc34"; single-primary mode: "true"; group_replication_auto_increment_increment: 7; '
2020-08-21T14:50:43.791901+08:00 2 [ERROR] Plugin group_replication reported: 'Can't start group replication on secondary member with single primary-mode while asynchronous replication channels are running.'
2020-08-21T14:50:43.791930+08:00 2 [Note] Plugin group_replication reported: 'Requesting to leave the group despite of not being a member'
2020-08-21T14:50:43.791944+08:00 2 [ERROR] Plugin group_replication reported: '[GCS] The member is leaving a group without being on one.'

停止复制,启动MGR便成功了,稍等片刻,节点状态便ONLINE了。

[14:51:32] root@ms52:~ # mysql -S /data/mysql/mysql4000/tmp/mysql.sock

mysql> stop slave;
Query OK, 0 rows affected (0.09 sec) mysql> start group_replication;
Query OK, 0 rows affected (6.61 sec) mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | ab726fa8-e379-11ea-a4c2-0242c0a8bc33 | ms51 | 4000 | ONLINE |
| group_replication_applier | aee85149-e379-11ea-8c01-0242c0a8bc34 | ms52 | 4000 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
2 rows in set (0.00 sec)

同样的,由于MySQL 5.7不支持参数直接持久化保存,需要手动将原slave1的相关参数补充到slave1实例的my.cnf文件中

binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name='a3e8c286-e375-11ea-868b-0242c0a8bc33'
loose-group_replication_local_address="192.168.188.52:13306"
loose-group_replication_group_seeds="192.168.188.51:13306,192.168.188.52:13306,192.168.188.53:13306"
loose-group_replication_bootstrap_group=off
loose-group_replication_start_on_boot=off

同理,将slave2转换为MGR成员,步骤略,记得保存参数到实例的my.cnf文件。

  • 最终转换完成后,三个节点都顺利ONLINE。
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | ab726fa8-e379-11ea-a4c2-0242c0a8bc33 | ms51 | 4000 | ONLINE |
| group_replication_applier | aee85149-e379-11ea-8c01-0242c0a8bc34 | ms52 | 4000 | ONLINE |
| group_replication_applier | b24d5bc3-e379-11ea-8eae-0242c0a8bc35 | ms53 | 4000 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)

MGR冷启动

  • 将三节点全部关掉
mysql > shutdown ;

  • 启动第一个节点(slave2)
[15:02:58] root@ms53:~ # mysqld --defaults-file=/data/mysql/mysql4000/my4000.cnf &
[1] 604
[15:04:51] root@ms53:~ # mysql -S /data/mysql/mysql4000/tmp/mysql.sock mysql> set global group_replication_bootstrap_group=ON;
Query OK, 0 rows affected (0.00 sec) mysql> start group_replication;
Query OK, 0 rows affected (2.53 sec) mysql> set global group_replication_bootstrap_group=OFF;
Query OK, 0 rows affected (0.00 sec) mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | b24d5bc3-e379-11ea-8eae-0242c0a8bc35 | ms53 | 4000 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
1 row in set (0.00 sec)
  • 启动第二个节点(slave1)
[15:03:20] root@ms52:~ # mysqld --defaults-file=/data/mysql/mysql4000/my4000.cnf &
[1] 593
[15:04:47] root@ms52:~ # mysql -S /data/mysql/mysql4000/tmp/mysql.sock mysql> start group_replication;
Query OK, 0 rows affected (6.37 sec) mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | aee85149-e379-11ea-8c01-0242c0a8bc34 | ms52 | 4000 | ONLINE |
| group_replication_applier | b24d5bc3-e379-11ea-8eae-0242c0a8bc35 | ms53 | 4000 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
2 rows in set (0.00 sec)
  • 启动第三个节点(master),踩了个坑
[15:04:33] root@ms51:~ # mysqld --defaults-file=/data/mysql/mysql4000/my4000.cnf &
[1] 7410
[15:04:43] root@ms51:~ # mysql -S /data/mysql/mysql4000/tmp/mysql.sock mysql> start group_replication;
Query OK, 0 rows affected (5.98 sec) mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | ab726fa8-e379-11ea-a4c2-0242c0a8bc33 | ms51 | 4000 | RECOVERING |
| group_replication_applier | aee85149-e379-11ea-8c01-0242c0a8bc34 | ms52 | 4000 | ONLINE |
| group_replication_applier | b24d5bc3-e379-11ea-8eae-0242c0a8bc35 | ms53 | 4000 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)

原master节点长时间处于recovering,查看status后猛然想起,先前转换MGR时,只对slave1、slave2做了change master for channel,把master给忘记了。

(该步骤已重新补充到master转换的操作步骤中。)

mysql> change master to master_user='rep',master_password='rep' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.05 sec) mysql> stop group_replication;
Query OK, 0 rows affected (10.65 sec) mysql> start group_replication;
Query OK, 0 rows affected (3.27 sec) mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | ab726fa8-e379-11ea-a4c2-0242c0a8bc33 | ms51 | 4000 | ONLINE |
| group_replication_applier | aee85149-e379-11ea-8c01-0242c0a8bc34 | ms52 | 4000 | ONLINE |
| group_replication_applier | b24d5bc3-e379-11ea-8eae-0242c0a8bc35 | ms53 | 4000 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec) 当前master
mysql> select * from performance_schema.global_status where variable_name='group_replication_primary_member';
+----------------------------------+--------------------------------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+----------------------------------+--------------------------------------+
| group_replication_primary_member | b24d5bc3-e379-11ea-8eae-0242c0a8bc35 |
+----------------------------------+--------------------------------------+
1 row in set (0.00 sec)

噢,忘了检查事务情况。 三节点结果一样,转换全面成功。

mysql> select count(*) from kk.k1;
+----------+
| count(*) |
+----------+
| 277 |
+----------+
1 row in set (0.02 sec) mysql> show master status;
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
| mysql-bin.000003 | 1686 | | | a3e8c286-e375-11ea-868b-0242c0a8bc33:1-240,
ab726fa8-e379-11ea-a4c2-0242c0a8bc33:1-46 |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

主从复制直接转换MGR_5.7验证试验的更多相关文章

  1. 主从复制架构直接转换MGR(manual)

    环境信息 IP port role info 192.168.188.81 3316 node1 master 192.168.188.82 3316 node2 slave1 192.168.188 ...

  2. Redis主从复制深入剖析

    Redis是一个开源的,遵守BSD许可协议的key/value缓存系统,并由其高效的响应速度以及丰富的数据结构而闻名.Redis在京东的使用也是非常普遍的,包括很多关键业务上的 使用,由于Redis官 ...

  3. MySQL 5.6 主从复制如何处理——触发器,函数,存储过程,调度事件

      截图来自MySQL5.6的pdf版文档. 说明: 1)基于语句的复制时,trigger会在slave上执行,所以slave上也需要有trigger的定义,不然会导致主从数据不一致的: 2)基于行的 ...

  4. redis+Keepalived实现Redis主从复制

    redis+Keepalived实现Redis主从复制: 环境:CentOs6.5Master: 10.10.10.203Slave:   10.10.10.204Virtural IP Addres ...

  5. mysql多实例(个人的情况,不是大众的)里面有配置好的脚本+主从复制

    [root@DB-S ~]# ll /usr/local/|grep mysql lrwxrwxrwx. 1 root root 21 Jun 14 01:52 mysql -> /alidat ...

  6. Redis 笔记与总结5 Redis 常用命令之 键值命令 和 服务器命令 && 高级应用之 安全性 和 主从复制

    Redis 提供了丰富的命令对数据库和各种数据库类型进行操作,这些命令可以在 Linux 终端使用. 1. 键值相关命令: 2. 服务器相关命令 键值相关命令 ① keys 命令 返回满足给定 pat ...

  7. 分布式数据存储 - MySQL主从复制高可用方案

    前面几篇文章说道MySQL数据库的高可用方案主从复制.主从复制的延迟产生原因.延迟检测及延迟解决方案(并未从根本上解决),这种主从复制方案保证数据的冗余的同时可以做读写分离来分担系统压力但是并非是高可 ...

  8. mysql5.5 对触发器,函数,存储引擎,事件进行主从复制情况.(转)

       mysql5.5 对触发器,函数,存储引擎,事件进行主从复制情况. 转(http://blog.csdn.net/m582445672/article/details/7670802) 一.My ...

  9. 关于mysql主从复制的概述与分类(转)

    一.概述: 按照MySQL的同步复制特点,大体上可以分为三种类别: 1.异步复制: 2.半同步复制: 3.完全同步的复制: -------------------------------------- ...

随机推荐

  1. 快速安装jumpserver开源堡垒机

    一 安装centos 7.X操作系统 二.选择极速安装(注意配置需要是4G2核) https://jumpserver.readthedocs.io/zh/master/install/setup_b ...

  2. 微信公众号获取openid(php实例)

    微信公众号获取openid 公众号获取openid的方法跟小程序获取openid其实是一样的,只是code获取的方式不一样 小程序获取code: 用户授权登录时调用wx.login即可获取到code ...

  3. C#实现SM2国密加密

    本文主要讲解"国密加密算法"SM系列的C#实现方法,不涉及具体的算法剖析,在网络上找到的java实现方法比较少,切在跨语言加密解密上会存在一些问题,所以整理此文志之.JAVA实现参 ...

  4. 面试官:小伙子,给我说一下spring框架吧

    1. spring是什么 轻量级开源框架 以 IoC(Inverse Of Control:反转控制)和 AOP(Aspect Oriented Programming:面向切面编程)为内核. 还能整 ...

  5. 正则表达式——maltrail工程项目中使用

    1. 正则表达所需语法 \ 正则表达式使用反斜杠字符 ('') 来表示特殊形式或是允许在使用特殊字符时不引发它们的特殊含义. 转义特殊字符(允许你匹配 '*', '?', 或者此类其他) \A 只匹配 ...

  6. 开源认证和访问控制的利器keycloak使用简介

    目录 简介 安装keycloak 创建admin用户 创建realm和普通用户 使用keycloak来保护你的应用程序 安装WildFly client adapter 注册WildFly应用程序 安 ...

  7. thinkPHP 无法加载控制器:Hello

    出现这种问题的情况下要看看: (1).控制器的名称是否写对,控制器的命名规范(别忘下class) 控制器的命名规则1.必须采用大驼峰的命名规则2.必须以Controller.class.php来结尾I ...

  8. 用FL Studio基础版制作一首完整的电音

    电音制作,自然少不了适合做电音的软件,市面上可以进行电音制作的软件不少,可是如果在这些软件中只能选择一款的话,想必多数人会把票投给FL Studio,毕竟高效率是永远不变的真理,今天就让我们来看看如何 ...

  9. 团队作业第三次 —— UML设计

    这个作业要求在哪里 https://edu.cnblogs.com/campus/fzzcxy/2018SE2/homework/11366 这个作业的目标 <团队一起设计UML图> 团队 ...

  10. shiro利用过期时间,解决用户冻结踢出问题

    背景 shiro中需要冻结某个用户,但是此时此刻这个用户在线,如果冻结只是改变状态的话,只会导致用户不满,所以要改变这个办法. 在查找过程中发现都是告诉shiro写自定义过滤器,那么我如果自定义过滤器 ...