1. MGR简介
1.1 MGR介绍
MGR全称MySQL Group Replication(mysql 组复制),是MySQL官方于2016年推出的一个全新的高可用扩展解决方案。是一种基于paxos协议的状态机复制,在MGR出现以前,都是以master-slave架构出现的,mysql5.7版本开始支持无损半同步复制(lossless semi-sync replication),从而进一步提升数据的强一致性。
MGR由若干个节点共同组成一个复制组,一个事务提交,必须经过组内大多数节点(N/2+1)决议并通过,才能提交。consensus层为一致性协议层,在事务提交过程中,发生级间通讯,由2个节点决议(cerity)通过这个事务,事务才能够得以提交并响应。
组复制是为了解决异步复制和半同步复制可能产生的数据不一致问题。
1.2 mysql的异步复制
主从同步过程中主服务器有一个工作线程I/O dump thread,从服务器有两个工作线程,io thread 和SQL thread。
主库把外界接收到的sql请求记录到自己的binlog日志中,从库的i/othread去请求主库的binlog日志,并将binlog日志写到中继日志中,然后从库重做中继日志的sql语句。
异步复制的弊端:
异步复制是mysql默认的复制方式,主库写入binlog即可成功后返回给客户端,不等待binlog日志传递的过程,如果主库宕机,就有可能会出现丢失数据的情况。
1.3 半同步复制
半同步复制原理:
半同步复制提升了主从之间数据的一致性,让复制更加安全可靠。基于传统异步存在的缺陷,mysql在5.5版本推出半同步复制,在master事务的commit之前,确保一个slave收到relay log并且响应master以后,才能进行事务的commit。但是slave对于relay log的应用仍然是异步进行的。
在mysql 5.7版本中又增加了rpl_semi_sync_master_wait_point参数,用来控制半同步模式下主库返回给session事务成功之前的事务提交方式。
该参数有两个值:
(1) after_commit:5.6版本的默认值,主库将每个事务写入到binlog,并同时传送给从库,刷新到中继日志中,同时主库提交事务。之后主库开始等待从库的反馈,只有收到从库的回复后master才将commit ok返回给客户端。
(2)after_sync: 5.7版本新增,也是默认值。主库将每个事务写入到binlog并传递给从库,刷新到中继日志,等从库反馈,从库有回复后,主库再提交事务,并返回commit ok给客户端。
注意:可以通过rpl_semi_sync_master_wait_for_slave_count参数来控制主库接收到多少个从库写事务成功反馈,才返回给客户端生产环境中使用半同步复制方式,当从库出现故障,等待超时的时间又很长,导致主库无法接收从库信息而无法正常写入时,可通过该参数剔除故障从库。另外rpl_semi_sync_master_timeout单位是毫秒,它表示如果主库等待从库回复消息的时间超过该值,就自动切换为异步复制模式,建议调整为很大,禁止向异步复制切换来保证数据复制的安全性。MySQL 5.7默认的半同步复制方式是after_sync模式。
在after_sync模式下,即使主库宕机,所有在主库上已经提交的事务都能保证已经同步到从库的中继日志中,不会丢失数据。
1.4 组复制的特性及原理
MGR特性:
a. 高一致性,基于原生复制及paxos协议的组复制技术,并以插件的方式提供,提供一致数据安全保证;
b. 高容错性,只要不是大多数节点宕机就可以工作,有自动检测机制,当不同节点产生资源争用冲突时,不会出现错误,按照先到者优先原则进行处理,内置了自动化脑裂防护机制。
c. 高扩展性,节点的新增和移除都是自动的,新节点加入后,会自动同步其他节点的状态,直到保持一致,如果某节点被移除,其他节点 自动更新组信息,自动维护新的组信息。
d. 高灵活性,有单主和多主,在单主模式下,会自动选主,从不能写入,在多主模式下,所有server都 可以写。
组复制原理:
状态机复制:
MGR本质上一个状态机复制的集群。在状态机复制的架构中,数据库被当做一个状态机。每一次写操作都会导致数据库的状态变化。为了创建一个高可用的数据库集群,有一个组件,即事务分发器,将这些操作按照同样的顺序发送到多个初始状态一致的数据库上,让这些数据库执行同样的操作。因为初始状态相同,每次执行的操作也相同,所以每次状态变化后各个数据库上的数据保持一致。
分布式状态机复制:
事务分发器是一个单点,为了避免单点故障,可以采用分布式的状态机复制。在分布式的状态机复制中,有多个事务分发器,它们彼此互相通信。事务分发器可以同时接收事务请求,就像单个事务分发器同时接收事务请求一样。从应用层来说,并发的事务发到同一个事务分发器和发到不同的事务分发器上效果是一样的。事务分发器之间会互相通信,把所有的事务汇总、排序。最终,每个事务分发器上都有一份完整的排好序的事务请求。每个事务分发器只连接到一个数据库上,并负责把事务请求依次发送到相连的数据库上去执行,其就是一个分布式状态机复制的模型了。
1.5 搭建MGR的基础结构需求和使用限制
1.5.1 基础结构需求
- 存储引擎必须为innodb,因为需要事务支持在commit时对各节点进行冲突检查;
- 每个表必须有主键;
- 开启binlog的row模式;
- 开启GTID,且主从状态信息存储在表中(–master-info-repository=TABLE,–relay-log-info-repositroy=TABLE,–log-slave-updates打开);
- 一致性检测设置(–transaction-write-set-extractinotallow=XXHASH64);
1.5.2 使用限制
- RP和普通复制binlog检验不能共存,需要设置–binlog-checksum=none;
- 不支持gap lock,隔离级别为RC;
- 不支持对表进行锁操作(lock/unlock table),不会发送到其他节点执行 ,影响需要对表进行加锁操作的情况,列入mysqldump全表备份恢复操作;
- 不支持serializable(序列化)隔离级别;
- DDL语句不支持原子性,不能检测冲突,执行后需要自行校验是否唯一;
- 多主模式不支持外键,单主 模式下支持,最多有9个节点,超过则无法以加入集群
1.6 paxos原理
1.6.1 三种特性说明
基于CAP theorm理论,引出的三个特性:
(1). 一致性(consistency): 分布式系统中会有多个节点,且内容不能矛盾; 读操作总是能读取到”之前“(之前的意思是针对于同一个客户端而言)完成的写操作结果,满足这一条件的系统称为强一致系统。
(2). 可用性(availability):服务不是经常可以访问到的; 读写操作在单台机器发生故障的情况下仍然可以运行,且不需要等待发生故障重启或者迁移到其他机器。
(3). 分区容错性(Partition tolerance):机器故障,网络故障或机房停电情况仍然可以满足一致性和可用性。
总的来说,CAP理论告诉我们,一个分布式系统不可能同时满足一致性,可用性,和分区容错性,最多可以满足两种。
一致性
如图所示,为了保证SERVER A SERVER B数据一致,用户A向server A,server B同时发送数据,当发生网络中断时,如果让clientA 写入server A 数据成功,那么client B ,clientc 读到的数据将不一致,如果写入失败,则读到的数据一致
可用性
如果让client c同时访问server 1 和server 2 的内容,根据数据的最新版本来推算,如果两条连路同时中断,数据是一致的,但是分区容错性不能达到了。
1.6.2 一致性模型
(1). 弱一致性(最终一致性)
DNS, gossip
最终一致性:最后一定会访问到。
(2). 强一致性
- 同步
- paxos
- raft (multi-paxos)
- ZAB
首先应该明确问题:
a. 数据不能放在单点;
b. 分布式系统对fault-tolerant的一般解决方案是state machine replication 状态机复制。
状态机复制:客户端向服务端发送一条sql请求,在执行sql之前,记录一个初始状态,记录的格式为log,在执行完sql之后又会记录一个状态,写入log。
paxos是一个共识算法,系统利用最终一致性,达成共识之后取决于client行为。
1.6.3 强一致性
(1) 同步
主从复制
a. 第一步master写请求,同步给slave
b. slave接收请求复制,给master回复;
c. master等待所有的slave 回复之后进行返回给客户端;
(2). 多数派
多数派:在每次写请求时,保证写入的大于集群的(n/2); 在每次读请求时,保证读的大于集群的(n/2);
问题:多数派跟并发场景有很大关系,执行顺序的不同,造成数据结果不一致(案例)
(3). paxos算法
1.6.4 paxos算法
- paxos 版本
basic paxos;
multi paxos;
fast paxos;
- paxos算法产生背景
paxos 算法是基于消息传递且具有高度容错特性的一致性算法,解决在分布式系统中 如何就某个值(决议)达成一致。
典型场景:
在一个分布式数据库 系统中,如果各节点的初始状态是一致的,每个节点都执行相同的操作序列,最后达到一致的状态,为保证每个节点执行的相同的命令,需要在每个指令上执行一个”一 致性算法”来保证每个节点看到的指令一致。
两种通讯模型:共享内存,消息传递(paxos)
拜占庭问题
拜占庭将军问题:是指拜占庭帝国军队的将军们必须全体一致的决定是否攻击某一支敌军。问题是这些将军在地理上是分隔开来的,只能依靠通讯员进行传递命令,但是通讯员中存在叛徒,它们可以篡改消息,叛徒可以欺骗某些将军采取进攻行动;促成一个不是所有将军都同意的决定,如当将军们不希望进攻时促成进攻行动;或者迷惑某些将军,使他们无法做出决定。
Paxos算法的前提假设是不存在拜占庭将军问题,即:信道是安全的(信道可靠),发出的信号不会被篡改,因为Paxos算法是基于消息传递的。此问题由Lamport提出,它也是 Paxos算法的提出者。
从理论上来说,在分布式计算领域,试图在异步系统和不可靠信道上来达到一致性状态是不可能的。因此在对一致性的研究过程中,都往往假设信道是可靠的,而事实上,大多数系统都是部署在一个局域网中,因此消息被篡改的情况很罕见;另一方面,由于硬件和网络原因而造成的消息不完整问题,只需要一套简单的校验算法即可。因此,在实际工程中,可以假设所有的消息都是完整的,也就是没有被篡改。
- 相关概念
client: 系统外部角色,相当于法庭的民众,不起决定性作用,通常有多个;
proposer: 接收client请求,向集群提出提议,并在冲突时,起到调节作用,有多个;
acceptor: 提议投票接收者,在形成法定人数(quorum major) 多数派提议才会被接受,有多个;
learners: 提议的接收者,相当于记录员,有多个
- paxos算法过程
basic paxos
基础流程:
a. proposer阶段:当client发出请求到proposer,proposer接收请求选择一个提案编号1,并发送给acceptor,acceptor接收到之后给proposer回应,通过proposer的计数来定义多数派;
b. 如果一个proposer收到半数以上的acceptor,那么就发送半数以上的编号为N的请求
部分节点失败:
blob:null/fac5b8a3-79dc-4840-8566-fb6e12a646ac
proposer失败:
会造成活锁等问题
活锁指的是任务或者执行者没有被阻塞,由于某些条件没有满足,导致一直重复尝试,失败,尝试,失败。
multi paxos: 引入了新概念leader,唯一的proposer
2. MGR集群搭建
2.1 搭建单主MGR集群
选主算法:
a. 考虑的第一个因素是哪个或哪些成员运行最低的MySQL Server版本。如果所有组成员都运行MySQL 8.0.17或更高版本,则首先按其发行版的补丁程序对成员进行排序。如果任何成员运行的是MySQL Server 5.7或MySQL 8.0.16或更低版本,则首先按其发行版的主版本对成员进行排序,并且忽略补丁程序版本。
b. 如果有多个成员正在运行最低版本的MySQL Server,则考虑权重,根据成员上的系统变量决定group_replication_member_weight
,如果组内成员都是5.7版本则不可用;
c. 如果有多个成员运行的是最低版本的MySQL Server,并且这些成员中有多个具有最高的成员权重(或者忽略了成员权重),则考虑的第三个因素是由Server_uuid系统变量指定的每个成员生成的服务器uuid的字典顺序。将选择服务器UUID最低的成员作为主要成员。这一因素起到了一个有保证和可预测的平局决胜局的作用,因此,如果无法由任何重要因素决定,所有小组成员都可以做出相同的决定。
查看组内成员情况:
mysql > select group_replication_set_as_primary();
更改组内成员: set group_replication_set_as_primary(member_uuid);
如果运行的是mysql 8.0.17或更高版本,且运行的成员都是mysql 8.0.17的,则只能指定一个成员,运行版本最低的为主服务器;
如果在mysql8.0.13和8.0.16之间,可以随意指定主服务器。
更改为单主模式:
mysql> select group_replication_switch_to_single_primary_mode();
mysql> set group_replication_switch_to_single_primary_mode(member_uuid);
更改为多主模式:
mysql >select group_replication_switch_to_multi_primary_mode();
mysql>set group_replication_switch_to_single_primary_mode(member_uuid);
如果更改为多主,运行的mysql 高于最低版本的成员,则运行8.0.17或更高自动配置于只读模式;
在组内运行mysql8.0.16的不执行检查,并始终处理读写。
实验环境:
主机名 | IP地址 | mysql版本 | 端口号 | server id |
db01 | 192.168.214.1 | mysql 5.7.20 | 3306 | 5160 |
db02 | 192.168.214.129 | mysql 5.7.20 | 3306 | 5160 |
db03 | 192.168.214.130 | mysql 5.7.20 | 3306 | 5160 |
在配置单主模式时,是在空的数据库下,如果主数据库中已经存在数据,需要将主数据库导出再导入从数据库中。另外还需要保证引擎为innodb,每个表必须存在主键。
- (1) 以db01作为主服务器,在db01上进行配置(1) 以db01作为主服务器,在db01上进行配置
a.配置ip地址映射(需要三台服务器同时设置):
[root@db01 opt]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.214.1 db01
192.168.214.129 db02
192.168.214.130 db03
# scp -rp /etc/hosts 192.168.214.129:/etc/
# scp -rp /etc/hosts 192.168.214.130:/etc/
b. 在主服务器上创建复制用户:
mysql> grant replication slave on *.* to 'repl'@'192.168.214.%' identified by 'repl';
Query OK, 0 rows affected, 1 warning (0.02 sec)
// 并刷新授权表
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
c. 修改主库的配置文件信息
[root@db01 ~]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql # 文件目录
datadir=/data/3306/data # 数据目录
user=mysql # 用户信息
server_id=5106 # server_id
log-error=/data/3306/error.log # 错误日志存储信息
log_bin=/data/3306/binlog/mysql-bin # 二进制日志存储文件
port=3306 # 端口
gtid-mode=on # 开启gtid模式,全局事务
enforce-gtid-consistency=on # 强制GTID的一致性
master-info-repository=TABLE # 将master.info元数据保存在系统表中
relay-log-info-repository=TABLE # 将relay.info元数据保存中系统表中
binlog-checksum=none # 禁用二进制日志事件校验
log-slave-updates=on # 级联复制
log-bin=binlog # 开启二进制日志记录
binlog-format=ROW # 二进制日志的行模式
transaction-write-set-extraction=XXHASH64 # 使用哈希算法将其编码为散列
loose-group_replication_group_name='ce9be252-2b71-11e6-b8f4-00212844f856' # 加入的组名,可以修改
loose-group_replication_start_on_boot=off # 不启用组复制集群
loose-group_replication_local_address='db01:33061' # 以本机端口33061接受来自组中成员的传入连接
loose-group_replication_group_seeds='db01:33061,db02:33062,db03:33063' # 组中成员的访问列表
loose-group_replication_bootstrap_group=off # 不启用引导组
[mysql]
socket=/tmp/mysql.sock
d. 如果防火墙是打开的,需要添加端口号,重启mysql
[root@db01 ~]# firewall-cmd --permanent --zone=public --add-port={3306,33061}/tcp
success
[root@db01 ~]# firewall-cmd --reload
success
[root@db01 ~]# firewall-cmd --permanent --zone=public --list-ports
3306/tcp 33061/tcp
# systemctl restart mysqld
e. 构建组复制集群(group_replication)信息,并安装插件
mysql> change master to master_user='repl',master_password='repl' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.05 sec)
mysql> install PLUGIN group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.02 sec)
mysql> show plugins;
+----------------------------+----------+--------------------+----------------------+---------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+----------------------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| PERFORMANCE_SCHEMA | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL |
| INNODB_TRX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCKS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCK_WAITS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_PER_INDEX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_PER_INDEX_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_PAGE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_PAGE_LRU | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_POOL_STATS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_TEMP_TABLE_INFO | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_METRICS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_DEFAULT_STOPWORD | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_DELETED | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_BEING_DELETED | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_CONFIG | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_INDEX_CACHE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_INDEX_TABLE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLESTATS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_INDEXES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_COLUMNS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FIELDS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FOREIGN | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_FOREIGN_COLS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_TABLESPACES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_DATAFILES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SYS_VIRTUAL | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ARCHIVE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
| BLACKHOLE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL |
| ngram | ACTIVE | FTPARSER | NULL | GPL |
| group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL |
+----------------------------+----------+--------------------+----------------------+---------+
45 rows in set (0.00 sec)
f. 作为主服务器开启引导,开启组复制集群
mysql> set global group_replication_bootstrap_group=on; // 开启复制引导
Query OK, 0 rows affected (0.02 sec)
mysql> start group_replication; // 开启组复制
Query OK, 0 rows affected (2.06 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 | 8d5455ff-a3fb-11ea-aabe-e454e8ce0527 | db01 | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
1 row in set (0.00 sec)
- (2) 在从库服务器db02上配置
a. 创建一个复制的用户
mysql> grant replication slave on *.* to 'repl'@'192.168.214.%' identified by 'repl';
Query OK, 0 rows affected, 1 warning (0.01 sec)
// 并刷新授权表
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
b. 修改配置文件并重启数据库
[root@db02 3306]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3306/data
user=mysql
server_id=5106
log-error=/data/3306/error.log
log_bin=/data/3306/binlog/mysql-bin
port=3306
gtid-mode=on
enforce-gtid-consistency=on
master-info-repository=TABLE
relay-log-info-repository=TABLE
binlog-checksum=none
log-slave-updates=on
log-bin=binlog
binlog-format=ROW
transaction-write-set-extraction=XXHASH64
loose-group_replication_group_name='ce9be252-2b71-11e6-b8f4-00212844f856'
loose-group_replication_start_on_boot=off
loose-group_replication_local_address='db02:33062' // 修改
loose-group_replication_group_seeds='db01:33061,db02:33062,db03:33063'
loose-group_replication_bootstrap_group=off
[mysql]
socket=/tmp/mysql.sock
# systemctl restart mysqld
c. 如果开启防火墙,添加放行端口
[root@db02 3306]# firewall-cmd --permanent --zone=public --add-port={3306,33062}/tcp
success
[root@db02 3306]# firewall-cmd --reload
success
[root@db02 3306]# firewall-cmd --zone=public --list-ports
3306/tcp 33062/tcp
d.修改 master信息,构建组复制集群,并安装插件
mysql> change master to master_user='repl',master_password='repl' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.03 sec)
mysql> install PLUGIN group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.02 sec)
e. 将db02加到集群中去,并查看复制集群的服务器信息
mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;
Query OK, 0 rows affected (0.00 sec)
mysql> start group_replication;
Query OK, 0 rows affected (6.56 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 8d5455ff-a3fb-11ea-aabe-e454e8ce0527 | db01 | 3306 | ONLINE |
| group_replication_applier | c64f22dd-a539-11ea-ad67-000c294780e2 | db02 | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
2 rows in set (0.01 sec)
(3) 配置db03,和配置db02的过程相同
a. 创建一个复制的用户
mysql> grant replication slave on *.* to 'repl'@'192.168.214.%' identified by 'repl';
Query OK, 0 rows affected, 1 warning (0.01 sec)
// 并刷新授权表
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
b. 修改配置文件,重启mysql
[root@db03 mysql]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3306/data
user=mysql
server_id=5106
log-error=/data/3306/error.log
log_bin=/data/3306/binlog/mysql-bin
port=3306
gtid-mode=on
enforce-gtid-consistency=on
master-info-repository=TABLE
relay-log-info-repository=TABLE
binlog-checksum=none
log-slave-updates=on
log-bin=binlog
binlog-format=ROW
transaction-write-set-extraction=XXHASH64
loose-group_replication_group_name='ce9be252-2b71-11e6-b8f4-00212844f856'
loose-group_replication_start_on_boot=off
loose-group_replication_local_address='db03:33063' # 修改
loose-group_replication_group_seeds='db01:33061,db02:33062,db03:33063'
loose-group_replication_bootstrap_group=off
[mysql]
socket=/tmp/mysql.sock
# systemctl restart mysqld
c. 修改防火墙信息
[root@db03 mysql]# firewall-cmd --permanent --zone=public --add-port={3306,33063}/tcp
success
[root@db03 mysql]# firewall-cmd --reload
success
[root@db03 mysql]# firewall-cmd --zone=public --list-ports
3306/tcp 33063/tcp
d. 将db03加入到集群中,并开启组复制,查看组复制集群
mysql> change master to master_user='repl',master_password='repl' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> install PLUGIN group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.01 sec)
mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;
Query OK, 0 rows affected (0.00 sec)
mysql> start group_replication;
Query OK, 0 rows affected (3.21 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 25f9dd2b-a53b-11ea-a857-000c29225984 | db03 | 3306 | ONLINE |
| group_replication_applier | 8d5455ff-a3fb-11ea-aabe-e454e8ce0527 | db01 | 3306 | ONLINE |
| group_replication_applier | c64f22dd-a539-11ea-ad67-000c294780e2 | db02 | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)
(4) 测试
在db01上创建数据:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test_db |
+--------------------+
5 rows in set (0.00 sec)
mysql> create database db;
Query OK, 1 row affected (0.02 sec)
mysql> use db;
Database changed
mysql> create table test(id int primary key,name varchar(30));
Query OK, 0 rows affected (0.03 sec)
mysql> insert into test values(1,'zhangsan');
Query OK, 1 row affected (0.03 sec)
mysql> select * from test;
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
+----+----------+
1 row in set (0.00 sec)
在db02上查看:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db |
| mysql |
| performance_schema |
| sys |
| test_db |
+--------------------+
6 rows in set (0.01 sec)
mysql> use db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from test;
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
+----+----------+
1 row in set (0.00 sec)
在db03上查看:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db |
| mysql |
| performance_schema |
| sys |
| test_db |
+--------------------+
6 rows in set (0.00 sec)
mysql> use db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from db;
ERROR 1146 (42S02): Table 'db.db' doesn't exist
mysql> select * from test;
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
+----+----------+
1 row in set (0.00 sec)
查看哪台服务器是主库的方法:
# 在db01上查看:
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | OFF |
| super_read_only | OFF |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.01 sec)
# 全为off,说明是主库
# 在db02上查看:
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | ON |
| super_read_only | ON |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.00 sec)
# 在db03上查看:
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | ON |
| super_read_only | ON |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.01 sec)
查看MGR的参数:
mysql> show variables like 'group_replication%';
+----------------------------------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------------------------------+--------------------------------------+
| group_replication_allow_local_disjoint_gtids_join | OFF |
| group_replication_allow_local_lower_version_join | OFF |
| group_replication_auto_increment_increment | 7 |
| group_replication_bootstrap_group | OFF |
| group_replication_components_stop_timeout | 31536000 |
| group_replication_compression_threshold | 1000000 |
| group_replication_enforce_update_everywhere_checks | OFF |
| group_replication_flow_control_applier_threshold | 25000 |
| group_replication_flow_control_certifier_threshold | 25000 |
| group_replication_flow_control_mode | QUOTA |
| group_replication_force_members | |
| group_replication_group_name | ce9be252-2b71-11e6-b8f4-00212844f856 |
| group_replication_group_seeds | db01:33061,db02:33062,db03:33063 |
| group_replication_gtid_assignment_block_size | 1000000 |
| group_replication_ip_whitelist | AUTOMATIC |
| group_replication_local_address | db01:33061 |
| group_replication_member_weight | 50 |
| group_replication_poll_spin_loops | 0 |
| group_replication_recovery_complete_at | TRANSACTIONS_APPLIED |
| group_replication_recovery_reconnect_interval | 60 |
| group_replication_recovery_retry_count | 10 |
| group_replication_recovery_ssl_ca | |
| group_replication_recovery_ssl_capath | |
| group_replication_recovery_ssl_cert | |
| group_replication_recovery_ssl_cipher | |
| group_replication_recovery_ssl_crl | |
| group_replication_recovery_ssl_crlpath | |
| group_replication_recovery_ssl_key | |
| group_replication_recovery_ssl_verify_server_cert | OFF |
| group_replication_recovery_use_ssl | OFF |
| group_replication_single_primary_mode | ON |
| group_replication_ssl_mode | DISABLED |
| group_replication_start_on_boot | OFF |
| group_replication_transaction_size_limit | 0 |
| group_replication_unreachable_majority_timeout | 0 |
+----------------------------------------------------+--------------------------------------+
35 rows in set (0.01 sec)
故障切换:
将db01数据库关闭:
[root@db01 ~]# systemctl stop mysqld
查看db02的状态:
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 25f9dd2b-a53b-11ea-a857-000c29225984 | db03 | 3306 | ONLINE |
| group_replication_applier | c64f22dd-a539-11ea-ad67-000c294780e2 | db02 | 3306 | RECOVERING |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
2 rows in set (0.00 sec)
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | ON |
| super_read_only | ON |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.00 sec)
查看db03的状态:
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | OFF |
| super_read_only | OFF |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.01 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 25f9dd2b-a53b-11ea-a857-000c29225984 | db03 | 3306 | ONLINE |
| group_replication_applier | c64f22dd-a539-11ea-ad67-000c294780e2 | db02 | 3306 | RECOVERING |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
2 rows in set (0.00 sec)
将db01数据库恢复:
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | OFF |
| super_read_only | OFF |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.01 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+-----------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+-----------+-------------+-------------+--------------+
| group_replication_applier | | | NULL | OFFLINE |
+---------------------------+-----------+-------------+-------------+--------------+
1 row in set (0.00 sec)
// 发现已经不在集群,数据不能及时恢复
2.2 搭建多主MGR集群
a. 在创建时启用多主模式
在配置文件中加入两行内容:
[root@db01 ~]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3306/data
user=mysql
server_id=5106
log-error=/data/3306/error.log
log_bin=/data/3306/binlog/mysql-bin
port=3306
gtid-mode=on
enforce-gtid-consistency=on
master-info-repository=TABLE
relay-log-info-repository=TABLE
binlog-checksum=none
log-slave-updates=on
log-bin=binlog
binlog-format=ROW
transaction-write-set-extraction=XXHASH64
loose-group_replication_group_name='ce9be252-2b71-11e6-b8f4-00212844f856'
loose-group_replication_start_on_boot=off
loose-group_replication_local_address='db01:33061'
loose-group_replication_group_seeds='db01:33061,db02:33062,db03:33063'
loose-group_replication_bootstrap_group=off
loose-group_replication_single_primary_mode=off //关闭单master模式
loose-group_replication_enforce_update_everywhere_checks=ON // 开
[mysql]
socket=/tmp/mysql.sock
b. 全部服务器停止组复制,并设置参数
mysql> stop group_replication;
Query OK, 0 rows affected (1.03 sec)
mysql> set global group_replication_single_primary_mode=off;
Query OK, 0 rows affected (0.00 sec)
mysql> set global group_replication_enforce_update_everywhere_checks=ON;
Query OK, 0 rows affected (0.00 sec)
c. 选择其中一台引导组复制,使用db01作为主
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.06 sec)
mysql> set global group_replication_bootstrap_group=OFF;
Query OK, 0 rows affected (0.00 sec)
d. 剩下的开启组复制即可
mysql> start group_replication;
Query OK, 0 rows affected (6.51 sec)
e. 查看非引导组复制服务器的状态
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 25f9dd2b-a53b-11ea-a857-000c29225984 | db03 | 3306 | ONLINE |
| group_replication_applier | 8d5455ff-a3fb-11ea-aabe-e454e8ce0527 | db01 | 3306 | ONLINE |
| group_replication_applier | c64f22dd-a539-11ea-ad67-000c294780e2 | db02 | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | ON |
| super_read_only | ON |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.01 sec)
f. 查看引导的服务器db01:
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | OFF |
| super_read_only | OFF |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.01 sec)
g. 如果db01宕机了,查看db02和db03的状态
//每台服务器上都是主库
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | OFF |
| super_read_only | OFF |
| transaction_read_only | OFF |
| tx_read_only | OFF |
+-----------------------+-------+
5 rows in set (0.00 sec)
h. 将db01修复,添加到复制组
# systemctl start mysqld
mysql> select * from performance_schema.replication_group_members; //查看组内成员
+---------------------------+-----------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+-----------+-------------+-------------+--------------+
| group_replication_applier | | | NULL | OFFLINE |
+---------------------------+-----------+-------------+-------------+--------------+
1 row in set (0.00 sec)
mysql> change master to master_user='repl',master_password='repl' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.04 sec)
mysql> set global group_replication_allow_local_disjoint_gtids_join=ON; // 将这台服务器重新添加到组复制中去
Query OK, 0 rows affected (0.00 sec)
mysql> start group_replication;
Query OK, 0 rows affected (2.75 sec)
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 25f9dd2b-a53b-11ea-a857-000c29225984 | db03 | 3306 | ONLINE |
| group_replication_applier | 8d5455ff-a3fb-11ea-aabe-e454e8ce0527 | db01 | 3306 | ONLINE |
| group_replication_applier | c64f22dd-a539-11ea-ad67-000c294780e2 | db02 | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)
mysql> select * from db.test; // 查看是否同步数据
+----+----------+
| id | name |
+----+----------+
| 1 | zhangsan |
| 2 | lisi |
+----+----------+
2 rows in set (0.00 sec)
3. MGR集群搭建mysql8.0版本
3.1 搭建单主MGR集群
环境准备:
主机名 | IP地址 | 数据库版本 | 端口号 | server_id | 对外访问端口 |
db01 | 192.168.214.1 | mysql 8.0.19 | 3380 | 3381 | 33081 |
db02 | 192.168.214.129 | mysql 8.0.19 | 3380 | 3381 | 33082 |
db03 | 192.168.214.133 | mysql 8.0.19 | 3380 | 3381 | 33084 |
a. 修改db01配置文件mysql80.cnf文件:
[root@db01 ~]# cat /data/mysql80/mysql80.cnf
[mysqld]
basedir=/usr/local/mysql80
datadir=/data/mysql80/data
user=mysql
server_id=3381
log-error=/data/mysql80/error.log
log_bin=/data/mysql80/binlog/mysql-bin
port=3380
gtid-mode=on
enforce-gtid-consistency=on
master-info-repository=TABLE
relay-log-info-repository=TABLE
binlog-checksum=none
log-slave-updates=on
log-bin=binlog
binlog-format=ROW
transaction-write-set-extraction=XXHASH64
loose-group_replication_group_name='ce9ee2e2-2b71-11e6-b8f4-0021284efe5e'
loose-group_replication_start_on_boot=off
loose-group_replication_local_address='db01:33081' ## 修改
loose-group_replication_group_seeds='db01:33081,db02:33082,db04:33084' # 修改
loose-group_replication_bootstrap_group=off
loose-group_replication_single_primary_mode=off
loose-group_replication_enforce_update_everywhere_checks=ON
loose-group_replication_member_weight = 50 #权重选择
[mysql]
socket=/tmp/mysql80.sock
# systemctl restart mysqld
b. 配置hosts解析(三台都配置):
[root@db01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.214.1 db01
192.168.214.129 db02
192.168.214.133 db03
[root@db01 ~]#
c. 配置主节点,创建复制用户
mysql> create user 'repl'@'192.168.214.%' identified by 'repl';
Query OK, 0 rows affected (0.01 sec)
mysql> grant replication slave on *.* to repl@'192.168.214.%';
Query OK, 0 rows affected (0.03 sec)
d. 复制所使用的用户,并安装插件,查看
mysql> change master to master_user='repl',master_password='repl' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.06 sec)
mysql> install plugin group_replication soname 'group_replication.so';
Query OK, 0 rows affected (0.02 sec)
mysql> show plugins;
+---------------------------------+----------+--------------------+----------------------+---------+
| Name | Status | Type | Library | License |
+---------------------------------+----------+--------------------+----------------------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| caching_sha2_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha2_cache_cleaner | ACTIVE | AUDIT | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL |
| INNODB_TRX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_PER_INDEX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_PER_INDEX_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_PAGE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_PAGE_LRU | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_BUFFER_POOL_STATS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_TEMP_TABLE_INFO | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_METRICS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_DEFAULT_STOPWORD | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_DELETED | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_BEING_DELETED | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_CONFIG | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_INDEX_CACHE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_FT_INDEX_TABLE | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_TABLES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_TABLESTATS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_INDEXES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_TABLESPACES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_COLUMNS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_VIRTUAL | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CACHED_INDEXES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_SESSION_TEMP_TABLESPACES | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| PERFORMANCE_SCHEMA | ACTIVE | STORAGE ENGINE | NULL | GPL |
| TempTable | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ARCHIVE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| BLACKHOLE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL |
| ngram | ACTIVE | FTPARSER | NULL | GPL |
| mysqlx | ACTIVE | DAEMON | NULL | GPL |
| mysqlx_cache_cleaner | ACTIVE | AUDIT | NULL | GPL |
| group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL |
+---------------------------------+----------+--------------------+----------------------+---------+
45 rows in set (0.00 sec)
e. 建立组复制,并查看组内成员:
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 (8.29 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 | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 917d940f-a60b-11ea-8671-e454e8ce0527 | db01 | 3380 | ONLINE | PRIMARY | 8.0.19 |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
1 row in set (0.01 sec)
f. 配置从节点,创建用户和复制用户:
mysql> change master to master_user='repl',master_password='repl' for channel 'group_replication_recovery';
g. 安装插件和查看:
mysql> install plugin group_replication soname 'group_replication.so';
Query OK, 0 rows affected (0.02 sec)
mysql> show plugins;
h. 在其他节点上加入复制组:
start group_replication;
select * from performance_schema.replication_group_members;