三台主机系统:
[root@master ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
?
三台主机的角色:
Master: 192.168.101.222
Slave1: 192.168.101.75
Slave2: 192.168.101.79
三台数据库的版本mysql5.7.31:
启动数据库,过滤启动log找到mysql的密码并修改:
[root@slave1 ~]# systemctl start mysqld
[root@slave1 ~]# cat /var/log/mysqld.log | grep -i pass
2021-07-20T06:06:11.318957Z 1 [Note] A temporary password is generated for root@localhost: 3qFk5jTrLK-9
[root@slave1 ~]# mysqladmin -uroot -p‘3qFk5jTrLK-9‘ password 1qaz@WSX
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
Master主配置文件:
Slave1是master的从库,slave2的主库。配置文件:
Master主库授权复制权限,slave1复制master主库:
mysql> grant replication slave on *.* to rep@‘%‘ identified by ‘1qaz@WSX‘;
检查master和salve1的主从状态:
Slave1授权复制权限,配置slave2复制slave1:
mysql> grant replication slave on *.* to rep2@‘%‘ identified by ‘1qaz@WSX‘;
Query OK, 0 rows affected, 1 warning (0.06 sec)
?
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
?
mysql> change master to master_host=‘192.168.101.75‘,master_user=‘rep2‘,master_password=‘1qaz@WSX‘, master_log_file=‘mysql-bin.000002‘,master_log_pos=1024;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
?
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
查看salve1和slave2的主从状态:
测试
Master主库创建full库,查看slave1和slave2同步状态: