mysql 架构~多写模式MGR

一  简介:今天咱们来聊聊MGR的单主切换和新节点加入
二 单主模式下变成多主:
  1 3306
  STOP group_replication;
  set global group_replication_single_primary_mode=OFF; //关闭单主模式
  set global group_replication_enforce_update_everywhere_checks= ON;//打开多主模式
  set global group_replication_bootstrap_group=ON;
  START group_replication;
  set global group_replication_bootstrap_group=OFF;
 2 3307 3308
  STOP group_replication;
  set global group_replication_single_primary_mode=OFF;//关闭单主
  set global group_replication_enforce_update_everywhere_checks= ON;//打开多主
  START group_replication;

3 进行测试
3306 3307 分别建立库 查看其他实例
证明成功

4 从库恢复

STOP group_replication;
set global group_replication_enforce_update_everywhere_checks= off;
set global group_replication_single_primary_mode=on;
START group_replication;

三 如何添加节点(少数据量情况下)

 1 初始化节点
  /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data_3309
2 启动节点并修改密码
 nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my_3309.cnf &
 mysql -uroot -S /tmp/mysql_3309.sock -e "set password for 'root'@'localhost' = password('test');"
 mysql -uroot -ptest -S /tmp/mysql_3309.sock -e "flush privileges"
3 创建用户
set sql_log_bin=0;
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl';
flush privileges;
set sql_log_bin=1;
4 加入
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_single_primary_mode=OFF;//关闭单主
set global group_replication_enforce_update_everywhere_checks= ON;//打开多主
set global group_replication_allow_local_disjoint_gtids_join=1;//这里要注意 一定要执行这步 否则会加入失败
START group_replication;

四 总结:

 1 推荐单主模式,多主只是为了测试功能性

 2 如果大量数据情况下,要采用备份恢复方式,不建议从头追加,一旦binlog丢失,成员将会有问题 

     

转载于:https://www.cnblogs.com/danhuangpai/p/8144965.html

你可能感兴趣的:(mysql 架构~多写模式MGR)