背景:

目前MySQL依然只支持一个Slave从一个Master复制数据,虽然也可以做到一主多备(M->S),双主复制(M<->M)等架构,但是局限性依然很大。由于项目的要求,需要各个主库的表整合到一个地方进行统计和分析,要是每次连不同的实例操作,是一件非常耗体力的操作。所以继续一种类似多主一从的实例。

安装

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://mirrors.hustunique.com/mariadb/repo/10.0/ubuntu trusty main'
sudo apt-get update
sudo apt-get install mariadb-server

环境搭建

Master :200.51(MySQL)
Master :200.52(MySQL)
Slave :200.73(MariaDB) 修改好server-id

确认好Master的POS:

M1:
rep@192.168.200.51 : (none) 10:26:11>show master status;
+--------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mysql-bin51.000013 | 107 | | test |
+--------------------+----------+--------------+------------------+
1 row in set (0.01 sec)
M2:
rep@192.168.200.52 : r2 10:26:23>show master status; +---------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-bin_52.000106 | 107 | | test |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Slave 操作:

MariaDB [(none)]> change master 'r1' to master_host='192.168.200.51',master_user='rep',master_password='rep123456',master_log_file='mysql-bin51.000013',master_log_pos=107;
Query OK, 0 rows affected (0.23 sec) MariaDB [(none)]> change master 'r2' to master_host='192.168.200.52',master_user='rep',master_password='rep123456',master_log_file='mysql-bin_52.000106',master_log_pos=107;
Query OK, 0 rows affected (0.25 sec)

MariaDB的change方法和MySQL有点不一样,多了一个 ['connection_name'] ,这个就是多主一从的关键。为每个主设置一个通道标识,这样就可以支持多主复制了。

如何保存复制的信息?单主复制会把复制信息保存在master.info中,在多主复制中的保存也类似,只是在最后加上通道标识名称。如:

-rw-rw----  mysql mysql   11月  : master-r1.info
-rw-rw---- mysql mysql 11月 : master-r2.info
-rw-rw---- mysql mysql 11月 : mysqld-relay-bin-r1.
-rw-rw---- mysql mysql 11月 : mysqld-relay-bin-r1.index
-rw-rw---- mysql mysql 11月 : mysqld-relay-bin-r2.
-rw-rw---- mysql mysql 11月 : mysqld-relay-bin-r2.index
-rw-rw---- mysql mysql 11月 : relay-log-r1.info
-rw-rw---- mysql mysql 11月 : relay-log-r2.info

查看同步

#查看所有通道
MariaDB [(none)]> show all slaves status\G;
*************************** 1. row ***************************
Connection_name: r1
Slave_SQL_State:
Slave_IO_State:
Master_Host: 192.168.200.51
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin51.000013
Read_Master_Log_Pos: 107
Relay_Log_File: mysqld-relay-bin-r1.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin51.000013
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 107
Relay_Log_Space: 248
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Retried_transactions: 0
Max_relay_log_size: 104857600
Executed_log_entries: 0
Slave_received_heartbeats: 0
Slave_heartbeat_period: 1800.000
Gtid_Slave_Pos:
*************************** 2. row ***************************
Connection_name: r2
Slave_SQL_State:
Slave_IO_State:
Master_Host: 192.168.200.52
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin_52.000106
Read_Master_Log_Pos: 107
Relay_Log_File: mysqld-relay-bin-r2.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin_52.000106
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 107
Relay_Log_Space: 248
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Retried_transactions: 0
Max_relay_log_size: 104857600
Executed_log_entries: 0
Slave_received_heartbeats: 0
Slave_heartbeat_period: 1800.000
Gtid_Slave_Pos:
2 rows in set (0.00 sec) ERROR: No query specified

#查看单个通道
MariaDB [(none)]> show slave 'r1' status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.200.51
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin51.000013
Read_Master_Log_Pos: 107
Relay_Log_File: mysqld-relay-bin-r1.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin51.000013
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 107
Relay_Log_Space: 248
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec) ERROR: No query specified MariaDB [(none)]> show slave 'r2' status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.200.52
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin_52.000106
Read_Master_Log_Pos: 107
Relay_Log_File: mysqld-relay-bin-r2.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin_52.000106
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 107
Relay_Log_Space: 248
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec) ERROR: No query specified

