mysql的組複製

1.配置server1

1.關閉server1的mysqld並刪除數據,查看uuid

[root@server1 mysql]# systemctl stop mysqld
[root@server1 mysql]# rm -fr  *
[root@server1 mysql]# cat auto.cnf 
[auto]
server-uuid=ad3a5dd5-b76f-11e9-bb9b-5254004772f0

在這裏插入圖片描述2.編輯mysql配置文件,並重啓數據庫

[root@server1 mysql]# vim /etc/my.cnf
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW

transaction_write_set_extraction=XXHASH64		##指示server必須爲每個事務收集寫集合,並使用XXHASH64哈希算法將其編碼爲散列
loose-group_replication_group_name="3f7d3133-b4fb-11e9-a23a-52540039676f"		##告知插件,正在加入或創建的組要命名
loose-group_replication_start_on_boot=off		##指示插件在server啓動時不自動啓動組複製
loose-group_replication_local_address= "172.25.16.1:33061"		##告訴插件使用IP地址本地主機,端口33061用於接收來自組中其他成員的傳入連接
loose-group_replication_group_seeds= "172.25.16.1:33061,172.25.16.2:33061,172.25.16.3:33061"
loose-group_replication_bootstrap_group=off		##配置是否自動引導組
loose-group_replication_ip_whitelist="127.0.0.1,172.25.16.0/24"		##用戶白名單
		loose-group_replication_enforce_update_everywhere_checks=ON			##多主模式下爲多主更新啓用或禁用嚴格一致性檢查	
loose-group_replication_single_primary_mode=OFF		##設置組自動選擇一個server來處理讀/寫工作

[root@server1 mysql]# systemctl start mysqld
[root@server1 mysql]# systemctl restart mysqld

在這裏插入圖片描述
在這裏插入圖片描述3.獲取初始密碼,並登陸數據庫修改密碼

[root@server1 mysql]# cat /var/log/mysql.log | grep password
2019-08-05T10:56:28.716457Z 1 [Note] A temporary password is generated for root@localhost: QllupXywe3;b
[root@server1 mysql]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-log

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> alter user root@localhost identified by 'Szy+123en';

在這裏插入圖片描述4.在server1上啓動組複製

mysql> show databases;  
mysql> SET SQL_LOG_BIN=0;	#禁用二進制日至
mysql> CREATE USER rpl_user@'%' IDENTIFIED BY 'Bgg+2019';	#創建用戶
mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';	#加用戶權限
mysql> FLUSH PRIVILEGES;	#刷新數據
mysql> SET SQL_LOG_BIN=1;	#啓用二進制日至
mysql> CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='Szy+123en' FOR CHANNEL 'group_replication_recovery';	#當配置了用戶,使用CHANGE MASTER TO語句將服務器爲下一次需要從其他成員恢復狀態時使SET SQL_LOG_BIN=0;用group_replication_recovery複製通道的給定憑證,發出以下命令,用創建用戶時直接使用的值替換rpl_user和密碼
mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';	#安裝組插件
mysql> SHOW PLUGINS; 
mysql> SET GLOBAL group_replication_bootstrap_group=ON;		#master上要先打開,等打開組複製之後再開啓(slave上不用進行)
mysql> START GROUP_REPLICATION; #打開組複製
mysql>  SET GLOBAL group_replication_bootstrap_group=OFF;  

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述5.在server1上創建表,便於測試

mysql> create database test;
Query OK, 1 row affected (0.02 sec)

mysql> use test;
Database changed
mysql> create table class (name int primary key,grades text not null);
Query OK, 0 rows affected (0.06 sec)
mysql> insert into class values (1,'tom');
Query OK, 1 row affected (0.02 sec)

mysql> select * from class
    -> ;
+------+--------+
| name | grades |
+------+--------+
|    1 | tom    |
+------+--------+
1 row in set (0.00 sec)

6.查看server1是否加入組複製羣組

mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | ad3a5dd5-b76f-11e9-bb9b-5254004772f0 | server1     |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
1 row in set (0.00 sec)

2.配置server2

1.清空數據庫數據

