ITPub博客

首页 > 数据库 > MySQL > 单机MGR搭建

单机MGR搭建

原创 MySQL 作者:to_be_Dba 时间:2021-12-14 07:07:09 0 删除 编辑


mkdir -p /app/mysql/data/{3310,3311,3312}

mkdir -p /app/mysql/log/{3310,3311,3312}

mkdir -p /app/mysql/app

mkdir -p /app/mysql/backup


cd /app/mysql/log

chown -R mysql.mysql 331*

cd /app/mysql/data

chown -R mysql.mysql 331*

chown mysql.mysql -R backup



cat >>/app/mysql/data/my3310.cnf <<EOF

[client]

socket = /app/mysql/data/mysql3310.sock 

port = 3310

[mysqld]

# log_bin

basedir = /app/mysql/app/mysql8027

datadir = /app/mysql/data/3310

port = 3310

socket = /app/mysql/data/mysql3310.sock

log-error =/app/mysql/log/3310/mysqld.log

pid-file = /app/mysql/data/mysqld3310.pid

slow_query_log = ON

slow_query_log_file = /app/mysql/log/3310/mysql_slow.log

long_query_time = 1

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Group Replication

server_id = 3310

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

sync_binlog = 1

expire_logs_days = 3


#plugin

mysqlx=0

#default_authentication_plugin = mysql_native_password

plugin-load-add=mysql_clone.so

plugin-load-add=group_replication.so


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 ='172.30.135.119:33101'

loose-group_replication_group_seeds ='172.30.135.119:33101,172.30.135.119:33111,172.30.135.119:33121'

loose-group_replication_bootstrap_group = off


#---------------replicate--------------#

relay-log-index = relay.index

relay-log = relay

log-slave-updates

EOF


分别将server_id改为3310、3311、3312

loose-group_replication_local_address改为3310、3311、3312端口:


cat >/app/mysql/data/my3311.cnf <<EOF

[client]

socket = /app/mysql/data/mysql3311.sock 

port = 3311

[mysqld]

# log_bin

basedir = /app/mysql/app/mysql8027

datadir = /app/mysql/data/3311

port = 3311

socket = /app/mysql/data/mysql3311.sock

log-error =/app/mysql/log/3311/mysqld.log

pid-file = /app/mysql/data/mysqld3311.pid

slow_query_log = ON

slow_query_log_file = /app/mysql/log/3311/mysql_slow.log

long_query_time = 1

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Group Replication

server_id = 3311

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

sync_binlog = 1

expire_logs_days = 3


#plugin

mysqlx=0

#default_authentication_plugin = mysql_native_password

plugin-load-add=mysql_clone.so

plugin-load-add=group_replication.so


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 ='172.30.135.119:33111'

loose-group_replication_group_seeds ='172.30.135.119:33101,172.30.135.119:33111,172.30.135.119:33121'

loose-group_replication_bootstrap_group = off


#---------------replicate--------------#

relay-log-index = relay.index

relay-log = relay

log-slave-updates

EOF



cat >/app/mysql/data/my3312.cnf <<EOF

[client]

socket = /app/mysql/data/mysql3312.sock 

port = 3312

[mysqld]

# log_bin

basedir = /app/mysql/app/mysql8027

datadir = /app/mysql/data/3312

port = 3312

socket = /app/mysql/data/mysql3312.sock

log-error =/app/mysql/log/3312/mysqld.log

pid-file = /app/mysql/data/mysqld3312.pid

slow_query_log = ON

slow_query_log_file = /app/mysql/log/3312/mysql_slow.log

long_query_time = 1

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Group Replication

server_id = 3312

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

sync_binlog = 1

expire_logs_days = 3


#plugin

mysqlx=0

#default_authentication_plugin = mysql_native_password

plugin-load-add=mysql_clone.so

plugin-load-add=group_replication.so


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 ='172.30.135.119:33121'

loose-group_replication_group_seeds ='172.30.135.119:33101,172.30.135.119:33111,172.30.135.119:33121'

loose-group_replication_bootstrap_group = off


#---------------replicate--------------#

relay-log-index = relay.index

relay-log = relay

log-slave-updates

EOF


chown -R mysql.mysql /app/mysql/data/my*.cnf



/app/mysql/app/mysql8027/bin/mysqld --initialize --user=mysql --basedir=/app/mysql/app/mysql8027 --datadir=/app/mysql/data/3310

/app/mysql/app/mysql8027/bin/mysqld --initialize --user=mysql --basedir=/app/mysql/app/mysql8027 --datadir=/app/mysql/data/3311

