配置mysql 组复制
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了配置mysql 组复制相关的知识,希望对你有一定的参考价值。
前面一篇文章简要介绍了mysql组复制的工作流程、先决条件与限制条件,以及同传统的异步复制集半同步复制的特点进行对比。本文将介绍mysql组复制的具体配置过程。
一、环境介绍
操作系统版本:centos linux 7.2 64bit
Mysql版本:mysql-5.7.19-linux-glibc2.12-x86_64
3台服务器hosts文件(其中vm2作为mysql组复制的第一台主机,通常第一台启动的为master)
# cat /etc/hosts
192.168.115.5 vm1
192.168.115.6 vm2
192.168.115.7 vm3
二、配置vm2的my.cnf文件
server-id=1155 lower_case_table_names = 1 skip-name-resolve innodb_file_per_table=1 gtid_mode = ON enforce_gtid_consistency = ON slave_parallel_workers=4 master_verify_checksum = 1 slave_sql_verify_checksum = 1 log-slave-updates=true sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES slave-parallel-type=LOGICAL_CLOCK slave-preserve-commit-order=ON master_info_repository = TABLE relay_log_info_repository = TABLE binlog_checksum = NONE transaction_write_set_extraction = XXHASH64 loose-group_replication_group_name = ‘aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa‘ loose-group_replication_start_on_boot = off loose-group_replication_local_address = ‘vm2:3306‘ loose-group_replication_group_seeds =‘vm1:3306,vm2:3306,vm3:3306‘ loose-group_replication_bootstrap_group = off
各项配置文件的具体含义可参考mysql手册(mysql的安装部署本文省略,具体也可参考mysql手册):
https://dev.mysql.com/doc/refman/5.7/en/group-replication-configuring-instances.html
三、在vm2上创建复制账号及权限配置
mysql> set SQL_LOG_BIN=0; Query OK, 0 rows affected (0.01 sec) mysql> create user [email protected]‘%‘ identified by "123456"; Query OK, 0 rows affected (0.00 sec) mysql> grant replication slave on *.* to [email protected]‘%‘; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> set SQL_LOG_BIN=1; Query OK, 0 rows affected (0.00 sec) mysql> change master to master_user=‘repl‘,master_password=‘123456‘ for channel ‘group_replication_recovery‘; Query OK, 0 rows affected, 2 warnings (0.08 sec) mysql> install PLUGIN group_replication SONAME ‘group_replication.so‘; Query OK, 0 rows affected (0.53 sec)
四、启动vm2上的group replication进程
mysql> set global group_replication_bootstrap_group=ON; Query OK, 0 rows affected (0.01 sec) mysql> start group_replication; Query OK, 0 rows affected (2.66 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 | 33025907-6d2d-11e7-8ce6-000c29e07281 | vm2 | 3306 | ONLINE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ 1 row in set (0.00 sec)
五、按照VM2相同的方法配置VM3,注意my.cnf文件中的server-id需要修改
mysql> set SQL_LOG_BIN=0; Query OK, 0 rows affected (0.00 sec) mysql> create user [email protected]‘%‘ identified by "123456"; Query OK, 0 rows affected (0.01 sec) mysql> grant replication slave on *.* to [email protected]‘%‘; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> set SQL_LOG_BIN=1; Query OK, 0 rows affected (0.00 sec) mysql> change master to master_user=‘repl‘,master_password=‘123456‘ 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.38 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 (7.89 sec) mysql> select * from performance_schema.replication_group_members; +---------------------------+--------------------------------------+-------------+-------------+--------------+ | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ | group_replication_applier | 33025907-6d2d-11e7-8ce6-000c29e07281 | vm2 | 3306 | ONLINE | | group_replication_applier | 35678d62-6d2d-11e7-80a7-000c2909332c | vm3 | 3306 | ONLINE | | group_replication_applier | 8b643791-6d30-11e7-986a-000c29d53b31 | vm1 | 3306 | ONLINE | +---------------------------+--------------------------------------+-------------+-------------+--------------+ 3 rows in set (0.00 sec)
这里面需要注意的是后面加入组复制的vm3和vm1,需要配置group_replication_allow_local_disjoint_gtids_join参数为ON,据文档描述开启此参数的含义为假如当前的数据库上的事务在组复制中不存在,一样允许加入组复制。
本文出自 “斩月” 博客,谢绝转载!
以上是关于配置mysql 组复制的主要内容,如果未能解决你的问题,请参考以下文章
Mysql 8 group replication组复制集群单主配置图解