MySQL MGR--MGR部署

MGR部署

场景描述:

使用三台服务器搭建一个简单MGR集群,使用MySQL 5.7.24版本,服务器列表为:

192.168.1.147
192.168.1.148
192.168.1.149

 

1、使用普通配置文件启动MySQL服务,安装MGR插件(所有节点执行)

INSTALL PLUGIN group_replication SONAME 'group_replication.so';

 

2、调整MySQL各节点的配置文件并重启MySQL服务(所有节点执行)

## config master
server-id               				= 17218228149
log-bin                 				= mysql-bin
master_info_repository  				= TABLE
binlog_format           				= ROW
expire_logs_days        				= 7
sync_binlog             				= 1
gtid_mode                				= on
enforce-gtid-consistency 				= true
binlog_rows_query_log_events 			        = on
binlog_checksum                         = NONE ## config slave skip-slave-start slave-parallel-workers = 8 slave-parallel-type = LOGICAL_CLOCK slave_preserve_commit_order = 1 log_slave_updates = 1 report_host = 192.168.1.149 ## config relay log relay-log = relay-log relay_log_recovery = ON sync_relay_log = 0 relay_log_info_repository = TABLE ## config group replication transaction_write_set_extraction    = XXHASH64 loose-group_replication_group_name    = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaa01" loose-group_replication_start_on_boot         = OFF loose-group_replication_bootstrap_group         = OFF loose-group_replication_local_address         = "192.168.1.149:33581" loose-group_replication_group_seeds    = "192.168.1.147:33581,192.168.1.148:33581,192.168.1.149:33581" loose-group_replication_ip_whitelist         = "192.168.1.147,192.168.1.148,192.168.1.149"

未安装MGR插件前在配置文件加入MGR配置会报错。

MGR配置说明:上面黄色部分参数在很多配置文件中都没提到,但很可能会导致部署失败,尤其是loose-group_replication_ip_whitelist参数。

 

3、配置MGR通信账号,并清理MASTER(所有节点执行)

CREATE USER repl@'%' IDENTIFIED BY 'repl';
GRANT REPLICATION SLAVE ON *.* TO repl@'%';
RESET MASTER;

 

4、创建MGR依赖的复制环境(所有节点执行)

CHANGE MASTER TO MASTER_USER='repl', 
MASTER_PASSWORD='repl'
FOR CHANNEL 'group_replication_recovery';

 

5、在主节点上启动MGR(在节点192.168.1.147上执行)

SET GLOBAL group_replication_bootstrap_group=ON;
START group_replication;
SET GLOBAL group_replication_bootstrap_group=off;

 

6、在辅助节点上启动MGR(在节点192.168.1.148和在节点192.168.1.149上执行)

START group_replication;

 

7、搭建完成后,可以使用下面语句查看状态:

## 查看各节点状态
SELECT * 
FROM performance_schema.replication_group_members;

## 查看当前MGR模式(单主还是多主)
SELECT @@group_replication_single_primary_mode;

 

8、判断节点状态

## 查看当前节点状态
SELECT member_state 
FROM performance_schema.replication_group_members 
WHERE member_id=@@server_uuid;


## 通过节点是否可写来判断群集是否为主节点
SELECT * 
FROM performance_schema.global_variables 
WHERE variable_name IN ('read_only', 'super_read_only');

MGR成员的五种状态:

ONLINE: The member is in a fully functioning state.

RECOVERING: The server has joined a group from which it is retrieving data.

OFFLINE: The group replication plugin is installed but has not been started.

ERROR: The member has encountered an error, either during applying transactions or during the recovery phase, and is not participating in the group's transactions.

UNREACHABLE: The failure detection process suspects that this member cannot be contacted, because the group messages have timed out.

 

新增MGR节点

目前MySQL不支持自动扩展新节点并将全量数据同步到新节点,因此需要:

1、备份任一节点数据(MySQLDump或Xtrabackup)至新节点并还原

2、在新节点上设置与备份数据对应的Executed_Gtid_Set

3、在新节点上执行下面命令直接启动MGR复制即可。

CHANGE MASTER TO MASTER_USER='repl', 
MASTER_PASSWORD='repl'
FOR CHANNEL 'group_replication_recovery';

START GROUP_REPLICATION;

 

转载于:https://www.cnblogs.com/gaogao67/p/11199360.html

你可能感兴趣的:(MySQL MGR--MGR部署)