Configuring Master-Master Replication On Mariadb: 1. Mariadb: Configuration of The First Master Server (Master-1)
Configuring Master-Master Replication On Mariadb: 1. Mariadb: Configuration of The First Master Server (Master-1)
In a Master-Master replication scheme, any of the MariaDB database servers may be used both to
write or read data. Replication is based on a special binlog file, a Master server saves all operations
with the database to. A Slave server connects to the Master and applies the commands to its
databases.
server-id = 1
report_host = master
log_bin = /var/lib/mysql/mariadb-bin
log_bin_index = /var/lib/mysql/mariadb-bin.index
relay_log = /var/lib/mysql/relay-bin
relay_log_index = /var/lib/mysql/relay-bin.index
+--------------------+----------+--------------+------------------+
| mariadb-bin.000002 | 664 | | |
+--------------------+----------+--------------+------------------+
#replication
server-id = 2
report_host = master2
log_bin = /var/lib/mysql/mariadb-bin
log_bin_index = /var/lib/mysql/mariadb-bin.index
relay_log = /var/lib/mysql/relay-bin
relay_log_index = /var/lib/mysql/relay-bin.index
Create a new user on the second server as well:
+--------------------+----------+--------------+------------------+
| mariadb-bin.000001 | 667 | | |
+--------------------+----------+--------------+------------------+
Let’s configure the connection between MariaDB servers in our software replication cluster:
STOP SLAVE;
Add Master-1 to the second server:
START SLAVE;
Connect to Master-1 and follow the same steps, but specify the information about the second server
instead:
STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='10.2.10.36', MASTER_USER='test_master2',
MASTER_PASSWORD='test_master2', MASTER_LOG_FILE='mariadb-bin.000001',
MASTER_LOG_POS=667;
START SLAVE;
Check the second server status:
As you can see in the screenshots, there is the connection between two servers, and no errors
occur.
Make sure that this database has automatically replicated on the second master and contains the
same table:
| Database |
+--------------------+
| information_schema |
| master1 |
| mysql |
| performance_schema |
+--------------------+
| Tables_in_master1 |
+-------------------+
| hello |
+-------------------+
The database has been created on the second master as well. To check the full cycle, create a table
in the Master1 database on the second Master server and check if it appears on the first server.
| Tables_in_master1 |
+-------------------+
| hello |
| hello_master1 |
+-------------------+