MGR群集搭建
环境
IP地址 | 主机名 | 数据库 | 端口号 | Server_ID | 操作系统 |
---|---|---|---|---|---|
192.168.144.10 | apenglinux-001.cn | MySQL5.7.26 | 3306 | 100 | CentOS7.5 |
192.168.144.20 | apenglinux-002.cn | MySQL5.7.26 | 3306 | 101 | CentOS7.5 |
192.168.144.30 | apenglinux-003.cn | MySQL5.7.26 | 3306 | 102 | CentOS7.5 |
single master 模式
- 三台机作ip与主机名的映射关系
vim /etc/hosts -- 加入以下内容
192.168.144.10 apenglinux-001.cn
192.168.144.20 apenglinux-002.cn
192.168.144.30 apenglinux-003.cn
- 单主master主机为apenglinux-001.cn
vim /etc/my.cnf -- 加入以下内容 server_id=100 gtid_mode=on enforce_gtid_consistency=on transaction_write_set_extraction=XXHASH64 log_bin=apenglinux binlog_checksum=none binlog_format=row log_slave_updates=on master_info_repository=table relay_log_info_repository=table loose_group_replication_group_name=‘70546c9a-5a52-46a4-84ee-141ca4359966‘ loose_group_replication_local_address=‘apenglinux-001.cn:10001‘ loose_group_replication_start_on_boot=off loose_group_replication_group_seeds=‘apenglinux-001.cn:10001,apenglinux-002.cn:10002,apenglinux-003.cn:10003‘ loose_group_replication_group_bootstrap_group=off
- 重启mysqld
- 连接mysql,到(apenglinux-001.cn)mysql里的操作如下
mysql> set sql_log_bin=off;
mysql> grant replication slave on *.* to [email protected]‘192.168.144.%‘ identified by ‘123456‘;
mysql> flush privileges;
mysql> set sql_log_bin=on;
mysql> change master to master_user=‘repl‘,master_password=‘123456‘ for channel ‘group_replication_recovery‘;
mysql> install plugin group_replication soname ‘group_replication.so‘;
mysql> set global group_replication_bootstrap_group=on;
mysql> start group_replication;
mysql> set global group_replication_bootstrap_group=off;
mysql> select * from performance_schema.replication_group_members; -- 以下是查询到的内容
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
| group_replication_applier | 8ea873c2-8f71-11e9-bbb4-000c298347f1 | apenglinux-001.cn | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
- 从服务器(apenglinux-002.cn)的配置
vim /etc/my.cnf -- 跟 apenglinux-001.cn一样的配置,只需要修改以下两行 server_id=101 loose_group_replication_local_address=‘apenglinux-002.cn:10002‘ 重启mysqld 连接msyql,到mysql里的操作如下 mysql> set sql_log_bin=off; mysql> grant replication slave on *.* to [email protected]‘192.168.144.%‘ identified by ‘123456‘; mysql> flush privileges; mysql> set sql_log_bin=on; mysql> change master to master_user=‘repl‘,master_password=‘123456‘ for channel ‘group_replication_recovery‘; mysql> install plugin group_replication soname ‘group_replication.so‘; mysql> set global group_replication_allow_local_disjoint_gtids_join=on; mysql> start group_replication; mysql> select * from performance_schema.replication_group_members; +---------------------------+--------------------------------------+-------------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-------------------+-------------+--------------+ | group_replication_applier | 8ea873c2-8f71-11e9-bbb4-000c298347f1 | apenglinux-001.cn | 3306 | ONLINE | | group_replication_applier | a049b503-8f72-11e9-ba4b-000c2906c8f7 | apenglinux-002.cn | 3306 | ONLINE | +---------------------------+--------------------------------------+-------------------+-------------+--------------+
- 从服务器apenglinux-003.cn的配置(与apenglinux-002.cn一样的配置),下面是要修改的
vim /etc/my.cnf
server_id=102
loose_group_replication_local_address=‘apenglinux-003.cn:10003‘
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
| group_replication_applier | 8ea873c2-8f71-11e9-bbb4-000c298347f1 | apenglinux-001.cn | 3306 | ONLINE |
| group_replication_applier | a049b503-8f72-11e9-ba4b-000c2906c8f7 | apenglinux-002.cn | 3306 | ONLINE |
| group_replication_applier | d9fd5ea2-8f73-11e9-8f3b-000c29096feb | apenglinux-003.cn | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
- 查看单主模式的主节点(所有的节点都可以查看)
mysql> show global status like ‘%primary%‘; +----------------------------------+--------------------------------------+ | Variable_name | Value | +----------------------------------+--------------------------------------+ | group_replication_primary_member | 8ea873c2-8f71-11e9-bbb4-000c298347f1 | +----------------------------------+--------------------------------------+
MGR的多主模式
在 apenglinux-001.cn主机上的设置:
停止MGR,关掉单主模式,开启多主模式,开启引导组,开启mgr,关闭引导组
mysql> stop group_replication;
mysql> set global group_replication_single_primary_mode=off;
mysql> set global group_replication_enforce_update_everywhere_checks=on;
mysql> set global group_replication_bootstrap_group=on;
mysql> start group_replication;
mysql> set global group_replication_bootstrap_group=off;
在apenglinux-002.cn,apenglinux-003.cn上的设置:
停止mgr,允许写入,加入组,关掉单主模式,开启多主模式,开启mgr
mysql> stop group_replication;
mysql> set global read_only=off,super_read_only=off;
mysql> set global group_replication_allow_local_disjoint_gtids_join=on;
mysql> set global group_replication_single_primary_mode=off;
mysql> set global group_replication_enforce_update_everywhere_checks=on;
mysql> start group_replication;
查看成员信息
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
| group_replication_applier | 8ea873c2-8f71-11e9-bbb4-000c298347f1 | apenglinux-001.cn | 3306 | ONLINE |
| group_replication_applier | a049b503-8f72-11e9-ba4b-000c2906c8f7 | apenglinux-002.cn | 3306 | ONLINE |
| group_replication_applier | d9fd5ea2-8f73-11e9-8f3b-000c29096feb | apenglinux-003.cn | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------------+-------------+--------------+
原文地址:https://blog.51cto.com/13480443/2411410
时间: 2024-10-10 01:15:13