0
点赞
收藏
分享

微信扫一扫

MGR Mysql 组复制

1、在 Centos01 上配置 NTP 时间服务器同步时间

1)挂载系统光盘 yum 安装时间服务器

[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载

[root@centos01 ~]# rm -rf /etc/yum.repos.d/CentOS-*

[root@centos01 ~]# cat /etc/yum.repos.d/local.repo

[local]

name=centos

baseurl=file:///mnt

enabled=1

gpgcheck=0

[root@centos01 ~]# yum -y install ntp

2)修改时间服务器配置文件

​root@centos01 ~]# vim /etc/ntp.conf

18 restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap

19 server 127.127.1.0

20 fudge 127.127.1.0 stratum 8

3)重新启动服务设置开启自动启动

[root@centos01 ~]# systemctl restart ntpd

[root@centos01 ~]# systemctl enable ntpd

4)从库和延时从库同步时间

[root@centos02 ~]# ntpdate 192.168.100.10

2 Mar 17:15:21 ntpdate[9744]: adjust time server 192.168.100.10 offset -0.010884 sec[root@centos03 ~]# ntpdate 192.168.100.10

2 Mar 17:15:28 ntpdate[3350]: adjust time server 192.168.100.10 offset -0.007429 sec

2、安装主 Mysql 数据库

1)安装 Mysql

​[root@centos01 ~]# tar zxf mysql-8.0.32-el7-x86_64.tar.gz -C /usr/src/

[root@centos01 ~]# mv /usr/src/mysql-8.0.32-el7-x86_64/ /usr/local/mysql

2)创建管理 Mysql 用户

​root@centos01 ~]# groupadd mysql

[root@centos01 ~]# useradd -M -s /sbin/nologin -g mysql mysql

3)优化 Mysql 命令

[root@centos01 ~]# echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile

[root@centos01 ~]# source /etc/profile

4)创建数据和日志存储目录

[root@centos01 ~]# mkdir /usr/local/mysql/date

[root@centos01 ~]# mkdir /usr/local/mysql/mysql-bin/

[root@centos01 ~]# chown -R mysql:mysql /usr/local/mysql/

5)生成 mysql 服务配置文件

[root@centos01 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@centos01 ~]# chmod +x /etc/init.d/mysqld

6)添加系统服务设置开机自动启动

[root@centos01 ~]# chkconfig --add mysqld

[root@centos01 ~]# chkconfig --level 35 mysqld on

7)修改主 Mysql 数据库配置文件

[root@centos01 ~]# vim /proc/sys/kernel/random/uuid 

996ae938-6650-48d5-8e21-f030ece7c93d

[root@centos01 ~]# vim /etc/my.cnf[mysqld]

user=mysql

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

port=3306

log-bin=/usr/local/mysql/mysql-bin/mysql-master-bin

log_replica_updates=1

server-id=10

secure-file-priv=/tmp

binlog_format=row

gtid-mode=on

enforce-gtid-consistency=true

skip_name_resolve

default_authentication_plugin=mysql_native_password //加载密码插件

binlog_checksum=NONE

binlog_transaction_dependency_tracking=WRITESET

transaction_write_set_extraction=XXHASH64

loose-group_replication_group_name="996ae938-6650-48d5-8e21-f030ece7c93d" //复制组

名字

loose-group_replication_start_on_boot=OFF //进制自动启动复制



loose-group_replication_local_address="192.168.100.10:33061"loose
group_replication_group_seeds="192.168.100.10:33061,192.168.100.20:33062,192.168.100

.30:33063"

loose-group_replication_bootstrap_group=OFF

8)初始化 Mysql 数据库

[root@centos01 ~]# mysqld --initialize-insecure

2023-03-05T08:24:39.842307Z 0 [Warning] [MY-011069] [Server] The syntax '--

transaction-write-set-extraction' is deprecated and will be removed in a future

release.

2023-03-05T08:24:39.842549Z 0 [Warning] [MY-010918] [Server]

'default_authentication_plugin' is deprecated and will be removed in a future

release. Please use authentication_policy instead.

2023-03-05T08:24:39.842613Z 0 [System] [MY-013169] [Server]

/usr/local/mysql/bin/mysqld (mysqld 8.0.32) initializing of server in progress as

process 7504

