Mysql MGR提供了高可用、高扩展和高可靠的MySQL集群服务,mgr集群当前支持最大9个节点,采用多副本,在2N+1个节点集群中,集群中只要N +1个节点存活,数据库就能稳定运行并对外提供服务。
1、初始化新的数据库,这里省略。
2、修改新节点的参数
[mysqld]
datadir=/data1/mgr4/data
basedir=/usr/local/mysql
port=3306
socket=/data1/mgr4/mysql.sock
server_id=3
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
basedir=/usr/local/mysql
port=3306
socket=/data1/mgr4/mysql.sock
server_id=3
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
log_error=/data1/mgr4/logs/error.log
log_bin=/data1/mgr4/logs/mysql-bin
transaction_write_set_extraction=XXHASH64
###
max_connections=1024
wait_timeout=60
sort_buffer_size=2M
max_allowed_packet=32M
join_buffer_size=2M
innodb_buffer_pool_size=128M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_log_files_in_group=2
binlog_cache_size=2M
max_binlog_cache_size=8M
max_binlog_size=512M
expire_logs_days=7
slow_query_log=on
slow_query_log_file=/data1/mgr4/logs/slow.log
###
loose-group_replication_group_name="05153196-c2ab-43ae-b355-b9832eacf0b2"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="192.168.170.19:33061"
loose-group_replication_group_seeds="192.168.170.17:33060,192.168.170.18:33060,192.168.170.19:33060,192.168.170.19:33061"
loose-group_replication_bootstrap_group=off
loose-group_replication_single_primary_mode=true
loose-group_replication_enforce_update_everywhere_checks=false
注意:server_id、loose-group_replication_local_address和loose-group_replication_group_seeds应该按照实际的情况调整好。
3、在原集群所有的节点中,把新节点增加进来
mysql> set global group_replication_group_seeds='192.168.170.17:33060,192.168.170.18:33060,192.168.170.19:33060,192.168.170.19:30061';
Query OK, 0 rows affected (0.00 sec)
4、在新节点中,增加复制的用户、加载group replication插件及加入mgr集群
mysql> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)
mysql> create user repl@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to repl@'%';
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> install plugin group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.11 sec)
mysql> change master to master_user='repl',master_password='123456' for channel 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (1.24 sec)
5、查询主节点日志,发现新节点已成功加入并开始同步数据
#####主节点日志,新节点已成功加入
2021-08-19T09:03:25.631311Z 0 [Note] Plugin group_replication reported: 'Members joined the group: rac3:3307'
2021-08-19T09:03:25.631599Z 0 [Note] Plugin group_replication reported: 'Group membership changed to rac1:3306, rac3:3307, rac2:3306, rac3:3306 on view 16292786917612147:6.'
#####新节点启动group replication服务
2021-08-19T09:03:21.481504Z 3 [Note] Plugin group_replication reported: 'Group communication SSL configuration: group_replication_ssl_mode: "DISABLED"'
2021-08-19T09:03:21.481713Z 3 [Note] Plugin group_replication reported: '[GCS] Added automatically IP ranges 127.0.0.1/8,192.168.122.1/24,192.168.170.19/24 to the whitelist'
2021-08-19T09:03:21.481964Z 3 [Warning] Plugin group_replication reported: '[GCS] Automatically adding IPv4 localhost address to the whitelist. It is mandatory that it is added.'
#####调用gsc,xcom的初始化
2021-08-19T09:03:23.382629Z 3 [Note] Plugin group_replication reported: 'Group Replication applier module successfully initialized!'
2021-08-19T09:03:23.382940Z 3 [Note] Plugin group_replication reported: 'auto_increment_increment is set to 7'
2021-08-19T09:03:23.382951Z 3 [Note] Plugin group_replication reported: 'auto_increment_offset is set to 4'
2021-08-19T09:03:23.409660Z 0 [Note] Plugin group_replication reported: 'XCom protocol version: 3'
2021-08-19T09:03:23.432515Z 0 [Note] Plugin group_replication reported: 'XCom initialized and ready to accept incoming connections on port 33061'
2021-08-19T09:03:25.632859Z 3 [Note] Plugin group_replication reported: 'This server is working as secondary member with primary member address rac2:3306.'
备注:如果数据量较大,可预先通过mysqldump或者xtrabackup先导入部分数据,在开启group replication。