开启同步

#开启单个通道
MariaDB [(none)]> start slave 'r1';
Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> start slave 'r2';
Query OK, 0 rows affected (0.00 sec) #开启所有通道
MariaDB [(none)]> start all slaves;
Query OK, 0 rows affected, 2 warnings (0.01 sec) MariaDB [(none)]> show warnings;
+-------+------+--------------------+
| Level | Code | Message |
+-------+------+--------------------+
| Note | 1937 | SLAVE 'r2' started |
| Note | 1937 | SLAVE 'r1' started |
+-------+------+--------------------+
2 rows in set (0.00 sec)

通过 show all slaves status 命令可知是否同步成功。

关闭同步

#关闭单个通道
MariaDB [(none)]> stop slave 'r1';
Query OK, 0 rows affected (0.14 sec) MariaDB [(none)]> stop slave 'r2';
Query OK, 0 rows affected (0.03 sec) #关闭所有通道
MariaDB [(none)]> stop all slaves;
Query OK, 0 rows affected, 2 warnings (0.08 sec) MariaDB [(none)]> show warnings;
+-------+------+--------------------+
| Level | Code | Message |
+-------+------+--------------------+
| Note | 1938 | SLAVE 'r2' stopped |
| Note | 1938 | SLAVE 'r1' stopped |
+-------+------+--------------------+
2 rows in set (0.00 sec)

多源复制在原先复制的基础上多了几个变量,现在来说明下:

MariaDB [(none)]> show all slaves status\G;
*************************** 1. row ***************************
Connection_name: r1 #master的连接名,通道名,第一个参数。
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.200.51
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin51.000013
Read_Master_Log_Pos: 107
Relay_Log_File: mysqld-relay-bin-r1.000005
Relay_Log_Pos: 396
Relay_Master_Log_File: mysql-bin51.000013
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 107
Relay_Log_Space: 845
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Retried_transactions: 0 #这个连接重试事务的次数
Max_relay_log_size: 104857600 #relay log的最大值. 如果是0的话,那么在启动的时候就会被设置成max_binlog_size 的大小
Executed_log_entries: 17 #slave已经指向了多少个日志条目
Slave_received_heartbeats: 0 #我们从master收到了多少个心跳包
Slave_heartbeat_period: 1800.000 #多久从master请求一个心跳包 (以秒计算)

Gtid_Slave_Pos:

测试复制

Master 1:
rep@192.168.200.51 : (none) 01:52:34>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mha_test |
| mysql |
| performance_schema |
| xtra_test |
+--------------------+
5 rows in set (0.00 sec) rep@192.168.200.51 : (none) 01:52:37>create database r1 default charset utf8;
Query OK, 1 row affected (0.01 sec) rep@192.168.200.51 : (none) 01:53:36>use r1;
Database changed rep@192.168.200.51 : r1 01:53:44>create table r1(id int not null auto_increment primary key,name varchar(30))default charset utf8;
Query OK, 0 rows affected (1.35 sec) rep@192.168.200.51 : r1 01:54:09>insert into r1(name) values('a'),('b'),('c');
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0 rep@192.168.200.51 : r1 01:54:56>select * from r1;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec) Master 2:
rep@192.168.200.52 : (none) 01:52:13>create database r2 default charset utf8;
Query OK, 1 row affected (0.01 sec) rep@192.168.200.52 : (none) 01:54:27>use r2
Database changed
rep@192.168.200.52 : r2 01:54:30>create table r2(id int not null auto_increment primary key,name varchar(30))default charset utf8;
Query OK, 0 rows affected (0.23 sec) rep@192.168.200.52 : r2 01:54:32>insert into r2(name) values('A'),('B'),('C');
Query OK, 3 rows affected (0.28 sec)
Records: 3 Duplicates: 0 Warnings: 0 rep@192.168.200.52 : r2 01:55:18>select * from r2;
+----+------+
| id | name |
+----+------+
| 1 | A |
| 2 | B |
| 3 | C |
+----+------+
3 rows in set (0.01 sec) Slave:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| r1 |
| r2 |
+--------------------+
5 rows in set (0.00 sec) MariaDB [(none)]> use r1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [r1]> select * from r1;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec) MariaDB [r1]> use r2;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
MariaDB [r2]> select * from r2;
+----+------+
| id | name |
+----+------+
| 1 | A |
| 2 | B |
| 3 | C |
+----+------+
3 rows in set (0.00 sec)

