Environment
Master1/master2 |
System |
Ip |
Database version |
Master1 |
CentOS6.7 |
10.10.3.211 |
mariadb-10.1.19 |
Master2 |
CentOS6.7 |
10.10.3.212 |
mariadb-10.1.19 |
First, the configuration of Master1
(1) Modify the Master1 configuration file/etc/my.cnf, as follows:
Log-Bin= /Usr/Local/Mysqllogs/Binlogs/Master1-bin #启用二进制日志relay-Log = /Usr/Local/Mysqllogs/Relaylogs/Relay-bin #启用中继日志auto-Increment-Offset= 1#自增起始值auto-Increment-Increment= 2#自增步长server-Id= 1
Restarting the database service
(2) Create a user with copy permission, the command is as follows
CREATE USER 'Luccy'@'10.10.3.212'Identified by '123456';REVOKE All Privileges,GRANT OPTION from 'Luccy'@'10.10.3.212';GRANTReload,lock TABLES,REPLICATIONCLIENT,REPLICATIONSLAVE on *.* to 'Luccy'@'10.10.3.212'; FLUSHPrivileges;
Second, the configuration of Master2
(1) Modify the Master1 configuration file/etc/my.cnf, as follows:
Log-Bin= /Usr/Local/Mysqllogs/Binlogs/Master2-Binrelay-Log = /Usr/Local/Mysqllogs/Relaylogs/Relay-Binauto-Increment-Offset= 2Auto-Increment-Increment= 2Server-Id= 2
Restarting the database service
(2) Create a user with copy permission, the command is as follows
CREATE USER 'Jerry'@'10.10.3.211'Identified by '123456';REVOKE All Privileges,GRANT OPTION from 'Jerry'@'10.10.3.211';GRANTReload,lock TABLES,REPLICATIONCLIENT,REPLICATIONSLAVE on *.* to 'Jerry'@'10.10.3.211'; FLUSHPrivileges;
Iii. viewing the status of Master1 and Master2
SHOW MASTER STATUS;
Master1
Master2
Four, pointing to each other
Change MASTER to Master_user= ' Jerry ', master_host= ' 10.10.3.212 ', master_password= ' 123456 ', master_log_file= ' master2-bin.000002', master_log_pos=982;
Change MASTER to Master_user= ' luccy ', master_host= ' 10.10.3.211 ', master_password= ' 123456 ', master_log_file= ' master1-bin.000001', master_log_pos=1473;
V. Start the Master1 and MASTER2 server replication process
START SLAVE;
Master1
Master2
VI. Testing
MariaDB configuration for Dual master replication