2023-03-05T08:24:39.865072Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization

has started.

2023-03-05T08:24:40.955156Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization

has ended.

2023-03-05T08:24:42.975603Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_group_name=996ae938-6650-48d5-8e21-f030ece7c93d'.

2023-03-05T08:24:42.975635Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_start_on_boot=OFF'.

2023-03-05T08:24:42.975653Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_local_address=192.168.100.10:33061'.2023-03-05T08:24:42.975671Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose
group_replication_group_seeds=192.168.100.10:33061,192.168.100.20:33062,192.168.100.

30:33063'.

2023-03-05T08:24:42.975689Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_bootstrap_group=OFF'.

2023-03-05T08:24:42.977876Z 6 [Warning] [MY-010453] [Server] root@localhost is

created with an empty password ! Please consider switching off the --initialize
insecure option.

9)启动 Mysql 服务

[root@centos01 ~]# systemctl start mysqld

[root@centos01 ~]# netstat -anptu | grep 3306

tcp6 0 0 :::33060 :::* LISTEN 4549/mysqld

tcp6 0 0 :::3306 :::* LISTEN 4549/mysqld

3、安装第一台从 Mysql 数据库

1)安装 Mysql

[root@centos02 ~]# tar zxf mysql-8.0.32-el7-x86_64.tar.gz -C /usr/src/

[root@centos02 ~]# mv /usr/src/mysql-8.0.32-el7-x86_64/ /usr/local/mysql

2)创建管理 Mysql 用户

[root@centos02 ~]# groupadd mysql

[root@centos02 ~]# useradd -M -s /sbin/nologin -g mysql

mysql

3)优化 Mysql 命令

[root@centos02 ~]# echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile

[root@centos02 ~]# source /etc/profile

4)创建数据和日志存储目录

[root@centos02 ~]# mkdir /usr/local/mysql/date

[root@centos02 ~]# mkdir /usr/local/mysql/mysql-bin/

[root@centos02 ~]# chown -R mysql:mysql /usr/local/mysql/

5)生成 mysql 服务配置文件

[root@centos02 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@centos02 ~]# chmod +x /etc/init.d/mysqld

6)添加系统服务设置开机自动启动

[root@centos02 ~]# chkconfig --add mysqld

[root@centos02 ~]# chkconfig --level 35 mysqld on

7)修改主 Mysql 数据库配置文件

[root@centos02 ~]# vim /etc/my.cnf

[mysqld]

user=mysql

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

port=3306

log-bin=/usr/local/mysql/mysql-bin/mysql-master-bin

log_replica_updates=1

server-id=20

secure-file-priv=/tmp

binlog_format=row

gtid-mode=on

enforce-gtid-consistency=true

skip_name_resolve //跳过DNS反向解析default_authentication_plugin=mysql_native_password //加载密码加密工具

binlog_checksum=NONE

binlog_transaction_dependency_tracking=WRITESET

transaction_write_set_extraction=XXHASH64 //事务读写结合使用sha算法加密

loose-group_replication_group_name="996ae938-6650-48d5-8e21-f030ece7c93d" //配置复

制组名字

loose-group_replication_start_on_boot=OFF //启动服务不自动启动复制组

loose-group_replication_local_address="192.168.100.20:33062" //接收其他组成员连接

loose
group_replication_group_seeds="192.168.100.10:33061,192.168.100.20:33062,192.168.100

.30:33063" //允许一下IP地址和端口连接

loose-group_replication_bootstrap_group=OFF //不需要配置为引导组

8)初始化 Mysql 数据库

[root@centos02 ~]# mysqld --initialize-insecure

2023-03-05T08:25:32.766501Z 0 [Warning] [MY-011069] [Server] The syntax '--

transaction-write-set-extraction' is deprecated and will be removed in a future

release.

2023-03-05T08:25:32.766672Z 0 [Warning] [MY-010918] [Server]

'default_authentication_plugin' is deprecated and will be removed in a future

release. Please use authentication_policy instead.

2023-03-05T08:25:32.766713Z 0 [System] [MY-013169] [Server]

/usr/local/mysql/bin/mysqld (mysqld 8.0.32) initializing of server in progress as

process 15382

2023-03-05T08:25:32.784985Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization

has started.2023-03-05T08:25:33.761875Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization

