侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

MySql Group Replication 搭建(Muti-Master Mode)

2023-11-13 星期一 / 0 评论 / 0 点赞 / 46 阅读 / 11023 字

组复制的作用: The following examples are typical use cases for Group Replication. Elastic Replication-

组复制的作用:

The following examples are typical use cases for Group Replication.

  • Elastic Replication - Environments that require a very fluid replication infrastructure, where the number of servers has to grow or shrink dynamically and with as few side-effects as possible. For instance, database services for the cloud.

  • Highly Available Shards - Sharding is a popular approach to achieve write scale-out. Use MySQL Group Replication to implement highly available shards, where each shard maps to a replication group.

  • Alternative to Master-Slave replication - In certain situations, using a single master server makes it a single point of contention. Writing to an entire group may prove more scalable under certain circumstances.

  • Autonomic Systems - Additionally, you can deploy MySQL Group Replication purely for the automation that is built into the replication protocol (described already in this and previous chapters).

官网给出的示意图

之前应

1.修改主机名与映射

参考:https://my.oschina.net/u/3407012/blog/889505

2.防火墙

参考:https://my.oschina.net/u/3407012/blog/889528

第一步:安装MySql 5.7,参考 https://my.oschina.net/u/3407012/blog/889497

第二步:修改 MySql 配置文件,增加以下配置

# *********** configure replication according  *******************************user=mysqlserver_id=154(标识每个机器,一般取ip最后段)gtid_mode=ONenforce_gtid_consistency=ONmaster_info_repository=TABLErelay_log_info_repository=TABLEbinlog_checksum=NONElog_slave_updates=ONlog_bin=binlogbinlog_format=ROW# *********** Group Replication Settings  *************************************transaction_write_set_extraction=XXHASH64loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"loose-group_replication_start_on_boot=offloose-group_replication_local_address= "host4:24904"loose-group_replication_group_seeds= "host1:24901,host3:24903,host4:24904"loose-group_replication_bootstrap_group= off

第三步:创建凭证

可参考https://dev.mysql.com/doc/refman/5.7/en/group-replication-user-credentials.html

mysql> SET SQL_LOG_BIN=0;Query OK, 0 rows affected (0,00 sec)mysql> CREATE USER rpl_user@'%';Query OK, 0 rows affected (0,00 sec)mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';Query OK, 0 rows affected, 1 warning (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='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';Query OK, 0 rows affected, 2 warnings (0,01 sec)

第四步:安装组复制插件

mysql>INSTALL PLUGIN group_replication SONAME 'group_replication.so';
mysql> SHOW PLUGINS;+----------------------------+----------+--------------------+----------------------+-------------+| Name                       | Status   | Type               | Library              | License     |+----------------------------+----------+--------------------+----------------------+-------------+| binlog                     | ACTIVE   | STORAGE ENGINE     | NULL                 | PROPRIETARY |(...)| group_replication          | ACTIVE   | GROUP REPLICATION  | group_replication.so | PROPRIETARY |+----------------------------+----------+--------------------+----------------------+------------

第五步:开启组

SET GLOBAL group_replication_bootstrap_group=ON;START GROUP_REPLICATION;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 | 17d5e429-2cc0-11e7-b506-00505684822e | host3       |       33063 | ONLINE       |+---------------------------+--------------------------------------+-------------+-------------+--------------+

第六步:新增SLAVE

同上第五步之前,第五步时需要

mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;mysql> START GROUP_REPLICATION;Query OK, 0 rows affected (44,88 sec)mysql> SELECT * FROM performance_schema.replication_group_members;+---------------------------+--------------------------------------+-------------+-------------+--------------+| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |+---------------------------+--------------------------------------+-------------+-------------+--------------+| group_replication_applier | 17d5e429-2cc0-11e7-b506-00505684822e | host3       |       33063 | ONLINE       || group_replication_applier | 59fae48b-2cc4-11e7-bba9-005056844614 | host1       |       33061 | ONLINE       || group_replication_applier | f3c27092-2ce0-11e7-9729-00505684d3b9 | host4       |       33064 | ONLINE       |+---------------------------+--------------------------------------+-------------+-------------+--------------+3 rows in set (0.00 sec)

第八步:创建测试数据

mysql> CREATE DATABASE test;Query OK, 1 row affected (0,00 sec)mysql> use testDatabase changedmysql> CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL);Query OK, 0 rows affected (0,00 sec)mysql> INSERT INTO t1 VALUES (1, 'Luis');Query OK, 1 row affected (0,01 sec)
mysql> SELECT * FROM t1;+----+------+| c1 | c2   |+----+------+|  1 | Luis |+----+------+1 row in set (0,00 sec)mysql> SHOW BINLOG EVENTS;+---------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------+| Log_name      | Pos | Event_type     | Server_id | End_log_pos | Info                                                               |+---------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------+| binlog.000001 |   4 | Format_desc    |         1 |         123 | Server ver: 5.7.17-gr080-log, Binlog ver: 4                        || binlog.000001 | 123 | Previous_gtids |         1 |         150 |                                                                    || binlog.000001 | 150 | Gtid           |         1 |         211 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1'  || binlog.000001 | 211 | Query          |         1 |         270 | BEGIN                                                              || binlog.000001 | 270 | View_change    |         1 |         369 | view_id=14724817264259180:1                                        || binlog.000001 | 369 | Query          |         1 |         434 | COMMIT                                                             || binlog.000001 | 434 | Gtid           |         1 |         495 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2'  || binlog.000001 | 495 | Query          |         1 |         585 | CREATE DATABASE test                                               || binlog.000001 | 585 | Gtid           |         1 |         646 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:3'  || binlog.000001 | 646 | Query          |         1 |         770 | use `test`; CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL) || binlog.000001 | 770 | Gtid           |         1 |         831 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:4'  || binlog.000001 | 831 | Query          |         1 |         899 | BEGIN                                                              || binlog.000001 | 899 | Table_map      |         1 |         942 | table_id: 108 (test.t1)                                            || binlog.000001 | 942 | Write_rows     |         1 |         984 | table_id: 108 flags: STMT_END_F                                    || binlog.000001 | 984 | Xid            |         1 |        1011 | COMMIT /* xid=38 */                                                |+---------------+-----+----------------+-----------+-------------+--------------------------------------------------------------------+15 rows in set (0,00 sec)

第九步:查看其他节点是否有数据

 

如要想动态扩容,那么需要在其他节点上执行:

mysql> set global group_replication_group_seeds="host1:24901,host2:24902...";Query OK, 0 rows affected (0.00 sec)mysql> show variables like '%group_replication_group_seeds%';+-------------------------------+-----------------------------------------------------+| Variable_name                 | Value                                                                           |+-------------------------------+-----------------------------------------------------+| group_replication_group_seeds | host1:24901,host2:24902 ...                              |+-------------------------------+-----------------------------------------------------+1 row in set (0.00 sec)

其他命令

1.查询谁是主(Single-Primary Mode):

SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member';

 

广告 广告

评论区