同步成功,那如何错误跳过呢(default_master_connection)?

在Master 1上创建r2数据库,因为Slave上存在,所以会报错:
Master
rep@192.168.200.51 : r1 01:55:52>create database r2 default charset utf8;
Query OK, 1 row affected (0.01 sec) rep@192.168.200.51 : r1 01:59:51>insert into r1(name) values('d'),('e'),('f');
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0 rep@192.168.200.51 : r1 02:04:22>select * from r1;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
| 5 | e |
| 6 | f |
+----+------+
6 rows in set (0.00 sec) Slave :
MariaDB [r2]> show slave 'r1' status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.200.51
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin51.000013
Read_Master_Log_Pos: 767
Relay_Log_File: mysqld-relay-bin-r1.000005
Relay_Log_Pos: 956
Relay_Master_Log_File: mysql-bin51.000013
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1007
Last_Error
: Error 'Can't create database 'r2'; database exists' on query. Default database: 'r2'. Query: 'create database r2 default charset utf8'
Skip_Counter: 0
Exec_Master_Log_Pos: 667
Relay_Log_Space: 1505
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1007
Last_SQL_Error: Error 'Can't create database 'r2'; database exists' on query. Default database: 'r2'. Query: 'create database r2 default charset utf8'
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec) MariaDB [r1]> select * from r1;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec) r1的同步失败了,那r2可以继续同步吗? Master :
rep@192.168.200.52 : r2 01:55:59>insert into r2(name) values('D'),('E'),('F');
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0 rep@192.168.200.52 : r2 02:02:19>select * from r2;
+----+------+
| id | name |
+----+------+
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | D |
| 5 | E |
| 6 | F |
+----+------+
6 rows in set (0.01 sec) Slave:
MariaDB [r2]> select * from r2;
+----+------+
| id | name |
+----+------+
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | D |
| 5 | E |
| 6 | F |
+----+------+
6 rows in set (0.00 sec) 上面可以得出:r1同步失败之后,不影响r2的同步。想要r1同步正常,则需要忽略即跳过该错误。如: MariaDB [r1]> stop slave 'r1';
Query OK, 0 rows affected (0.12 sec) MariaDB [r1]> set @@default_master_connection='r1'; #这里是重点:指定一个通道,然后用单通道的sql_slave_skip_counter。
Query OK, 0 rows affected (0.00 sec) MariaDB [r1]> select @@default_master_connection;
+-----------------------------+
| @@default_master_connection |
+-----------------------------+
| r1 |
+-----------------------------+
1 row in set (0.00 sec) MariaDB [r1]> SET GLOBAL sql_slave_skip_counter =1;
Query OK, 0 rows affected (0.00 sec) MariaDB [r1]> start slave 'r1';
Query OK, 0 rows affected (0.00 sec) MariaDB [r1]> show slave 'r1' status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.200.51
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin51.000013
Read_Master_Log_Pos: 993
Relay_Log_File: mysqld-relay-bin-r1.000006
Relay_Log_Pos: 396
Relay_Master_Log_File: mysql-bin51.000013
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 993
Relay_Log_Space: 1731
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec) MariaDB [r1]> select * from r1;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
| 5 | e |
| 6 | f |
+----+------+
6 rows in set (0.00 sec) 看到跳过/忽略错误之后,r1的复制就正常了。

从上面的测试上说明,在用多主一从的复制时,需要保证各个主的Master Schema 要唯一,不能有重复。

最后再看看如何初始化

