环境:centos-6.5      Mariadb:10.1.13-MariaDB

多源复制:企业数据库中写的需求较大,以至于I/O负载比较大,那么就必须把写的操作分摊到多台主服务器上进行,然后在将主服务器上的数据汇总到从服务器上去进行数据分析。或者是将异地数据库的数据汇总到一起。注意:每台主服务上的库是不能相同的。

  proxy-mysql:192.168.88.139

  master1:192.168.88.147

  master2:192.168.88.148

  slave1:192.168.88.149

  slave2:192.168.88.150

一、1.编辑master1的配置文件:

 编辑/etc/my.cnf,修改如下两行:
[root@www ~]# vim /etc/my.cnf
log-bin = /mylogs/mysql-bin    #二进制日志存放位置
server-id = 10            #mysql服务器id,同一集群里的所有server-id都不能相同

  2.创建二进制日志目录,并重启:

 [root@www ~]# mkdir /mylogs
2 [root@www ~]# chown mysql.mysql -R /mylogs
3 [root@www ~]# service mysqld restart

  3.连接mysql服务器,进行复制用户授权:

 MariaDB [(none)]>  grant replication slave,replication client on *.* to 'daixiang'@'192.168.88.%' identified by 'daixiang';    #在生产环境,为了安全起见,千万记住要指定单台被授权的主机

2 MariaDB [(none)]>  flush privileges;

二、1.编辑master2的配置文件:

1 编辑/etc/my.cnf,修改如下两行:
2 [root@www ~]# vim /etc/my.cnf
3 log-bin = /mylogs/mysql-bin    #二进制日志存放位置
4 server-id = 20            #mysql服务器id,同一集群里的所有server-id都不能相同
5
6

  2.创建二进制日志目录,并重启:

1 [root@www ~]# mkdir /mylogs
2 [root@www ~]# chown mysql.mysql -R /mylogs
3 [root@www ~]# service mysqld restart

 

  3.连接mysql服务器,进行复制用户授权:

1 MariaDB [(none)]>  grant replication slave,replication client on *.* to 'daixiang'@'192.168.88.%' identified by 'daixiang';
2 MariaDB [(none)]> flush privileges;

三、1.编辑slave1配置文件并重启mysql:

 编辑/etc /my.cnf修改如下几行:
[root@www ~]# vim /etc/my.cnf
server-id =
relay-log = relay-mysql #启用中继日志
#log-bin=mysql-bin #不启用二进制日志 6 [root@www ~]# service mysqld restart 

  2.连接slave1,分别指定master1和master2的位置,并启动I/O_thread和SQL_thread:

 MariaDB [(none)]> change master 'm1' to MASTER_HOST='192.168.88.147',MASTER_USER='daixiang',MASTER_PASSWORD='daixiang';
MariaDB [(none)]> change master 'm2' to MASTER_HOST='192.168.88.148',MASTER_USER='daixiang',MASTER_PASSWORD='daixiang'; #分别指定主服务器并设置别名为m1和m2
3 MariaDB [(none)]> start all slaves; 4 MariaDB [(none)]> help change master to; #查看change master to命令用法

  3.查看从服务器slave1的状态:

MariaDB [(none)]> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.88.147
Master_User: daixiang
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-mysql.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes     #表示I/O_thread启动成功
Slave_SQL_Running: Yes        #表示SQL_thread启动成功
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:     #如果此处出现错误提示,一般情况是需要指定主服务器上position:下面有详细解释
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
row in set (0.00 sec) #注意:如果上面启动复制线程和执行中继日志语句线程时,使用show all slaves status\G时,出现错误提示;一般情况是因为初始化数据库时,主从服务器上的库是相同的,而从服务器是从最开始的位置同步主服务器上的二进制日志进自己中继日志并执行,那么从服务器上原本就已经有了系统库,如果在执行一遍中继日志那么就会产生冲突,所以必须要指定position,我使用的是Mariadb:10.1.13-MariaDB,很幸运,没出现此错误:
  解决方法:1.切换到主服务器上查看其状态:
MariaDB [mage]> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin. | | | |
+------------------+----------+--------------+------------------+
row in set (0.00 sec) 2.在到从服务器上执行下面语句:
MariaDB [(none)]> STOP ALL SLAVES;
MariaDB [(none)]> change master 'm1' to MASTER_HOST='192.168.88.147',MASTER_USER='daixiang',MASTER_PASSWORD='daixiang',MASTER_LOG_FILE='mysql-bin.000005',MASTER_LOG_POS=721;
MariaDB [(none)]> START ALL SLAVES;
  

四、1.编辑slave2配置文件并重启mysql:

1 编辑/etc /my.cnf修改如下几行:
2 [root@www ~]# vim /etc/my.cnf
3 server-id = 40
4 relay-log = relay-mysql #启用中继日志
5 #log-bin=mysql-bin #不启用二进制日志 6 [root@www ~]# service mysqld restart

  

  2.连接slave1,分别指定master1和master2的位置,并启动I/O_thread和SQL_thread:

1 MariaDB [(none)]> change master 'm1' to MASTER_HOST='192.168.88.147',MASTER_USER='daixiang',MASTER_PASSWORD='daixiang';
2 MariaDB [(none)]> change master 'm2' to MASTER_HOST='192.168.88.148',MASTER_USER='daixiang',MASTER_PASSWORD='daixiang';
3 MariaDB [(none)]> start all slaves; MariaDB [(none)]> help change master to; #查看change master to命令用法

  3.查看从服务器slave2的状态:

MariaDB [(none)]> show all slaves status\G
*************************** . row ***************************
Connection_name: m1
Slave_SQL_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.88.147 #master1的地址
Master_User: daixiang
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysql-relay-m1.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes #已启动I/O_thread线程
Slave_SQL_Running: Yes                #已启动SQL_thread线程
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
Retried_transactions:
Max_relay_log_size:
Executed_log_entries:
Slave_received_heartbeats:
Slave_heartbeat_period: 1800.000
Gtid_Slave_Pos: --
*************************** . row ***************************
Connection_name: m2
Slave_SQL_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.88.148 #master2的地址
Master_User: daixiang
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysql-relay-m2.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
Retried_transactions:
Max_relay_log_size:
Executed_log_entries:
Slave_received_heartbeats:
Slave_heartbeat_period: 1800.000
Gtid_Slave_Pos: --
rows in set (0.00 sec)

五、验证:

  1.在master1上创建一个库dxdb ,在dxdb库里面创建表daixiang,并在里面插入一些数据:

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| dxdb |
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.05 sec) MariaDB [(none)]> use dxdb
Database changed
MariaDB [dxdb]> show tables;
+----------------+
| Tables_in_dxdb |
+----------------+
| daixiang |
+----------------+
row in set (0.00 sec)

MariaDB [dxdb]> select * from daixiang;
  +------+
  | name |
  +------+
  | tom |
  | jeck |
  +------+
  2 rows in set (0.01 sec)

  2.在master2上创建一个库mage_db,在mage_db库里面创建表mage_tb,并在里面插入一些数据:

MariaDB [mage]> show databases;
+------------------------+
| Database |
+------------------------+
| information_schema |
| mage_db |
| mysql |
| performance_schema |
| test |
+------------------------+
rows in set (0.00 sec)

  3.在slave1上验证是否已经成功汇总:

MariaDB [mage]> show databases;
+--------------------+
| Database |
+--------------------+
| dxdb |
| information_schema |
| mage_db |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec)

  4.在slave2上验证是否已经成功汇总:

MariaDB [mage]> show databases;
+--------------------+
| Database |
+--------------------+
| dxdb |
| information_schema |
| mage |
| mysql |
| performance_schema |
| test |
+--------------------+
rows in set (0.00 sec)

  