has ended.

2023-03-05T08:25:35.326136Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_group_name=996ae938-6650-48d5-8e21-f030ece7c93d'.

2023-03-05T08:25:35.326168Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_start_on_boot=OFF'.

2023-03-05T08:25:35.326186Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_local_address=192.168.100.20:33062'.

2023-03-05T08:25:35.326204Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose
group_replication_group_seeds=192.168.100.10:33061,192.168.100.20:33062,192.168.100.

30:33063'.

2023-03-05T08:25:35.326222Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_bootstrap_group=OFF'.

2023-03-05T08:25:35.328305Z 6 [Warning] [MY-010453] [Server] root@localhost is

created with an empty password ! Please consider switching off the --initialize
insecure option.

9)启动 Mysql 服务

[root@centos02 ~]# systemctl start mysqld

[root@centos02 ~]# netstat -anptu | grep 3306

tcp6 0 0 :::33060 :::* LISTEN 4549/mysqld

tcp6 0 0 :::3306 :::* LISTEN 4549/mysqld

4、安装第二台从 Mysql 数据库

1)安装 Mysql

[root@centos03 ~]# tar zxf mysql-8.0.32-el7-x86_64.tar.gz -C /usr/src/

[root@centos03 ~]# mv /usr/src/mysql-8.0.32-el7-x86_64/ /usr/local/mysql

2)创建管理 Mysql 用户

[root@centos03 ~]# groupadd mysql

[root@centos03 ~]# useradd -M -s /sbin/nologin -g mysql mysql

3)优化 Mysql 命令

[root@centos03 ~]# echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile

[root@centos03 ~]# source /etc/profile

4)创建数据和日志存储目录

[root@centos03 ~]# mkdir /usr/local/mysql/date

[root@centos03 ~]# mkdir /usr/local/mysql/mysql-bin/

[root@centos03 ~]# chown -R mysql:mysql /usr/local/mysql/

5)生成 mysql 服务配置文件

[root@centos03 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@centos03 ~]# chmod +x /etc/init.d/mysqld

6)添加系统服务设置开机自动启动

[root@centos03 ~]# chkconfig --add mysqld

[root@centos03 ~]# chkconfig --level 35 mysqld on

7)修改主 Mysql 数据库配置文件

[root@centos03 ~]# vim /etc/my.cnf

[mysqld]

user=mysql

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

port=3306log-bin=/usr/local/mysql/mysql-bin/mysql-master-bin

log_replica_updates=1

server-id=30

secure-file-priv=/tmp

binlog_format=row

gtid-mode=on

enforce-gtid-consistency=true

skip_name_resolve

default_authentication_plugin=mysql_native_password

binlog_checksum=NONE

binlog_transaction_dependency_tracking=WRITESET

transaction_write_set_extraction=XXHASH64

loose-group_replication_group_name="996ae938-6650-48d5-8e21-f030ece7c93d"

loose-group_replication_start_on_boot=OFF

loose-group_replication_local_address="192.168.100.30:33063"

loose
group_replication_group_seeds="192.168.100.10:33061,192.168.100.20:33062,192.168.100

.30:33063"

loose-group_replication_bootstrap_group=OFF

8)初始化 Mysql 数据库

​[root@centos03 ~]# mysqld --initialize-insecure

2023-03-05T08:26:17.023471Z 0 [Warning] [MY-011069] [Server] The syntax '--

transaction-write-set-extraction' is deprecated and will be removed in a future

release.2023-03-05T08:26:17.023640Z 0 [Warning] [MY-010918] [Server]

'default_authentication_plugin' is deprecated and will be removed in a future

release. Please use authentication_policy instead.

2023-03-05T08:26:17.023681Z 0 [System] [MY-013169] [Server]

/usr/local/mysql/bin/mysqld (mysqld 8.0.32) initializing of server in progress as

process 15872

2023-03-05T08:26:17.044102Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization

has started.

2023-03-05T08:26:18.065281Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization

has ended.

2023-03-05T08:26:19.888955Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_group_name=996ae938-6650-48d5-8e21-f030ece7c93d'.

2023-03-05T08:26:19.888985Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_start_on_boot=OFF'.

2023-03-05T08:26:19.889003Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_local_address=192.168.100.30:33063'.

