mariadb多源复制 muiltil source replication
环境: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的更多相关文章
- MariaDB多源复制环境搭建(多主一丛)
环境: 192.168.1.248 HE1 主库 192.168.1.249 HE2 主库 192.168.1.250 HE3 从库 主库授权备份账户 mysql> grant SELECT, ...
- MySQL 多源复制(Mulit-Source Replication)
MySQL多源复制方案 看复制源Master_1的同步状态:SHOW SLAVE STATUS FOR CHANNEL 'Master_1'\G 查看复制源Master_2的同步状态:S ...
- mariadb 10 多源复制(Multi-source replication) 业务使用场景分析,及使用方法
mariadb 10 多源复制(Multi-source replication) 业务使用场景分析,及使用方法 官方mysql一个slave只能对应一个master,mariadb 10开始支持多源 ...
- MariaDB的GTID复制和多源复制
什么是GTID? GTID就是全局事务ID(global transaction identifier ),最初由google实现,官方MySQL在5.6才加入该功能.GTID实际上是由UUID+TI ...
- mariadb multi-source replication(mariadb多主复制)
下文一起来看看mariadb multi-source replication(mariadb多主复制)例子,希望对各位有帮助. mariadb multi-source replication( ...
- 初试mysql5.7.2新特性:多源复制(MySQL 5.7 multi-source replication)
多源复制和多主复制的区别: 多主复制示意图: 多源复制示意图: 在my.cnf中添加crash safe特性参数:master_info_repository=TABLE;relay_log_info ...
- mysql5.7 安装和多源复制实践
MySQL 5.7发布后,在复制方面有了很大的改进和提升.比如开始支持多源复制(multi-source)以及真正的支持多线程复制了.多源复制可以使用基于二进制日子的复制或者基于事务的复制.下面我们说 ...
- MySQL多源复制(八)
一.什么是多源复制 MySQL 5.7发布后,在复制方面有了很大的改进和提升.比如开始支持多源复制(multi-source)以及真正的支持多线程复制了.多源复制可以使用基于二进制日志的复制或者基于事 ...
- mariadb-10GTID复制及多源复制
---本文大纲 一.什么是GTID 二.应用场景 三.多线程复制说明 四.实现过程 五.多源复制原理 六.实现过程 ---------------------------------- 一.什么是GI ...
随机推荐
- 第二百五十五节,Bootstrap项目实战--关于
Bootstrap项目实战--关于 html <!DOCTYPE html> <html lang="zh-cn"> <head> <me ...
- Wamp2.5 64bit,无法改动MySQL datadir位置
今天偶然想到去更新一下机子里面PHP的版本号,然后又一次去wamp官网下载了WAMP(wamp 64 Apache : 2.4.9 MySQL : 5.6.17 PHP : 5.5.12 PHPMy ...
- MFC存储图片到SQL Server数据库
第一步:建立数据库表,比如:id char,pic image. 第二步:建立MFC单文档应用程序,再添加类CMyRecordset,基类选择CRecordset,导入数据库的刚建立的表. 第三步:在 ...
- Proxool线程池的简单实现demo
使用的jar包:ojdbc14.jar proxool-0.9.0.jar commons-logging-1.1.3.jar 代码分为两部分: ProxoolTest.java和proxo ...
- Erstudio8.0怎么用?Erstudio8.0汉化版详细使用教程
Erstudio8.0使用教程 打开ERstudio,点击新建出现如图对话框: 选择第一个,表示创建一个新的关系型 数据库模型 这里提一点数据库模型分为relational(关系)和dimension ...
- 【黑金原创教程】【TimeQuest】【第六章】物理时钟与外部模型
声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/al ...
- 【BZOJ1486】[HNOI2009]最小圈 分数规划
[BZOJ1486][HNOI2009]最小圈 Description Input Output Sample Input 4 5 1 2 5 2 3 5 3 1 5 2 4 3 4 1 3 Samp ...
- 解析oracle的rownum,数据库查询结果返回行数设置
对于rownum来说它是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,依此类推,这个伪字段可以用于限制查询返回的总行数,而且rownum不能以任何表的名称作为前缀 ...
- vector排序问题<unresolved overloaded function type>
要对vector中的自定义类型进行排序,首先需要提供一个函数bool comp(const Interval & a, const Interval & b) 来定义类型的排序准则 然 ...
- SignalR循序渐进(三)简易的集群通讯组件
上一篇演示了泛型Hub的实现,微软于6月17日更新了SignalR 2.1.0,然后自带了泛型Hub,于是就不需要自己去实现了…(微软你为啥不早一个月自带啊…).不过没关系,SignalR出彩之处不在 ...