Building MariaDB Master Salve replication cluster CentOS 7

Assumptions:
We have 2 Linux VMs with 5.5.56-MariaDB. IP address 192.168.0.222(cluster1.local) and 192.168.0.223(cluster2.local)
We have 3 existing databases on cluster1.local – mydb1, mydb2, mydb3

Setup Master (cluster1.local)

Edit my.cnf file

vi /etc/my.cnf
bind-address = 0.0.0.0
server_id=1
log-basename=master1
log-bin
replicate-do-db = mydb1
replicate-do-db = mydb2

Restart MariaDB

systemctl restart mariadb

Inside MariaDB prompt

GRANT REPLICATION SLAVE ON *.* TO 'rpluser'@'%' IDENTIFIED BY 'Password33';
FLUSH PRIVILEGES;

FLUSH TABLES WITH READ LOCK;     # keep this session running 
SHOW MASTER STATUS; # record file and position details
MariaDB [(none)]> SHOW MASTER STATUS;
+--------------------+----------+--------------+------------------+
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mariadb-bin.000001 |      245 |              |                  |
+--------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Dump both databases that we will need to replicate (you will need to open new terminal for this as mysql session must remain locked and open)

mysqldump -u root -p --opt mydb1 > mydb1.sql
mysqldump -u root -p --opt mydb2 > mydb2.sql

After dump completed copy both databases to slave server and unlock databases in MariaDB prompt

UNLOCK TABLES;
QUIT;

Setup Slave (cluster2.local)

Edit my.cnf file

vi /etc/my.cnf
bind-address = 0.0.0.0
server-id = 2
binlog_do_db = mydb1
binlog_do_db = mydb2

Restart MariaDB

systemctl restart mariadb

Inside MariaDB prompt

CREATE DATABASE mydb1;
CREATE DATABASE mydb2;

Import databases we exported above

mysql -u root -p mydb1 < mydb1.sql
mysql -u root -p mydb2 < mydb2.sql

Inside MariaDB prompt (make sure you use MASTER_LOG_FILE and MASTER_LOG_POS received from steps above)

CHANGE MASTER TO
  MASTER_HOST='192.168.0.222',
  MASTER_USER='rpluser',
  MASTER_PASSWORD='Password33',
  MASTER_PORT=3306,
  MASTER_LOG_FILE='mariadb-bin.000001 ',
  MASTER_LOG_POS=245,
  MASTER_CONNECT_RETRY=10;

START SLAVE;

To stop replication and view status

STOP SLAVE;
SHOW SLAVE STATUS\G

If you get Mysql error 1236 from master when reading data from binary log

Slave - in MariaDB

stop slave;

Master - in MariaDB

flush logs;

Master - in MariaDB

show master status;    #take note of the master log file and master log position
MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 |      245 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Slave - in MariaDB

CHANGE MASTER TO MASTER_LOG_FILE=' mysql-bin.000004', MASTER_LOG_POS=245;
start slave;