2023-03-05T08:26:19.889020Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose
group_replication_group_seeds=192.168.100.10:33061,192.168.100.20:33062,192.168.100.

30:33063'.

2023-03-05T08:26:19.889038Z 0 [Warning] [MY-000067] [Server] unknown variable

'loose-group_replication_bootstrap_group=OFF'.2023-03-05T08:26:19.891231Z 6 [Warning] [MY-010453] [Server] root@localhost is

created with an empty password ! Please consider switching off the --initialize
insecure option.

9)启动 Mysql 服务

[root@centos03 ~]# systemctl start mysqld

[root@centos03 ~]# netstat -anptu | grep 3306

tcp6 0 0 :::33060 :::* LISTEN 4549/mysqld

tcp6 0 0 :::3306 :::* LISTEN 4549/mysqld

5、修改 hosts 文件

1)修改第一台 Mysql 数据库 hosts 文件

[root@centos01 ~]# vim /etc/hosts

192.168.100.10 centos01

192.168.100.20 centos02

192.168.100.30 centos03

2)将 hosts 文件复制到第二台 Mysql 服务器

[root@centos01 ~]# scp /etc/hosts root@192.168.100.20:/etc/

3)将 hosts 文件复制到第三台 Mysql 服务器

[root@centos01 ~]# scp /etc/hosts root@192.168.100.30:/etc/

二、在 Mysql 中配置单主多从复制组

1、在所有 Mysql 节点开启 Mysql 组复制功能

1)在主 Mysql 节点上安装 MGR 组复制插件创建授权访问用户

[root@centos01 ~]# mysqladmin -uroot password

New password:

Confirm new password:[root@centos01 ~]# mysql -uroot -ppwd@123 -e "install plugin group_replication

soname 'group_replication.so';"

[root@centos01 ~]# mysql -uroot -ppwd@123

mysql> set sql_log_bin=0;

mysql> create user repl@'%' identified by 'pwd@123';

mysql> create user repl@'localhost' identified by 'pwd@123';

mysql> create user repl@'127.0.0.1' identified by 'pwd@123';

mysql> grant replication slave,replication client on *.* to repl@'%';

mysql> grant replication slave,replication client on *.* to repl@'localhost';

mysql> grant replication slave,replication client on *.* to repl@'127.0.0.1';

mysql> flush privileges;

mysql> set sql_log_bin=1;

2)在第一台从 Mysql 节点上安装 MGR 组复制插件创建授权访问用户

[root@centos02 ~]# mysqladmin -uroot password

New password:

Confirm new password:

[root@centos01 ~]# mysql -uroot -ppwd@123 -e "install plugin group_replication

soname 'group_replication.so';"

[root@centos02 ~]# mysql -uroot -ppwd@123

mysql> set sql_log_bin=0;

mysql> create user repl@'%' identified by 'pwd@123';

mysql> create user repl@'localhost' identified by 'pwd@123';

mysql> create user repl@'127.0.0.1' identified by 'pwd@123';

mysql> grant replication slave,replication client on *.* to repl@'%';

mysql> grant replication slave,replication client on *.* to repl@'localhost';mysql> grant replication slave,replication client on *.* to repl@'127.0.0.1';

mysql> flush privileges;

mysql> set sql_log_bin=1;

3)在第二台从 Mysql 节点上安装 MGR 复制插件创建授权访问用户

[root@centos03 ~]# mysqladmin -uroot password

New password:

Confirm new password:

[root@centos03 ~]# mysql -uroot -ppwd@123 -e "install plugin group_replication

soname 'group_replication.so';"

[root@centos01 ~]# mysql -uroot -ppwd@123

mysql> set sql_log_bin=0;

mysql> create user repl@'%' identified by 'pwd@123';

mysql> create user repl@'localhost' identified by 'pwd@123';

mysql> create user repl@'127.0.0.1' identified by 'pwd@123';

mysql> grant replication slave,replication client on *.* to repl@'%';

mysql> grant replication slave,replication client on *.* to repl@'localhost';

mysql> grant replication slave,replication client on *.* to repl@'127.0.0.1';

mysql> flush privileges;

mysql> set sql_log_bin=1;

2、在主 Mysql 服务器配置为群集引导节点将两个从 Mysql 加入复制群集验

1)配置主 Mysql 为 MGR 群集引导节点

