主机名 |
Ip |
角色 |
mysql1 |
10.188.34.10 |
主 |
mysql2 |
10.188.34.9 |
备 |
mysql3 |
10.188.34.11 |
备 |
修改host文件(和主机名一致)按实际IP和主键名修改
vi /etc/hosts
10.188.34.10 mysql1
10.188.34.9 mysql2
10.188.34.11 mysql3
准备
要等到业务不再使用,进行备份复制,保持数据一致
备份
msyqldump -u root -pmysql8.0.com --skip-add-drop-table --set-gtid-purged=OFF --routines --single_transaction --master-data=2 --all-databases -S /data/mysql/tmp/mysqld.sock > /data/all_back.sql
将主库备份的数据传到备库
scp all_databases.sql [email protected]:/xx/ 从库IP
复制(从库)
登录 mysql -u root -pmysql8.0.com source /xx/all_databases.sql
编辑配置文件
主库
server_id = 1 enforce_gtid_consistency = ON gtid_mode = ON binlog_checksum = none default_authentication_plugin = mysql_native_password plugin_dir = /usr/local/mysql/lib/plugin log_slave_updates = ON binlog_format = ROW master_info_repository = TABLE relay_log_info_repository = TABLE transaction_write_set_extraction = XXHASH64 loose-group_replication_recovery_use_ssl = ON loose-group_replication_group_name = "aadaaaaa-adda-adda-aaaa-aaaaaaddaaaa" loose-group_replication_start_on_boot = OFF loose-group_replication_local_address = "mysql1:33061" loose-group_replication_group_seeds = "mysql1:33061,mysql2:33062,mysql3:33063" loose-group_replication_bootstrap_group = OFF
从库1
server_id = 2 enforce_gtid_consistency = ON gtid_mode = ON binlog_checksum = none default_authentication_plugin = mysql_native_password plugin_dir = /usr/local/mysql/lib/plugin log_slave_updates = ON binlog_format = ROW master_info_repository = TABLE relay_log_info_repository = TABLE transaction_write_set_extraction = XXHASH64 loose-group_replication_recovery_get_public_key = ON loose-group_replication_recovery_use_ssl = ON loose-group_replication_group_name = "aadaaaaa-adda-adda-aaaa-aaaaaaddaaaa" loose-group_replication_start_on_boot = OFF loose-group_replication_local_address = "mysql2:33062" loose-group_replication_group_seeds = "mysql1:33061,mysql2:33062,mysql3:33063" loose-group_replication_bootstrap_group = OFF
从库2
server_id = 3 enforce_gtid_consistency = ON gtid_mode = ON binlog_checksum = none default_authentication_plugin = mysql_native_password plugin_dir = /usr/local/mysql/lib/plugin log_slave_updates = ON binlog_format = ROW master_info_repository = TABLE relay_log_info_repository = TABLE transaction_write_set_extraction = XXHASH64 loose-group_replication_recovery_get_public_key = ON loose-group_replication_recovery_use_ssl = ON loose-group_replication_group_name = "aadaaaaa-adda-adda-aaaa-aaaaaaddaaaa" loose-group_replication_start_on_boot = OFF loose-group_replication_local_address = "mysql3:33063" loose-group_replication_group_seeds = "mysql1:33061,mysql2:33062,mysql3:33063" loose-group_replication_bootstrap_group = OFF
之后重启数据库
mysqld_safe --defaults-file=/data/mysql/conf/my.cnf-old &
修改 auto.cnf
su - mysql cd $MYSQL_DATA_HOME/data/ mv auto.cnf auto.cnf.bk
主从节点创建账号
mysql> SET SQL_LOG_BIN=0; mysql> CREATE USER mgruser@'%' IDENTIFIED BY 'rootROOT@123'; mysql> GRANT REPLICATION SLAVE ON *.* TO mgruser@'%'; mysql> FLUSH PRIVILEGES; mysql> SET SQL_LOG_BIN=1; mysql> CHANGE MASTER TO MASTER_USER='mgruser', MASTER_PASSWORD='rootROOT@123' FOR CHANNEL 'group_replication_recovery'; grant all privileges on *.* to mgruser@"%" ;
主从节点安装组插件
install PLUGIN group_replication SONAME 'group_replication.so'; show plugins;
主从库都要执行(gtid一致)
reset master CHANGE MASTER TO MASTER_USER='mgruser', MASTER_PASSWORD='rootROOT@123' FOR CHANNEL 'group_replication_recovery';
主库开启
SET GLOBAL group_replication_bootstrap_group=ON; START GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=OFF; SELECT * FROM performance_schema.replication_group_members;
从库
START GROUP_REPLICATION;
查看
SELECT * FROM performance_schema.replication_group_members;
异常
分析原因 主备 uuid 一致导致搭建失败,了解到虚拟机是克隆过来的,克隆完之后所有的文件都是一样的,包括IP地址、mac地址、uuid等。导致mysql的uuid一样
克隆的虚拟机导致mysql主从UUID一致怎么修改_克隆虚拟机uuid一样怎么办_WuYle的博客-CSDN博客
解决
登录数据库
select uuid()
将结果值,添加到配置文件,之后重启数据库
保持 gtid 一致
reset master CHANGE MASTER TO MASTER_USER='mgruser', MASTER_PASSWORD='rootROOT@123' FOR CHANNEL 'group_replication_recovery';
开启组关系
START GROUP_REPLICATION;