环境: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. leetCode 77.Combinations (组合)

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  2. hdu 1140:War on Weather(计算几何,水题)

    War on Weather Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  3. 插件之下拉框Select2

    select2为代替常规的select而出现,可自定义select的样式,最明显的功能就是集合中可以搜索 关于浏览器要求,ie8+,Chrome 8+,Firefox 10+,Safari 3+,Op ...

  4. zookeeper配置详解

    原文地址: http://itindex.net/detail/40187-zookeeper-%E7%AE%A1%E7%90%86%E5%91%98-%E7%AE%A1%E7%90%86 参数名 说 ...

  5. Apache里的httpd-vhosts.conf详解

    首先看下面的配置: <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "D ...

  6. 使用jq获取文字的宽度

    获取字符串的长度很简单,但是如何获取一个字符串的字体宽度却是一个不太好操作的问题,今天查阅了许多资料,终于找到了解决方法: 1.首先,需要添加一个标签,HTML代码如下: <body> & ...

  7. 在静态工具类中需要注入mapper

    在xml中 <bean id="messageUtil" class="org.ldd.ssm.hangyu.utils.MessageUtil" ini ...

  8. Android 中加载几百张图片做帧动画防止 OOM 的解决方案

    Android 中加载几百张图片做帧动画防止 OOM 的解决方案 最近,项目中有个需求:就是要做一个帧动画,按理说这个是很简单的!但是我能说这个帧动画拥有几百张图片吗?...... 填坑一 ---帧动 ...

  9. Android ListView的监听事件

    Android开发时,最常用的控件之一就是ListView了,而使用ListView的同时,必然需要对它设置监听器,常用的监听器有这么几个1.OnItemClickListener 2.OnTouch ...

  10. 记一个在docker中运行多线程event_loop.run_forever()的bug

    问题简介 我写爬虫,用到了asyncio相关的事件循环,新建了一个线程去run_forever(),在docker中运行.后来程序有异常,主线程挂了,但是竟然不报错.查了很久,才找出来. 如果你新建一 ...