部署M-S-S模型
环境介绍:
Master MySQL 5.7.20 192.168.1.63
Slave中继 MySQL 5.7.20 192.168.1.64
Slave MysQL 5.7.20 192.168.1.65
部署Master-->xuegod63:
在主服务上创建一个用户,并授予replication slave权限:
[root@xuegod63 ~]# mysql -hlocalhost -uroot -p
mysql> grant replication slave,replication client on *.* to repl@'192.168.1.64' identified by '123456';
flush privileges;
show master status;
[root@xuegod63 ~]# vim /etc/my.cnf
server_id=1
log_bin=mysql-bin
log_bin_index=mysql-bin.index
binlog_format=row
binlog_do_db=HA
binlog_ignore_db=mysql
sync_binlog=1
重启服务
[root@xuegod63 ~]# systemctl restart mysqld
导出主服务器HA库完整备份, 拷贝到 中继服务器 和slave服务器
[root@xuegod63 ~]# mysqldump -hlocalhost -uroot -p123456 -B HA > ha.sql
[root@xuegod63 ~]# scp ha.sql 192.168.1.64:/root
[root@xuegod63 ~]# scp ha.sql 192.168.1.65:/root
部署slave中继-->xuegod64
导入数据库ha.sql
[root@xuegod64 ~]# mysql -hlocalhost -uroot -p123456 <ha.sql
配置my.cnf
[root@xuegod64 ~]# vim /etc/my.cnf
server_id=2
log_bin=mysql-bin
log_bin_index=mysql-bin.index
relay_bin=relay-bin
relay_bin_index=relay-bin.index
binlog_format=row
log-slave-updates=1 #把它从relay-log当中读取出来的二进制日志并且这本机上执行的操作也记录这自己的二进制日志里面,这样才能使第三台slave通过中继slave读取到相应数据变化
重启服务
[root@xuegod64 ~]# systemctl restart mysqld
指定中继Slave的主服务器
mysql> stop slave;
change master to master_host='192.168.1.63',master_user='repl',master_password='123456';
start slave;
查看中继服务的状态
mysql> show slave status \G
在中继Slave1上创建一个用户,并授予replication slave权限
mysql> grant replication slave,replication client on *.* to 'repl'@'192.168.1.65' identified by '123456';
mysql> flush privileges;
部署Slave2-->xuegod65
导入数据库ha.sql
[root@xuegod65 ~]# mysql -hlocalhost -uuroot -p123456 <ha.sql
配置my.cnf
vim /etc/my.cnf
server_id=3
log_bin=mysql-bin
log_bin_index=mysql-bin.index
relay_bin=relay-bin
relay_bin_index=relay-bin.index
binlog_format=row
[root@xuegod65 ~]# systemctl restart mysqld
指定Slave1中继服务作为xuegod65的主:
mysql> stop slave;
change master to master_host='192.168.1.64',master_user='repl',master_password='123456';
start slave;
查看从服务的状态
mysql> show slave status \G
从Master上插入数据测试:
mysql> create database HA;
mysql> use HA;
mysql> create table T1(id int,name varchar(40));
mysql> insert into test values (1,'AA');
然后分别在Slave1中继,与Alave2上查看
为什么中继服务器也查到数据呢? 因为是存储引擎的问题。
修改表的引擎:
mysql> alter table t1 ENGINE=blackhole; (先关闭日志记录再修改set sql_log_bin=off)
链接:http://blog.itpub.net/31485142/viewspace-2157329/
https://blog.csdn.net/weixin_45894245/article/details/108233507