一,多源复制说明
MySQL 5.7开始支持多源复制,mariadb 10 也开始支持多源复制,多远复制即一个slave可以有多个master,分别从各自的master复制不同的DB,将多个DB汇总在一台服务器上。和普通复制一样,各Master开启一个binlog dump线程通知Slave端,由Slave开启多个IO threads到各Master端上复制二进制日志并记录到本地的relay日志中,由本地的SQL thread在读取出来并在本地应用,从而实现复制功能。
二,配置安装
以下接着前面的配置进行,基于 CentOS x86_64 并使用 mariadb-10.1.11.tar.gz ,数据库安装配置可以参考MySQL主从复制原理及配置。
注:在此实验中多源复制各Master中不能有同名库,否则复制将失败。
master节点1:192.168.1.106 CentOS6.6 x86_64 master节点2:192.168.1.113 CentOS6.6 x86_64 slave 节点2:192.168.1.114 CentOS6.6 x86_64
1,配置slave节点
(1),修改从服务器配置文件:
修改server-id
#log-bin=mysql-bin #注释掉二进制日志
relay-log = relay-bin #添加relay-log
(2),创建复制账号
mysql> grant replication slave,replication client on *.* to 'repluser'@'192.168.%.%' identified by 'replpass';
(3),启动从节点的复制线程
MariaDB [(none)]> change master 'm1' to master_host='192.168.1.106',master_user='repluser',master_password='replpass'; Query OK, 0 rows affected (0.02 sec) MariaDB [(none)]> change master 'm2' to master_host='192.168.1.113',master_user='repluser',master_password='replpass'; Query OK, 0 rows affected (0.02 sec) MariaDB [(none)]> show all slaves status\G; MariaDB [(none)]> start all slaves; #启动slave
传统复制模式 — > 多源复制的命令变化:
reset slave -> reset slave ‘conn_erp’, 多个连接源名字
start slave -> start slave ‘connection_name’ 或者 start all slaves
show slave status -> show slave ‘conn_mall’ status,或者 show all slaves status查看所有的slave连接状态
2,开始验证正确性
master1执行:
mysql> create database m1db; Query OK, 1 row affected (0.00 sec) mysql> use m1db; Database changed mysql> create table t1(id int); Query OK, 0 rows affected (0.05 sec)
master2执行:
mysql> create database m2db; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> use m2db; Database changed MariaDB [m2db]> create table t2(id int); Query OK, 0 rows affected (0.23 sec)
slave节点查看:
正常工作了。看起来很简单!