One, double copy master model: two node mutual master-slave, can read and write.
Second, dual copy master model:
1, presentation environment:
IP |
operating system |
Database Version |
Mounting |
Character |
192.168.1.145 |
CentOS 7.6 x86_64 |
MariaDB-10.3.15 |
yum |
master1 |
192.168.1.146 |
CentOS 7.6 x86_64 |
MariaDB-10.3.15 |
yum |
master2 |
2, the server time synchronization of two nodes
3, Master1 modify server.cnf configuration file: # vim /etc/my.cnf.d/server.cnf
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
data = / var / lib / mysql
log_error=/var/log/mariadb.log
lower_case_table_names=1
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
innodb_file_per_table=1
skip_name_resolve=1
slow_query_log=1
slow_query_log_file=mariadb-slow.log
log_bin=master1-bin
log_bin_index=master1-bin.index
binlog_format=mixed
relay_log=relay1-log
relay_log_index=relay1-log.index
server_id=1
sync_binlog=1
innodb_flush_log_at_trx_commit=1
Note: The default relay log does not exist, will be automatically generated only when the copy start
4, Master1 create a user with replication privileges:
MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'192.168.1.146' identified by '123456';
MariaDB [(none)]> flush privileges;
5, Master1 view is being used binary log file name and location of the event:
MariaDB [(none)]> show master status;
6, Master2 modify server.cnf configuration file: # vim /etc/my.cnf.d/server.cnf
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
data = / var / lib / mysql
log_error=/var/log/mariadb.log
lower_case_table_names=1
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
innodb_file_per_table=1
skip_name_resolve=1
slow_query_log=1
slow_query_log_file=mariadb-slow.log
log_bin=master2-bin
log_bin_index=master2-bin.index
binlog_format=mixed
relay_log=relay2-log
relay_log_index=relay2-log.index
server_id=2
sync_binlog=1
innodb_flush_log_at_trx_commit=1
. 7, Master2 user permissions to connect to a replication Master1 :
MariaDB [(none)]> change master to master_host='192.168.1.145',master_user='repluser',master_password='123456',master_port=3306,master_log_file='master1-bin.000001',master_log_pos=2035;
MariaDB [(none)]> show slave status\G
Remarks:
(1) Slave_IO_Running and Slave_SQL_Running value, the default is No
(2) Automatic data directory / var / lib / mysql creation RELAY2-log.000001 , RELAY2-log.index and relay-log.info file
(3) Master_Log_File value master1 binary log file name
(4) Read_Master_Log_Pos value master1 position binary log events
8, Master2 start replication threads:
MariaDB [(none)]> start slave;
Remarks:
(. 1) Start Slave equivalent to each execution start slave io_thread and start slave sql_thread
(2) STOP Slave means to stop the master-slave replication thread
(3) Restart master2 server is located, copied thread will automatically start
MariaDB [(none)]> show slave status\G
Remarks:
(1) only if Slave_IO_Running and Slave_SQL_Running values are Yes , the copy thread is considered a successful start
(2) the Seconds_Behind_Master a value of 0 , indicating master2 not behind master1
(3) Information recorded in detail during replication master2 error log /var/log/mariadb.log in
9, Master2 create a user with replication privileges:
MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'192.168.1.145' identified by '123456';
MariaDB [(none)]> flush privileges;
10, Master2 view is being used binary log file name and location of the event:
MariaDB [(none)]> show master status;
. 11, Master1 user permissions to connect to a replication Master2 :
MariaDB [(none)]> change master to master_host='192.168.1.146',master_user='repluser',master_password='123456',master_port=3306,master_log_file='master2-bin.000001',master_log_pos=2035;
MariaDB [(none)]> show slave status\G
Remarks:
(1) Slave_IO_Running and Slave_SQL_Running value, the default is No
(2) Automatic data directory / var / lib / mysql creation RELAY1-log.000001 , RELAY1-log.index and relay-log.info file
(3) Master_Log_File value master2 binary log file name
(4) Read_Master_Log_Pos value master2 position binary log events
12, Master1 start replication threads:
MariaDB [(none)]> start slave;
Note: Restart master1 server is located, copied thread will automatically start
MariaDB [(none)]> show slave status\G
Remarks:
(1) only if Slave_IO_Running and Slave_SQL_Running values are Yes , the copy thread is considered a successful start
(2) the Seconds_Behind_Master a value of 0 , indicating master1 not behind master2
(3) Information recorded in detail during replication master1 error log /var/log/mariadb.log in
13, Master1 view master2 information:
MariaDB [(none)]> show slave hosts;
14, Master2 view master1 information:
MariaDB [(none)]> show slave hosts;
Third, the test double master model to copy:
1, Master1 create test data:
MariaDB [(none)]> create database db1;
MariaDB [(none)]> use db1;
MariaDB [db1]> create table tb1(id int unsigned auto_increment primary key not null,name char(20) not null);
MariaDB [db1]> desc tb1;
MariaDB [db1]> insert into tb1(name) values('zhangsan'),('lisi');
MariaDB [db1]> select * from tb1;
MariaDB [db1]> show master status;
2, Master2 view the test data:
MariaDB [(none)]> show databases;
MariaDB [(none)]> use db1;
MariaDB [db1]> show tables;
MariaDB [db1]> desc tb1;
MariaDB [db1]> select * from tb1;
MariaDB [db1]> show slave status\G
3, Master2 create test data:
MariaDB [db1]> insert into tb1(name) values('wangwu'),('zhaoliu');
MariaDB [db1]> select * from tb1;
MariaDB [db1]> show master status;
4, Master1 view the test data:
MariaDB [db1]> select * from tb1;
MariaDB [db1]> show slave status\G