[root@centos01 ~]# mysql -uroot -ppwd@123mysql> change master to master_user='repl',master_password='pwd@123' for channel 

'group_replication_recovery';

Query OK, 0 rows affected, 5 warnings (0.02 sec)

mysql> set global group_replication_bootstrap_group=on; //设置引导组启动

Query OK, 0 rows affected (0.00 sec)

mysql> start group_replication; //启动复制组

Query OK, 0 rows affected (1.43 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 | MEMBER_ROLE | MEMBER_VERSION |

MEMBER_COMMUNICATION_STACK |

+---------------------------+--------------------------------------+----------------

+-------------+--------------+-------------+----------------+-----------------------

-----+

| group_replication_applier | ff85a6dd-bafd-11ed-b7e8-000c294cc769 | 192.168.100.10

| 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

+---------------------------+--------------------------------------+----------------

+-------------+--------------+-------------+----------------+-----------------------

-----+1 row in set (0.01 sec)

2)将第一台从 Mysql 加入到群集中

mysql> reset master;

Query OK, 0 rows affected (0.01 sec)

mysql> change master to master_user='repl',master_password='pwd@123' for channel

'group_replication_recovery';

Query OK, 0 rows affected, 5 warnings (0.02 sec)

mysql> start group_replication;

Query OK, 0 rows affected (3.17 sec)

3)将第二台从 Mysql 加入到群集中

mysql> reset master;

Query OK, 0 rows affected (0.01 sec)

mysql> change master to master_user='repl',master_password='pwd@123' for channel

'group_replication_recovery';

Query OK, 0 rows affected, 5 warnings (0.02 sec)

mysql> start group_replication;

Query OK, 0 rows affected (2.34 sec)

4)查看创建的 Mysql 组复制群集

[root@centos01 ~]# mysql -uroot -ppwd@123

mysql> select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+----------------

+-------------+--------------+-------------+----------------+-----------------------

-----+| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST |

MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |

MEMBER_COMMUNICATION_STACK |

+---------------------------+--------------------------------------+----------------

+-------------+--------------+-------------+----------------+-----------------------

-----+

| group_replication_applier | f08b8188-bafa-11ed-89a5-000c29bdb4a4 | 192.168.100.20

| 3306 | ONLINE | SECONDARY | 8.0.32 | XCom |

| group_replication_applier | fc73f235-bafa-11ed-9eed-000c2962859c | 192.168.100.30

| 3306 | ONLINE | SECONDARY | 8.0.32 | XCom |

| group_replication_applier | ff85a6dd-bafd-11ed-b7e8-000c294cc769 | 192.168.100.10

| 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

+---------------------------+--------------------------------------+----------------

+-------------+--------------+-------------+----------------+-----------------------

-----+

3 rows in set (0.00 sec)

3、验证 MGR 复制

1)停止主 mysql 服务指定选举新的主节点

[root@centos01 ~]# systemctl stop mysqld

[root@centos02 ~]# mysql -uroot -ppwd@123

mysql> select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| group_replication_applier | f08b8188-bafa-11ed-89a5-000c29bdb4a4 | 192.168.100.20 | 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

| group_replication_applier | fc73f235-bafa-11ed-9eed-000c2962859c | 192.168.100.30 | 3306 | ONLINE | SECONDARY | 8.0.32 | XCom |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

2 rows in set (0.00 sec)2)在线修改主节点

mysql> select group_replication_set_as_primary('fc73f235-bafa-11ed-9eed-000c2962859c');

+--------------------------------------------------------------------------+

| group_replication_set_as_primary('fc73f235-bafa-11ed-9eed-000c2962859c') |

+--------------------------------------------------------------------------+

| Primary server switched to: fc73f235-bafa-11ed-9eed-000c2962859c |

+--------------------------------------------------------------------------+

1 row in set (0.07 sec)

mysql> select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| group_replication_applier | f08b8188-bafa-11ed-89a5-000c29bdb4a4 | 192.168.100.20| 3306 | ONLINE | SECONDARY | 8.0.32 | XCom |

| group_replication_applier | fc73f235-bafa-11ed-9eed-000c2962859c | 192.168.100.30 | 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

| group_replication_applier | ff85a6dd-bafd-11ed-b7e8-000c294cc769 | 192.168.100.10 | 3306 | ONLINE | SECONDARY | 8.0.32 | XCom |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