/app/mysql/app/mysql8027/bin/mysqld --initialize --user=mysql --basedir=/app/mysql/app/mysql8027 --datadir=/app/mysql/data/3312



初始root密码如下

3310:Nhnxa8tlWi%8

3311:wD#P8B_!N8lO

3312:Fyf_fo*F&0ug


/app/mysql/app/mysql8027/bin/mysqld --defaults-file=/app/mysql/data/my3310.cnf --user=mysql --datadir=/app/mysql/data/3310 --plugin-dir=/app/mysql/app/mysql8027/lib/plugin  --basedir=/app/mysql/app/mysql8027 --pid-file=/app/mysql/data/mysql3310.pid --socket=/app/mysql/data/mysql3310.sock --port=3310 &

/app/mysql/app/mysql8027/bin/mysql -uroot -P 3310 -h127.0.0.1 -p


alter user root@`localhost` identified with  mysql_native_password by 'root123';

set sql_log_bin=0;

create user rpl_user@'%'  identified with  mysql_native_password  by 'rpl_pass';

grant replication slave on *.* to rpl_user@'%' ;

flush privileges;

set sql_log_bin=1;

change master to master_user='rpl_user',master_password='rpl_pass' for channel 'group_replication_recovery';


报错:

mysql> install PLUGIN group_replication SONAME 'group_replication.so';

ERROR 1126 (HY000): Can't open shared library '/root/mysql8025/lib/plugin/group_replication.so' (errno: 0 /root/mysql8025/lib/plugin/group_replication.so: cannot open shared object file: Permission denied)


使用软链接存储mysql安装文件时总有这个报错。换成实际地址存放后解决。



mysql> show plugins;

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

| Name                            | Status   | Type               | Library              | License |

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

| binlog                          | ACTIVE   | STORAGE ENGINE     | NULL                 | GPL     |

……

| clone                           | ACTIVE   | CLONE              | mysql_clone.so       | GPL     |

| group_replication               | ACTIVE   | GROUP REPLICATION  | group_replication.so | GPL     |

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

47 rows in set (0.00 sec)



@3310库:

CREATE USER 'clone_user' IDENTIFIED BY 'password';

GRANT BACKUP_ADMIN on *.* to 'clone_user';


--装插件

INSTALL PLUGIN clone SONAME 'mysql_clone.so';

select * from information_schema.plugins where plugin_name='clone';



##############################

@目标库:

/app/mysql/app/mysql8027/bin/mysqld --defaults-file=/app/mysql/data/my3311.cnf --user=mysql --datadir=/app/mysql/data/3311 --plugin-dir=/app/mysql/app/mysql8027/lib/plugin  --basedir=/app/mysql/app/mysql8027 --pid-file=/app/mysql/data/mysql3311.pid --socket=/app/mysql/data/mysql3311.sock --port=3311 &

/app/mysql/app/mysql8027/bin/mysql -uroot -P 3311 -h127.0.0.1 -p


/app/mysql/app/mysql8027/bin/mysqld --defaults-file=/app/mysql/data/my3312.cnf --user=mysql --datadir=/app/mysql/data/3312 --plugin-dir=/app/mysql/app/mysql8027/lib/plugin  --basedir=/app/mysql/app/mysql8027 --pid-file=/app/mysql/data/mysql3312.pid --socket=/app/mysql/data/mysql3312.sock --port=3312 &

/app/mysql/app/mysql8027/bin/mysql -uroot -P 3312 -h127.0.0.1 -p


alter user root@`localhost` identified with  mysql_native_password by 'root123';

set sql_log_bin=0;

create user rpl_user@'%'  identified with  mysql_native_password  by 'rpl_pass';

grant replication slave on *.* to rpl_user@'%' ;

flush privileges;

set sql_log_bin=1;


--装插件

INSTALL PLUGIN clone SONAME 'mysql_clone.so';

--设参数

SET GLOBAL clone_valid_donor_list = '172.30.135.119:3310';

--执行克隆操作

clone instance from 'clone_user'@`172.30.135.119`:3310 identified by 'password';

克隆结束后会尝试自动重启实例,由于当前环境需要用mysql命令重启(未设置systemctl方式重启),报错:

ERROR 3707 (HY000): Restart server failed (mysqld is not managed by supervisor process).

这个是正常现象。


无需修改,启动实例,命令略


在原库和目标库分别执行命令 show master status;

由于操作期间原库39.51没有数据变化,可以看到其Executed_Gtid_Set一样






在第一个节点开启引导功能,立即开启该节点的组复制功能来创建组,然后立即关闭组引导功能