[root@server2 ~]# systemctl stop mysqld
[root@server2 ~]# cd /var/lib/mysql
[root@server2 mysql]# ls
[root@server2 mysql]# rm -rf *

2.修改數據庫配置文件

[root@server2 ~]# vim /etc/my.cnf
enforce-gtid-consistency=true
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="3f7d3133-b4fb-11e9-a23a-52540039676f"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "172.25.16.2:33061"
loose-group_replication_group_seeds= "172.25.16.1:33061,172.25.16.2:33061,172.25.16.3:33061"
loose-group_replication_bootstrap_group=off
loose-group_replication_ip_whitelist="127.0.0.1,172.25.16.0/24"
loose-group_replication_enforce_update_everywhere_checks=ON
loose-group_replication_single_primary_mode=OFF

[root@server2 ~]# systemctl start  mysqld

在這裏插入圖片描述3.獲取臨時密碼,進入數據庫修改密碼

[root@server2 mysql]# cat /var/log/mysqld.log | grep password
2019-08-05T11:51:03.681848Z 1 [Note] A temporary password is generated for root@localhost: >NuN6,w2sEq(
[root@server2 mysql]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-log

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> alter user root@localhost identified by 'Szy+123en';
Query OK, 0 rows affected (0.02 sec)

4.啓動server2的組複製

mysql> SET SQL_LOG_BIN=0;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE USER rpl_user@'%' IDENTIFIED BY 'Szy+123en';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
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> CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='Szy+123en' FOR CHANNE
Query OK, 0 rows affected, 2 warnings (0.09 sec)

mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.24 sec)

mysql> set global group_replication_allow_local_disjoint_gtids_join=on;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> START GROUP_REPLICATION;
Query OK, 0 rows affected, 1 warning (5.90 sec)

測試:在server1上查看server2是否加入組複製羣組,是否在線

mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 4d41bf26-b777-11e9-aa93-52540039676f | server2     |        3306 | ONLINE       |
| group_replication_applier | ad3a5dd5-b76f-11e9-bb9b-5254004772f0 | server1     |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
2 rows in set (0.00 sec)

在這裏插入圖片描述
在server1的class表插入的數據,看server2是否同步成功
在這裏插入圖片描述

3.配置server3

1.將server2的安裝包傳給server3
在這裏插入圖片描述2.安裝所有包
在這裏插入圖片描述3.編輯mysql配置文件

[root@server3 ~]# vim /etc/my.cnf
server-id=3
gtid_mode=ON
enforce-gtid-consistency=true
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="3f7d3133-b4fb-11e9-a23a-52540039676f"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "172.25.16.3:33061"

[root@server3 ~]# systemctl start mysqld

在這裏插入圖片描述

4.獲取臨時密碼,進入數據庫並修改密碼

[root@server3 ~]# cat /var/log/mysqld.log | grep password
2019-08-05T12:29:43.983430Z 1 [Note] A temporary password is generated for root@localhost: bcj(gD>Uk6oF
[root@server3 ~]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-log

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> alter user root@localhost identified by 'Szy+123en';
Query OK, 0 rows affected (0.02 sec)

5.在server3開啓組複製

mysql> SET SQL_LOG_BIN=0;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE USER rpl_user@'%' IDENTIFIED BY 'Szy+123en';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
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> CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='Szy+123en' FOR CHANNEL 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.08 sec)

mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.20 sec)

mysql> set global group_replication_allow_local_disjoint_gtids_join=on;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> START GROUP_REPLICATION;
Query OK, 0 rows affected, 1 warning (3.50 sec)

測試:
在server1上查看server3是否加入,並在線

mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 4d41bf26-b777-11e9-aa93-52540039676f | server2     |        3306 | ONLINE       |
| group_replication_applier | ad3a5dd5-b76f-11e9-bb9b-5254004772f0 | server1     |        3306 | ONLINE       |
| group_replication_applier | b4443ef0-b77c-11e9-98b7-52540046c65d | server3     |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.08 sec)

server3是否能夠查看class表裏的數據
在這裏插入圖片描述

在server3的class表裏添加信息
在這裏插入圖片描述
server2和server1可以查看到添加的信息
在這裏插入圖片描述在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章