多通道复制
In MySQL multi-source replication, a replica opens multiple replication channels, one for each source server. The replication channels represent the path of transactions flowing from a source to the replica. Each replication channel has its own receiver (I/O) thread, one or more applier (SQL) threads, and relay log. When transactions from a source are received by a channel’s receiver thread, they are added to the channel’s relay log file and passed through to the channel’s applier threads. This enables each channel to function independently.
在MySQL多源复制中,一个副本打开多个复制通道,每个源服务器一个。复制通道表示从源流向副本的事务路径。每个复制通道都有其自己的接收器(I / O)线程,一个或多个应用程序(SQL)线程以及中继日志。通道的接收器线程接收到来自源的事务时,会将它们添加到通道的中继日志文件中,并传递到通道的应用程序线程。这样可使每个通道独立运行
启动多通道复制
在 mysql 8.0中 默认relay_log_info_repository和master_info_repository设置为table
先停掉 slave的 sql线程
STOP SLAVE SQL_THREAD;
## 设置多通道复制类型
set global slave_parallel_type=LOGICAL_CLOCK;
## 设置多通道复制个数
set gloabl slave_parallel_workers=value;
也可以写在/etc/my.cnf 中
启动 slave的 sql线程
START SLAVE SQL_THREAD;
线性复制
master->slave1->slave2
新加server3 mysql
导入数据
[root@server3 mysql]# mysql -uroot -pRedHat7.6 < ~/dump.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
####测试
访问加密
原理
实现步骤
- 1 在master上添加/etc/my.cnf
[mysqld]
ssl_ca=/data/mysql/cacert.pem
ssl_cert=/data/mysql/server-cert.pem
ssl_key=/data/mysql/server-key.pem
修改复制用户 权限
ALTER USER 'repl'@'%.example.com' REQUIRE SSL;
- 2 slave端
mysql> stop slave;
Query OK, 0 rows affected (1.54 sec)
mysql> change master to MASTER_SSL_CA='/data/mysql/ca.pem', MASTER_SSL_CERT = '/data/mysql/client-cert.pem', MASTER_SSL_KEY = '/data/mysql/client-key.pem';
Query OK, 0 rows affected (1.17 sec)
mysql> start slave;
Query OK, 0 rows affected (0.85 sec)
效果:
延迟复制
官方文档
MySQL支持延迟复制,以便副本服务器故意在比源晚至少指定时间的情况下执行事务。
默认复制延迟为0秒。使用该 CHANGE MASTER TO MASTER_DELAY=N语句将延迟设置为N秒。从源接收到的事务要至少N在其提交到直接源之后至少几秒钟才执行。延迟发生在每个事务中(不是MySQL以前的版本中的事件),实际延迟仅施加于gtid_log_event或 anonymous_gtid_log_event。事务中的其他事件始终跟随这些事件,而不会对其施加任何等待时间。
mysql> stop slave;
Query OK, 0 rows affected (0.22 sec)
mysql> CHANGE MASTER TO MASTER_DELAY=60;
Query OK, 0 rows affected (0.37 sec)
mysql> start slave;
Query OK, 0 rows affected (0.13 sec)