一 简介 :MGR一直没有时间测试,今天咱们来初步了解搭建一下呗
二 环境: mysql5.7.20 单台机器 启动三实例
三 mysql 搭建:
1 建立相关目录+
mkdir -p /data/mysql/data_3306
mkdir -p /data/mysql/data_3307
mkdir -p /data/mysql/data_3308
2 脚本初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data_3306
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data_3307
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data_3308
3 修改密码
mysql -uroot -S /tmp/mysql_3306.sock -e "set password for ‘root‘@‘localhost‘ = password(‘test‘);"
mysql -uroot -ptest -S /tmp/mysql_3306.sock -e "flush privileges"
mysql -uroot -S /tmp/mysql_3307.sock -e "set password for ‘root‘@‘localhost‘ = password(‘test‘);"
mysql -uroot -ptest -S /tmp/mysql_3307.sock -e "flush privileges"
mysql -uroot -S /tmp/mysql_3308.sock -e "set password for ‘root‘@‘localhost‘ = password(‘test‘);"
mysql -uroot -ptest -S /tmp/mysql_3308.sock -e "flush privileges"
4 启动命令
nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my_3306.cnf &
nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my_3307.cnf &
nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my_3308.cnf &
四 MGR配置
1 配置文件添加
gtid_mode = ON
enforce_gtid_consistency = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
binlog_checksum = NONE
log_slave_updates = ON
transaction_write_set_extraction = XXHASH64
loose-group_replication_group_name="01e5fb97-be64-41f7-bafd-3afc7a6ab555"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="127.0.0.1:13306"//除了此处不同 其他都相同
loose-group_replication_group_seeds="127.0.0.1:13306,127.0.0.1:13307,127.0.0.1:13308"
loose-group_replication_bootstrap_group = off
2 重启服务,分别创建复制账户
set sql_log_bin=0;
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO ‘repl‘@‘%‘ IDENTIFIED BY ‘repl‘;
flush privileges;
set sql_log_bin=1;
3 主节点执行
change master to master_user=‘repl‘,master_password=‘repl‘ for channel ‘group_replication_recovery‘;
install plugin group_replication soname ‘group_replication.so‘;
set global group_replication_bootstrap_group=ON;
START group_replication;
set global group_replication_bootstrap_group=OFF;
4 从节点执行
change master to master_user=‘repl‘,master_password=‘repl‘ for channel ‘group_replication_recovery‘;
install plugin group_replication soname ‘group_replication.so‘;
START group_replication;
5 查看状态
select * from performance_schema.replication_group_members;
三个成员均为online 则代表搭建成功
6 查看主成员
1 select variable_value from performance_schema.global_status where variable_name =‘group_replication_primary_member‘; 获取主UUID
2 select * from performance_schema.replication_group_members; 根据UUID确定primary
7 测试
1 建立一个拥有主键的表并插入数据(MGR架构下表必须拥有主键)
2 查看其他节点是否拥有数据
五 说明
这篇文章是单主的MGR的第一次尝试,以后会继续补充