MariaDB [r1]> show all slaves status\G;
*************************** 1. row ***************************
Connection_name: r1
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.200.51
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin51.000013
Read_Master_Log_Pos: 1376
Relay_Log_File: mysqld-relay-bin-r1.000006
Relay_Log_Pos: 779
Relay_Master_Log_File: mysql-bin51.000013
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1376
Relay_Log_Space: 2114
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Retried_transactions: 0
Max_relay_log_size: 104857600
Executed_log_entries: 39
Slave_received_heartbeats: 4
Slave_heartbeat_period: 1800.000
Gtid_Slave_Pos:
*************************** 2. row ***************************
Connection_name: r2
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.200.52
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin_52.000106
Read_Master_Log_Pos: 893
Relay_Log_File: mysqld-relay-bin-r2.000005
Relay_Log_Pos: 1183
Relay_Master_Log_File: mysql-bin_52.000106
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 893
Relay_Log_Space: 1633
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Retried_transactions: 0
Max_relay_log_size: 104857600
Executed_log_entries: 28
Slave_received_heartbeats: 4
Slave_heartbeat_period: 1800.000
Gtid_Slave_Pos:
2 rows in set (0.00 sec) #单个通道初始化
MariaDB [r1]> reset slave 'r1' all;
ERROR 1198 (HY000): This operation cannot be performed as you have a running slave 'r1'; run STOP SLAVE 'r1' first
MariaDB [r1]> stop slave 'r1';
Query OK, 0 rows affected (0.03 sec) MariaDB [r1]> reset slave 'r1' all;
Query OK, 0 rows affected (0.04 sec) MariaDB [r1]> stop slave 'r2';
Query OK, 0 rows affected (0.02 sec) MariaDB [r1]> reset slave 'r2' all;
Query OK, 0 rows affected (0.02 sec) MariaDB [r1]> show all slaves status\G;
Empty set (0.00 sec) #所有通道初始化
MariaDB [r1]> stop all slaves;
Query OK, 0 rows affected, 2 warnings (0.05 sec) MariaDB [r1]> show warnings;
+-------+------+--------------------+
| Level | Code | Message |
+-------+------+--------------------+
| Note | 1938 | SLAVE 'r2' stopped |
| Note | 1938 | SLAVE 'r1' stopped |
+-------+------+--------------------+
2 rows in set (0.00 sec) MariaDB [r1]> reset slave all; #执行时候发现只能让r1初始化,不能初始化r2。所以初始化还是要单通道执行。

总结:

经过上面的测试,实现了多个主实例的数据同步到一个从实例,这个就可以把集中做分析的数据表同步到一起进行分析处理,大大减少了数据的中间处理时间和安全,这里还有一点特别注意的是,在同步数据库的时候可以用过滤选项(Replicate_Do_Table、Replicate_Ignore_Table、Replicate_Wild_Do_Table、Replicate_Wild_Ignore_Table),看着需要同步自己需要的表,不需要把没必要的也同步过来。

传统复制模式 -> 多源复制的命令变化

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连接状态
sql_slave_skip_couter -> stop slave 'connection_name',先指定连接源名称 set @@default_master_connection='connection_name';然后再set global sql_slave_skip_counter=;最后start slave 'connection_name'
多源复制环境下的replicate-... variables 变量问题
在my.cnf replicate_ignore_db 前添加conn连接串前缀,比如 r1.replicate_ignore_db=ignore_database若不加前缀,就是忽略所有同名的数据库,其他变量类推。

更多信息见:

https://mariadb.com/kb/en/mariadb/documentation/replication/standard-replication/multi-source-replication/

http://www.penglixun.com/tech/database/diy_multi_master_replication.html

https://mariadb.com/kb/zh-cn/multi-source-replication/