mariadb多源复制 muiltil source replication的更多相关文章

  1. MariaDB多源复制环境搭建(多主一丛)

    环境: 192.168.1.248 HE1 主库 192.168.1.249 HE2 主库 192.168.1.250 HE3 从库 主库授权备份账户 mysql>  grant SELECT, ...

  2. MySQL 多源复制(Mulit-Source Replication)

    MySQL多源复制方案        看复制源Master_1的同步状态:SHOW SLAVE STATUS FOR CHANNEL 'Master_1'\G 查看复制源Master_2的同步状态:S ...

  3. mariadb 10 多源复制(Multi-source replication) 业务使用场景分析,及使用方法

    mariadb 10 多源复制(Multi-source replication) 业务使用场景分析,及使用方法 官方mysql一个slave只能对应一个master,mariadb 10开始支持多源 ...

  4. MariaDB的GTID复制和多源复制

    什么是GTID? GTID就是全局事务ID(global transaction identifier ),最初由google实现,官方MySQL在5.6才加入该功能.GTID实际上是由UUID+TI ...

  5. mariadb multi-source replication(mariadb多主复制)

    下文一起来看看mariadb multi-source replication(mariadb多主复制)例子,希望对各位有帮助.   mariadb multi-source replication( ...

  6. 初试mysql5.7.2新特性:多源复制(MySQL 5.7 multi-source replication)

    多源复制和多主复制的区别: 多主复制示意图: 多源复制示意图: 在my.cnf中添加crash safe特性参数:master_info_repository=TABLE;relay_log_info ...

  7. mysql5.7 安装和多源复制实践

    MySQL 5.7发布后,在复制方面有了很大的改进和提升.比如开始支持多源复制(multi-source)以及真正的支持多线程复制了.多源复制可以使用基于二进制日子的复制或者基于事务的复制.下面我们说 ...

  8. MySQL多源复制(八)

    一.什么是多源复制 MySQL 5.7发布后,在复制方面有了很大的改进和提升.比如开始支持多源复制(multi-source)以及真正的支持多线程复制了.多源复制可以使用基于二进制日志的复制或者基于事 ...

  9. mariadb-10GTID复制及多源复制

    ---本文大纲 一.什么是GTID 二.应用场景 三.多线程复制说明 四.实现过程 五.多源复制原理 六.实现过程 ---------------------------------- 一.什么是GI ...

随机推荐

  1. HashSet非常的消耗空间,TreeSet因为有排序功能,因此资源消耗非常的高,我们应该尽量少使用

    注:HashMap底层也是用数组,HashSet底层实际上也是HashMap,HashSet类中有HashMap属性(我们如何在API中查属性).HashSet实际上为(key.null)类型的Has ...

  2. java中不用BigInteger实现超大整数的乘法操作

    昨天看到一个题目:计算1234!,不能用BigInteger类 众所周知阶乘的数据会非常大,经常使用的int和long型根本不够用.一般想到的仅仅有BigInteger类,可是题目中明白说了不能用,所 ...

  3. pydoc介绍

    Ka-Ping Yee 曾创建了一个相当著名的模块,名叫 pydoc (比较而言: pydoc 可以做到 perldoc 所能做的任何事,并且做得更好.更漂亮:-).对于 Python 2.1 来说, ...

  4. mysql的优化基础知识

    1.查看各种SQL执行的频率 mysql> show status like 'Com_select';--Com_insert,Com_delete,connections(试图连接mysql ...

  5. mysql查询各种类型的前N条记录

    mysql查询各种类型的前N条记录,将3改为N(需查询条数)即可  (select * from event_info where event_type = 1  limit 3)union all( ...

  6. freemarker3

    结束标签 可以在结束标签中忽略user_def_dir_exp 也就是说可以写</@>来代替</@anything> 循环变量 <@myRepeatMacro count ...

  7. Python+selenium之简单介绍unittest单元测试框架

    Python+selenium之简单介绍unittest单元测试框架 一.unittest简单介绍 unittest支持测试自动化,共享测试用例中的初始化和关闭退出代码,在unittest中最小单元是 ...

  8. radio 标签状态改变时 触发事件

    <html> <head> <script src="jquery1.7.2.js"></script> </head> ...

  9. 深入理解JS之Scope链

    JS被很多人认为是『拙劣的语言』,被这门语言里的各种离奇的事情整的团团转,这篇文章主要来讲讲JS中的Scope链,其主要是影响JS中的变量作用域. 注:本文适合稍有一定JS基础的同学 目录: 初步认识 ...

  10. 关于Win7 x64下过TP保护(应用层)(转)

    非常感谢大家那么支持我上一篇教程.Win10 快出了,所以我打算尽快把应用层的部分说完. 调试对象:DXF调试工具:CE.OD.PCHunter.Windbg调试先言:TP的应用层保护做得比较多,包括 ...