User Rating: 5 / 5

Star Active Star Active Star Active Star Active Star Active
 
star_replication.png

MariaDB comes with a very interesting way to build clusters: semi-synchronous. SS clusters are exactly in the middle of the well-known architecture; while Galera Cluster is a synchronous multi-master cluster for MariaDB (meaning that the cluster is on hold until all the nodes report back the sync) and asynchronous (the cluster waits for no slaves); SS clusters only wait or one node to report back while the others will catch on later.

Also, you can have a master-master SS cluster.

I will talk in this article about how I did this configuration using MariaDB 10.1.x. Remember you can install MariaDB under Centos 6, 7  and 8 (Rocky as well) by using OKay's repository.

How-to

The first thing is to make the host to find each other using hostnames. The easiest way to do it is by adding entries in your /etc/hosts files. You can use DNS as well, it is up to you.

1. On the Master Node

Add/edit the following lines in your my.cnf file or any inside the my.cnf.d directory.

[mysqld]
# replication
log-bin
server_id=5
log-basename=voipdb5
plugin_load_add = semisync_master
rpl_semi_sync_master_enabled=ON

Important things here:

  • server_id must be unique in all your cluster

2. On the Slave Node(s)

Edit the same file as the master, but put the following.

[mysqld]
# replication
log-bin
server_id=6
log-basename=voipdb6
plugin_load_add = semisync_slave
rpl_semi_sync_slave_enabled=ON

Please note the plugin you are adding is the slave. The same observations happen to the slave nodes.

3. (Re)start MariaDB

Just type systemctl start mariadb

4. User Creation for the Sync

CREATE USER 'replication'@'%' IDENTIFIED BY 'your-password';

GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%';

I have found notes that they suggest doing it only on the master. However, it is up to you if this may be done in all nodes.

5. Start the Sync

Type these commands in the slave nodes. Make sure the host and username match with the user you created before.

CHANGE MASTER  'label' TO MASTER_HOST='host-1', MASTER_USER='replication', MASTER_PASSWORD='your-password', MASTER_PORT=3306, MASTER_CONNECT_RETRY=10, MASTER_USE_GTID = slave_pos;

START SLAVE 'label';

If for a reason you did something wrong, the RESET SLAVE 'label' or RESET SLAVE ALL commands will help you to delete them.

Notes

  • If you want a multi-master you have to put the master configuration on a slave, and the slave configuration on a master.
    multi source replication
  • If you have a third node that is a slave of two or more masters, you will have to run the START SLAVE command per master you want to sync against.

Good luck!

blog comments powered by Disqus

About

Read about IT, Migration, Business, Money, Marketing and other subjects.

Some subjects: FusionPBX, FreeSWITCH, Linux, Security, Canada, Cryptocurrency, Trading.