@3310:

set global group_replication_bootstrap_group=ON;

start group_replication;

set global group_replication_bootstrap_group=OFF;

select * from performance_schema.replication_group_members;


@3311、3312




可能用到的操作:

关闭 -》     /app/mysql/app/mysql8027/bin/mysqladmin -uroot -P3310 -p -h 127.0.0.1 shutdown


############################################################################################

一、配置

mysql-router 8.0+MGR单主集群

-------------------------------------

写在前面的总结:

1、MGR单主模式,不太合适,因为MGR单主模式下主库failover之后,下一个主库是投票出来的,不知道漂去哪里,VIP+keepalived的方式没用;

2、mysql-router配置文件里写的read-write的主机,只要前一个能用,后一个就不会被用(“首个可用”算法);

3、MGR单主模式下,主以外其他的机器都是read-only,一旦主机发生failover,其他的库无法通过代理写入;

4、mysql-router需要分别给写端(read-write)和读端(read-only)绑定不同的端口,可能需要应用端来做读写分离,相比之下Atlas代理则无需绑定端口;

所以,Mysql-router适合的模式应该是:普通的主从集群,多个主库互为主从且互相之间有VIP,或者传统的MHA集群等。

--------------------------------------

二、对mysql-router的一些说明:

读写分离:read-write模式:采用“首个可用”算法,优先使用第一个server,当第一个server不可达时,将会Failover到第二个server,依次进行。如果都不可达,那么请求将会被中断,且此时Router将不可用。

负载均衡:read-only模式.Mysql-router可以实现对不同的后端数据进行数据负载均衡,read-only模式将采用“轮询”算法,依次选择server新建连接,如果某个Server不可达,将会重试下一个Server,如果所有的Server都不可达,那么此端口上的请求将中断,即READ操作将不可用。同时Router将会持续与每个Server保持心跳探测,当恢复后重新加入Active列表,此后那些新建的连接请求可以分发给此Server。


三、配置与测试过程


各服务器的主机名、IP、角色分配:


mysql-router:172.30.135.119

mgr1:172.30.135.119:3310  Primary

mgr2:172.30.135.119:3311  Secondary

mgr3:172.30.135.119:3312  Secondary


1、下载安装:

xz -d mysql-router-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz 

tar xvf mysql-router-8.0.27-linux-glibc2.17-x86_64-minimal.tar 

cp -rf mysql-router-8.0.27-linux-glibc2.17-x86_64-minimal /app/mysql/app/mysql-router 


mkdir /app/mysql/app/mysql-router/conf/


2、编辑配置文件:

vi /app/mysql/app/mysql-router/conf/mysqlrouter.ini

---------

[DEFAULT]

logging_folder=/app/mysql/app/mysql-router/log

runtime_folder=/app/mysql/app/mysql-router/run

data_folder=/app/mysql/app/mysql-router/data

connect_timeout=30

read_timeout=30


[logger]

level = INFO

[routing:failover]

bind_address = 0.0.0.0

bind_port = 7001

max_connections = 1024

mode = read-write

destinations =172.30.135.119:3310 #可用的支持写操作的主库,或者主库共用的VIP,多个地址用逗号分隔


[routing:balancing]

bind_address = 0.0.0.0

bind_port = 7002 #端口7002

max_connections = 1024

mode = read-only

destinations = 172.30.135.119:3311,172.30.135.119:3312 #参与读负载均衡的从库们

---------


改一下环境变量:

echo "export PATH=$PATH:/app/mysql/app/mysql-router/bin/" >> /etc/profile

source /etc/profile

验证安装配置是否成功:

# mysqlrouter -V

MySQL Router  Ver 8.0.27 for Linux on x86_64 (MySQL Community - GPL)


chown -R mysql.mysql /app/mysql/app/mysql-router


3、启动

/app/mysql/app/mysql-router/bin/mysqlrouter -c /app/mysql/app/mysql-router/conf/mysqlrouter.ini &

netstat -ntpl|grep mysqlrouter可以看到7001和7002端口已经被使用;


# netstat -ntpl|grep mysqlrouter

tcp        0      0 0.0.0.0:7001            0.0.0.0:*               LISTEN      3107/mysqlrouter    

tcp        0      0 0.0.0.0:7002            0.0.0.0:*               LISTEN      3107/mysqlrouter  



4、登录测试及负载均衡测试:

数据库里创建账号并授权允许远程登录,此处使用rpl_user用户

注意,一定要确保账号可以远程登录。自己实验时由于root没有远程权限,试了半天才解决。


