节点信息:
10.32.3.41
10.32.3.42
10.32.3.43
安装mysql
1、安装新版mysql之前,我们需要将系统自带的mariadb-lib卸载
[root@bogon ~]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@bogon ~]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
修改主机名
hostnamectl set-hostname mgr-multi01
hostnamectl set-hostname mgr-multi02
hostnamectl set-hostname mgr-multi03
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
在/etc/hosts文件中添加三个节点的信息
vim /etc/hosts
10.32.3.41 mgr-multi01
10.32.3.42 mgr-multi02
10.32.3.43 mgr-multi03
安装mysql
解压mysql安装包
[root@mgr01 home]# mkdir mysql
[root@mgr01 home]# tar -xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar -C mysql
[root@mgr-multi01 yum.repos.d]# rpm -qa |grep mysql
mysql-community-libs-5.7.22-1.el7.x86_64
mysql-community-common-5.7.22-1.el7.x86_64
mysql-community-libs-compat-5.7.22-1.el7.x86_64
[root@mgr-multi01 yum.repos.d]# rpm -e --nodeps mysql-community-libs-5.7.22-1.el7.x86_64
[root@mgr-multi01 yum.repos.d]# rpm -e --nodeps mysql-community-common-5.7.22-1.el7.x86_64
[root@mgr-multi01 yum.repos.d]# rpm -e --nodeps mysql-community-libs-compat-5.7.22-1.el7.x86_64
安装mysql软件
[root@mgr01 mysql]# rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm
[root@mgr01 mysql]# rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm
[root@mgr01 mysql]# rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm
[root@mgr01 mysql]# rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.23-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libsasl2.so.2()(64bit) is needed by mysql-community-server-5.7.23-1.el7.x86_64
解决办法: rpm -ivh mysql-community-server-5.7.23-1.el6.x86_64.rpm --nodeps --force
初始化mysql,修改root用户的登陆密码
mysqld --initialize --user=mysql
service mysqld start
grep 'temporary password' /var/log/mysqld.log
mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> flush privileges;
搭建mgr-multi
[root@mgr-multi01 lib]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#Group Replication
server_id = 41
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="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot = off
loose-group_replication_local_address = '10.32.3.41:33061'
loose-group_replication_group_seeds ='10.32.3.41:33061,10.32.3.42:33062,10.32.3.43:33063'
loose-group_replication_bootstrap_group = off
loose-group_replication_single_primary_mode = off
loose-group_replication_enforce_update_everywhere_checks = on
service mysqld restart
set SQL_LOG_BIN=0;
mysql> create user repl@'%' identified by '123456';
mysql> grant replication slave on *.* to repl@'%';
set SQL_LOG_BIN=1;
change master to master_user='repl',master_password='123456' for channel 'group_replication_recovery';
install PLUGIN group_replication SONAME 'group_replication.so';
mysql> CHANGE MASTER TO MASTER_USER='rppl', MASTER_PASSWORD='123456' FOR CHANNEL 'group_replication_recovery';
Query OK, 0 rows affected, 2 warnings (0.02 sec)
mysql>
mysql> install PLUGIN group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.00 sec)
mysql> show plugins;
set global group_replication_bootstrap_group=ON;
start group_replication;
set global group_replication_bootstrap_group=OFF;
select * from performance_schema.replication_group_members;
mysql> select * from performance_schema.replication_group_members;
配置另外两台服务器
[root@mgr-multi02 mysql]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#Group Replication
server_id = 42
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="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot = off
loose-group_replication_local_address = '10.32.3.42:33061'
loose-group_replication_group_seeds ='10.32.3.41:33061,10.32.3.42:33062,10.32.3.43:33063'
loose-group_replication_bootstrap_group = off
loose-group_replication_single_primary_mode = off
loose-group_replication_enforce_update_everywhere_checks = on
service mysqld restart
mysql> set SQL_LOG_BIN=0;
mysql> create user repl@'%' identified by '123456';
mysql> grant replication slave on *.* to repl@'%';
mysql> flush privileges;
mysql> SET SQL_LOG_BIN=1;
mysql> change master to master_user='repl',master_password='123456' for channel 'group_replication_recovery';
-- 安装group replication插件
mysql> install PLUGIN group_replication SONAME 'group_replication.so';
把实例添回到之前的复制组
mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;
mysql> start group_replication;
在mgr-multi02上查看复制组状态
mysql> select * from performance_schema.replication_group_members;
测试:
测试服务器mgr-multi01上的mysql
mysql> create database test;
mysql> use test;
mysql> create table t1(c1 int primary key, c2 text not null);
mysql> insert into t1 values (1, 'Luis');
mysql> select * from t1;
mysql> show binlog events;
测试服务器mgr-multi02上的mysql
mysql> create database test2;
mysql> use test2;
mysql> create table t3(b1 int primary key, b2 text not null);
mysql> insert into t3 values (1, 'kate');
mysql> select * from t3;
mysql> show binlog events;
测试服务器mgr-multi03上的mysql
mysql> create database test1;
mysql> use test1;
mysql> create table t2(d1 int primary key, d2 text not null);
mysql> insert into t2 values (1, 'mary');
mysql> select * from t2;
mysql> show binlog events;
无论部署模式如何,组复制都不处理客户端故障转移,必须由应用程序本身,连接器或中间件框架(如代理或路由器)处理。
在多主模式下部署时,会检查语句以确保它们与模式兼容。在多主模式下部署组复制时,将进行以下检查:
如果事务在SERIALIZABLE隔离级别下执行,则在与组同步时其提交失败。
如果事务针对具有级联约束的外键的表执行,则在与组同步时事务无法提交。
本节介绍提供有关组复制信息的状态变量。该变量具有以下含义:
group_replication_primary_member
当组以单主模式运行时,显示主要成员的UUID。如果该组在多主模式下运行,则显示空字符串。