3 rows in set (0.01 sec)

3)从单主模式修改为多主模式

mysql> select group_replication_switch_to_multi_primary_mode(); 
//多主模式

+--------------------------------------------------+

| group_replication_switch_to_multi_primary_mode() |

+--------------------------------------------------+

| Mode switched to multi-primary successfully. |

+--------------------------------------------------+

1 row in set (0.01 sec)

mysql> select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| group_replication_applier | f08b8188-bafa-11ed-89a5-000c29bdb4a4 | 192.168.100.20| 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

| group_replication_applier | fc73f235-bafa-11ed-9eed-000c2962859c | 192.168.100.30 | 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

| group_replication_applier | ff85a6dd-bafd-11ed-b7e8-000c294cc769 | 192.168.100.10 | 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

3 rows in set (0.00 sec)

mysql> select group_replication_switch_to_single_primary_mode();

//修改为单主

模式

+---------------------------------------------------+

| group_replication_switch_to_single_primary_mode() |

+---------------------------------------------------+

| Mode switched to single-primary successfully. |

+---------------------------------------------------+

1 row in set (0.01 sec)mysql> select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| group_replication_applier | f08b8188-bafa-11ed-89a5-000c29bdb4a4 | 192.168.100.20 | 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

|group_replication_applier | fc73f235-bafa-11ed-9eed-000c2962859c | 192.168.100.30 | 3306 | ONLINE | SECONDARY | 8.0.32 | XCom |

| group_replication_applier | ff85a6dd-bafd-11ed-b7e8-000c294cc769 | 192.168.100.10 | 3306 | ONLINE | SECONDARY | 8.0.32 | XCom |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

3 rows in set (0.00 sec)

4、配置 MGR 多主复制

1)停止单主复制模式配置多主

[root@centos02 ~]# mysql -uroot -ppwd@123

mysql> stop group_replication;

Query OK, 0 rows affected (3.22 sec)

mysql> set global group_replication_single_primary_mode=off;

Query OK, 0 rows affected (0.00 sec)

mysql> set global group_replication_enforce_update_everywhere_checks=1;

Query OK, 0 rows affected (0.00 sec)

mysql> select

@@group_replication_single_primary_mode,@@group_replication_enforce_update_everywher

e_checks;

+-----------------------------------------+-----------------------------------------

-------------+

| @@group_replication_single_primary_mode |

@@group_replication_enforce_update_everywhere_checks |

+-----------------------------------------+-----------------------------------------

-------------+

| 0 | 1 |+-----------------------------------------+-----------------------------------------

-------------+

1 row in set (0.00 sec)

mysql> set global read_only=0; //关闭只读功能

Query OK, 0 rows affected (0.00 sec)

mysql> set global super_read_only=0;

Query OK, 0 rows affected (0.00 sec)

2)修改主 Mysql 数据库配置设置为引导节点

mysql> stop group_replication;

Query OK, 0 rows affected (3.25 sec)

mysql> set global group_replication_single_primary_mode=off;

Query OK, 0 rows affected (0.00 sec)

mysql> set global group_replication_enforce_update_everywhere_checks=on;

Query OK, 0 rows affected (0.00 sec)

mysql> set global group_replication_bootstrap_group=on;

Query OK, 0 rows affected (0.00 sec)

mysql> start group_replication;

Query OK, 0 rows affected (1.25 sec)

3)将第二个主节点添加到 Mysql 复制组群集

[root@centos02 ~]# mysql -uroot -ppwd@123

mysql> start group_replication;

Query OK, 0 rows affected (2.29 sec)

4)查看多主复制数据

mysql> select * from performance_schema.replication_group_members;

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

| group_replication_applier | f08b8188-bafa-11ed-89a5-000c29bdb4a4 | 192.168.100.20 | 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

| group_replication_applier | fc73f235-bafa-11ed-9eed-000c2962859c | 192.168.100.30 | 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

| group_replication_applier | ff85a6dd-bafd-11ed-b7e8-000c294cc769 | 192.168.100.10 | 3306 | ONLINE | PRIMARY | 8.0.32 | XCom |

+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+----------------------------+

3 rows in set (0.00 sec)

举报

相关推荐

0 条评论