先测试写端口7001:

#  /app/mysql/app/mysql8027/bin/mysql -urpl_user -P7001 -h172.30.135.119 -prpl_pass -e "select @@hostname;select @@port" 

mysql: [Warning] Using a password on the command line interface can be insecure.

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

| @@hostname |

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

| centos84   |

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

+--------+

| @@port |

+--------+

|   3310 |

+--------+



如果有两个read-write主机的话,首先访问第一个,只有第一个故障才会访问第二个;


再测试读:

[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysql -urpl_user -P7002 -h172.30.135.119 -prpl_pass -e "select @@port"                  

mysql: [Warning] Using a password on the command line interface can be insecure.

+--------+

| @@port |

+--------+

|   3311 |

+--------+

[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysql -urpl_user -P7002 -h172.30.135.119 -prpl_pass -e "select @@port"

mysql: [Warning] Using a password on the command line interface can be insecure.

+--------+

| @@port |

+--------+

|   3312 |

+--------+

[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysql -urpl_user -P7002 -h172.30.135.119 -prpl_pass -e "select @@port"

mysql: [Warning] Using a password on the command line interface can be insecure.

+--------+

| @@port |

+--------+

|   3311 |

+--------+

[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysql -urpl_user -P7002 -h172.30.135.119 -prpl_pass -e "select @@port"

mysql: [Warning] Using a password on the command line interface can be insecure.

+--------+

| @@port |

+--------+

|   3312 |

+--------+

轮询显示3311和3312。


####################################################


主节点shutdown后重新加入集群:


[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysqladmin -uroot -P3310 -p -h 127.0.0.1 shutdown

Enter password: 

[root@centos84 app]# 

[root@centos84 app]# 

[root@centos84 app]# 

[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysqld --defaults-file=/app/mysql/data/my3310.cnf --user=mysql --datadir=/app/mysql/data/3310 --plugin-dir=/app/mysql/app/mysql8027/lib/plugin  --basedir=/app/mysql/app/mysql8027 --pid-file=/app/mysql/data/mysql3310.pid --socket=/app/mysql/data/mysql3310.sock --port=3310 &

[5] 3318

[1]   Done                    /app/mysql/app/mysql8027/bin/mysqld --defaults-file=/app/mysql/data/my3310.cnf --user=mysql --datadir=/app/mysql/data/3310 --plugin-dir=/app/mysql/app/mysql8027/lib/plugin --basedir=/app/mysql/app/mysql8027 --pid-file=/app/mysql/data/mysql3310.pid --socket=/app/mysql/data/mysql3310.sock --port=3310  (wd: /app/mysql/data/3310)

(wd now: /app/mysql/app)

[root@centos84 app]# 

[root@centos84 app]# 

[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysql -uroot -P 3310 -h127.0.0.1 -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.27 MySQL Community Server - GPL


Copyright (c) 2000, 2021, Oracle and/or its affiliates.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> 

mysql> 

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 |           |             |        NULL | OFFLINE      |             |                |                            |

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

1 row in set (0.01 sec)


mysql> reset master;

Query OK, 0 rows affected (0.01 sec)


mysql> show master status;

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

| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

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

| binlog.000001 |      152 |              |                  |                   |

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

1 row in set (0.00 sec)


mysql> clone instance from 'clone_user'@`172.30.135.119`:3311 identified by 'password';

ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement

mysql> 

mysql> 

mysql> show global variables like 'super%';

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

| Variable_name   | Value |

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

| super_read_only | ON    |

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

1 row in set (0.01 sec)


mysql> set global super_read_only=off;

Query OK, 0 rows affected (0.00 sec)


mysql> clone instance from 'clone_user'@`172.30.135.119`:3311 identified by 'password';

ERROR 3707 (HY000): Restart server failed (mysqld is not managed by supervisor process).

mysql> 

mysql> 

mysql> exit

Bye

[5]+  Done                    /app/mysql/app/mysql8027/bin/mysqld --defaults-file=/app/mysql/data/my3310.cnf --user=mysql --datadir=/app/mysql/data/3310 --plugin-dir=/app/mysql/app/mysql8027/lib/plugin --basedir=/app/mysql/app/mysql8027 --pid-file=/app/mysql/data/mysql3310.pid --socket=/app/mysql/data/mysql3310.sock --port=3310

[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysqld --defaults-file=/app/mysql/data/my3310.cnf --user=mysql --datadir=/app/mysql/data/3310 --plugin-dir=/app/mysql/app/mysql8027/lib/plugin  --basedir=/app/mysql/app/mysql8027 --pid-file=/app/mysql/data/mysql3310.pid --socket=/app/mysql/data/mysql3310.sock --port=3310 &

[5] 3425

[root@centos84 app]# 

[root@centos84 app]# /app/mysql/app/mysql8027/bin/mysql -uroot -P 3310 -h127.0.0.1 -p


Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.27 MySQL Community Server - GPL


Copyright (c) 2000, 2021, Oracle and/or its affiliates.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> 

mysql> 

mysql> show master status;

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

| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                   |

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

| binlog.000002 |      152 |              |                  | 12498f62-5be7-11ec-a94e-00163e012cf2:1-3,

aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1-12 |

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

1 row in set (0.00 sec)


mysql> start group_replication;

Query OK, 0 rows affected (10.74 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 | 12498f62-5be7-11ec-a94e-00163e012cf2 | centos84    |        3310 | ONLINE       | SECONDARY   | 8.0.27         | XCom                       |

| group_replication_applier | a8fae19c-5bea-11ec-b0f7-00163e012cf2 | centos84    |        3311 | ONLINE       | PRIMARY     | 8.0.27         | XCom                       |

| group_replication_applier | b2c1d08a-5beb-11ec-b90e-00163e012cf2 | centos84    |        3312 | ONLINE       | SECONDARY   | 8.0.27         | XCom                       |

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

3 rows in set (0.00 sec)



切换主节点:

mysql> SELECT group_replication_set_as_primary('b2c1d08a-5beb-11ec-b90e-00163e012cf2');

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

| group_replication_set_as_primary('b2c1d08a-5beb-11ec-b90e-00163e012cf2') |

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

| Primary server switched to: b2c1d08a-5beb-11ec-b90e-00163e012cf2         |

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

1 row in set (0.00 sec)


mysql> SELECT event_name, work_completed, work_estimated FROM performance_schema.events_stages_current WHERE event_name LIKE "%stage/group_rpl%";

Empty set (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 | 12498f62-5be7-11ec-a94e-00163e012cf2 | centos84    |        3310 | ONLINE       | SECONDARY   | 8.0.27         | XCom                       |

| group_replication_applier | a8fae19c-5bea-11ec-b0f7-00163e012cf2 | centos84    |        3311 | ONLINE       | SECONDARY   | 8.0.27         | XCom                       |

| group_replication_applier | b2c1d08a-5beb-11ec-b90e-00163e012cf2 | centos84    |        3312 | ONLINE       | PRIMARY     | 8.0.27         | XCom                       |

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

3 rows 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 |           |             |        NULL | OFFLINE      |             |                |                            |

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

1 row in set (0.00 sec)


mysql> 

mysql> 

mysql> 

mysql> show master status;

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

| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                                                                   |

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

| binlog.000004 |      192 |              |                  | 12498f62-5be7-11ec-a94e-00163e012cf2:1-3,

aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1-13 |

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

1 row in set (0.00 sec)


mysql> show global variables like 'super%';

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

| Variable_name   | Value |

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

| super_read_only | OFF   |

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

1 row in set (0.00 sec)


三个节点无法相互发现,gtid一致,都不是只读模式。


将其中一个节点作为主节点,执行:

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 |           |             |        NULL | OFFLINE      |             |                |                            |

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

1 row in set (0.00 sec)


mysql> 

mysql> 

mysql> 

mysql> 

mysql> 

mysql> set global group_replication_bootstrap_group=ON;

Query OK, 0 rows affected (0.00 sec)


mysql> 

mysql> start group_replication;


Query OK, 0 rows affected (1.08 sec)


mysql> 

mysql> set global group_replication_bootstrap_group=OFF;

Query OK, 0 rows affected (0.00 sec)


mysql> 

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 | 12498f62-5be7-11ec-a94e-00163e012cf2 | centos84    |        3310 | ONLINE       | PRIMARY     | 8.0.27         | XCom                       |

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

1 row in set (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, 4 warnings (0.01 sec)


mysql> start group_replication;

Query OK, 0 rows affected (1.65 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 | 12498f62-5be7-11ec-a94e-00163e012cf2 | centos84    |        3310 | ONLINE       | PRIMARY     | 8.0.27         | XCom                       |

| group_replication_applier | b2c1d08a-5beb-11ec-b90e-00163e012cf2 | centos84    |        3312 | ONLINE       | SECONDARY   | 8.0.27         | XCom                       |

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

2 rows in set (0.00 sec)


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26451536/viewspace-2847550/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2011-11-23

  • 博文量
    170
  • 访问量
    484871