mysql 组全同步

全同步,都是master。

172..25.5.3 - server3 第一个组员
172.25.5.4 - server4 第二个组员
172.25.5.5 - server5 第三个组员

mysql环境配置,server端都做。

[root@server3 ~]# cd /var/lib/mysql
[root@server3 mysql]# rm -rf *
[root@server3 mysql]# vim /etc/my.cnf

添加配置文件,3个sever端id不同,address不同。

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

transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="b9e8cc0f-9c7a-11e8-ac38-52540025fd63"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="172.25.5.3:24901"
loose-group_replication_group_seeds="172.25.5.3:24901,172.25.5.4:24901,172.25.5.5:24901"
loose-group_replication_bootstrap_group=off
loose-group_replication_single_primary_mode=off
loose-group_replication_enforce_update_everywhere_checks=on
loose-group_replication_ip_whitelist="172.25.5.0/24,127.0.0.1/8"

[root@server3 mysql]# grep password /var/log/mysqld.log

找到password;

打开数据库,修改root密码。

mysql> alter user root@localhost identified by 'ssH+101010';
Query OK, 0 rows affected (0.05 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

server3配置(第一个组员的配置)。

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

mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' identified by 'ssH+101010';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> reset master;
Query OK, 0 rows affected (0.45 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='ssH+101010'  FOR CHANNEL 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.61 sec)

mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.51 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.67 sec)

mysql> SET GLOBAL group_replication_bootstrap_group=OFF;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.35 sec)

mysql> USE test;
Database changed
mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL);
Query OK, 0 rows affected (0.47 sec)

mysql> INSERT INTO t1 VALUES (1, 'Luis');
Query OK, 1 row affected (0.38 sec)

mysql> SELECT * FROM t1;
+----+------+
| c1 | c2   |
+----+------+
|  1 | Luis |
+----+------+
1 row in set (0.00 sec)

mysql> SHOW BINLOG EVENTS;

server4,server5配置;(其他组员配置)

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

mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' identified by 'ssH+101010';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> reset master;
Query OK, 0 rows affected (0.45 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='ssH+101010'  FOR CHANNEL 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.61 sec)

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

mysql> SHOW PLUGINS;


mysql> START GROUP_REPLICATION;
Query OK, 0 rows affected (6.06 sec)

基本就OK了,

查看是否同步数据库,(不要创建,直接同步server3 的test库)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t1             |
+----------------+
1 row in set (0.00 sec)

mysql> select * from t1;
+----+------+
| c1 | c2   |
+----+------+
|  1 | Luis |
+----+------+
1 row in set (0.00 sec)

全同步就OK了。

三个server端online,OK。
这里写图片描述

检测:

server4插入
这里写图片描述

server3检测
这里写图片描述

server5插入:
这里写图片描述

server3检测
这里写图片描述

扫描二维码关注公众号,回复: 2694037 查看本文章

server3插入
这里写图片描述

server4检测
这里写图片描述

全同步OK。

猜你喜欢

转载自blog.csdn.net/su_use/article/details/81567502