MariaDB 多主一从 搭建测试的更多相关文章

  1. mysql之 mysql 5.6不停机双主一从搭建(活跃双主一从基于日志点复制)

    环境说明:版本 version 5.6.25-log 主1库ip: 10.219.24.25主2库ip: 10.219.24.22从1库ip:10.219.24.26os 版本: centos 6.7 ...

  2. MFC程序使用GTest搭建测试框架

    一.起源 最近对单元测试比较感兴趣,之后就上网搜了一些测试的框架,C++项目使用的测试框架基本上都使用的GoogleTest,之后就开启了gtest的学习之路. 主要是根据<玩转Google开源 ...

  3. LVS+keepalived快速搭建测试环境

    #LVS+keepalived快速搭建测试环境 #LVS+keepalived快速搭建测试环境 #centos6 X64 # LVS 负载均衡模式:DR(直接路由) 192.168.18.31 mas ...

  4. 结合jenkins在Linux服务器搭建测试环境

    何时使用: 测试过程中我们需要持续构建一个软件项目,为避免重复的手动下载.解压操作,我们需要搭建一个能够自动构建的测试环境,当代码有更新时,测试人员只需点一下[构建]即可拉取最新的代码进行测试(也可设 ...

  5. 在Linux上搭建测试环境常用命令(转自-测试小柚子)

    一.搭建测试环境: 二.查看应用日志: (1)vivi/vim 原本是指修改文件,同时可以使用vi 日志文件名,打开日志文件(2)lessless命令是查看日志最常用的命令.用法:less 日志文件名 ...

  6. mysql 架构篇系列 4 复制架构一主一从搭建(半同步复制)

    一.概述 在mysql 5.5之前,mysql 的复制是异步操作,主库和从库的数据之间存在一定的延时,这样存在一个隐患:当主库上写入一个事务并提交成功,而从库尚未得到主库推送的Binlog日志时,主库 ...

  7. 大数据基础-2-Hadoop-1环境搭建测试

    Hadoop环境搭建测试 1 安装软件 1.1 规划目录 /opt [root@host2 ~]# cd /opt [root@host2 opt]# mkdir java [root@host2 o ...

  8. Nginx配置多个基于域名的虚拟主机+实验环境搭建+测试

    标签:Linux 域名 Nginx 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://xpleaf.blog.51cto.com/9 ...

  9. Mybatis框架一:搭建测试

    Mybatis框架不再介绍: 在JDBC中存在一些问题: 1.频繁连接和释放资源浪费内存 2.编码完成后不便于维护 于是产生了简化数据库操作的框架:Hibernate.Mybatis等等,这里介绍My ...

随机推荐

  1. HTML标记语言篇--学习笔记01

    HTML标记语言篇 第1章  HTML基础 1.1 基本概念 WWW 是"World Wide Web"(全球广域网)的缩写,简称为Web,中文又称为"万维网" ...

  2. C#基础系列——异步编程初探:async和await

    前言:前面有篇从应用层面上面介绍了下多线程的几种用法,有博友就说到了async, await等新语法.确实,没有异步的多线程是单调的.乏味的,async和await是出现在C#5.0之后,它的出现给了 ...

  3. ASP.NET中的缓存机制

    ASP.NET 提供一个功能完整的缓存引擎,页面可使用该引擎通过 HTTP 请求存储和检索任意对象.缓存的生存期与应用程序的生存期相同,也就是说,当应用程序重新启动时,将重新创建缓存. 将数据添加到缓 ...

  4. 分享 Ionic 开发 Hybrid App 中遇到的问题以及后期发布 iOS/Android 的方方面面

    此篇文章主要整理了最近在使用 Ionic 开发 Hybrid App 过程中遇到的一些疑难点以及后期发布生成 iOS 和 Android 版本过程中的种种问题. 文章目录 Ionic 简介和项目需求介 ...

  5. 浅谈微信小程序

    在如火如荼的互联网技术发展中,各种各样的框架出现,当下最受关注的应该就是微信小程序了.从新闻论坛乃至qq群.微信群,很多很多从事IT工作的朋友喜欢讨论研究这个小程序.带着好奇心,我也参与其中. 第一步 ...

  6. JavaScript----Js操控-HTML5 <progress> 标签

    Js操控----HTML5 <progress> 标签 简单模拟下下载进度跑条 <h4>加载进度</h4> <input type="button& ...

  7. 使用apache ftpserver搭建ftp服务器

    作为一个javaer,遇到任何问题,先查一下java中的解决方案.地球上的许多事情,在java中都能找到完美的解决方案.之前搭建ftp服务器使用的是vsftpd,现在可以把它卸掉了,它以服务的形式运行 ...

  8. Nginx搭建https服务器

    HTTPS简介 HTTPS(Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单来讲就是HTTP的安全版.即H ...

  9. jQuery之XML的加载和解析

    1.XML(eXtensible Markup Language)即可扩展标记语言,与HTML一样,都是SGML标准通用语言.语法如下: 任何起始标签都必须有一个结束标签. 可以采用另一种简化语法,即 ...

  10. ssh中org.springframework.orm.hibernate4.support.OpenSessionInViewFilter的作用及配置

     org.springframework.orm.hibernate4.support.OpenSessionInViewFilter 是Spring为我们解决Hibernate的Session的关闭 ...