MariaDB Master-Slave Replication on CentOS 8

Step 1: Mariadb installation 
# yum install mariadb-server mariadb

Step 2: Start MariaDB service and let it to start automatically on every reboot:
# systemctl start mariadb
# systemctl disable mariadb

Step 3: Set MariaDB root password by default root password is empty
# mysql_secure_installation

Step 4: Stop master & slave server firewall 
# systemctl stop firewalld
# vim /etc/selinux/config
SELINUX=disabled


Step 5: Configuration for master file
configuration file name and location (CentOS)
# /etc/my.cnf.d/mariadb-server.cnf

add the following lines under [mysqld] section
log_bin
server_id=1
bind-address=machine ip (Ex. 150.236.189.166)

Step 6: Restart Mariadb Server
# systemctl restart mariadb

Step 7: Create Slave user and password
# mysql -u root -proot (login mysql server with root user)
# Create user 'mst_rep1'@'%' identified by 'mst_rep1'
# grant replication slave on *.* to 'mst1_rep'@'%';
# flush privileges;

Step 8: Show master status
# Show master status;
+--------------------+----------+--------------+------------------+
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| mariadb-bin.000004 |     1796 |              |                  |
+--------------------+----------+--------------+------------------+

Step 9: Stop mariadb from master 
# systemctl stop mariadb

Step 10: Backup data folder and send to slave server (backup original data folder)

data folder directory
# /var/lib/mysql
# tar -zcvf mysql_master.tgz /var/lib/mysql/

==========================================
Step 11: Slave Server Configuration
add the following lines under [mysqld] section
# /etc/my.cnf.d/mariadb-server.cnf
add the following lines under [mysqld] section
# server_id=2
# bind-address=150.236.189.124

Step 12: execute below command
# mysql -r root -proot (login slave server)
# stop slave;
# change master to master_host='150.236.189.166', master_user='mst_rep', master_password='mst_rep',
master_log_file='mariadb-bin.000004', master_log_pos=1322;
# start slave;

Step 13: Check slave status
MariaDB [(none)]> show slave status \G;
*************************** 1. row ***************************
                Slave_IO_State: Waiting for master to send event
                   Master_Host: 150.236.189.166
                   Master_User: mst_rep
                   Master_Port: 3306
                 Connect_Retry: 60
               Master_Log_File: mariadb-bin.000004
           Read_Master_Log_Pos: 1796
                Relay_Log_File: mariadb-relay-bin.000002
                 Relay_Log_Pos: 1031
         Relay_Master_Log_File: mariadb-bin.000004
              Slave_IO_Running: Yes
             Slave_SQL_Running: Yes

Step 14: Test MariaDB Replication
# Create a database in master database and check the database from slave server
@ Master database
MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
@ Slave database
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| testdb             |
+--------------------+
5 rows in set (0.000 sec)

Done!!

Post a Comment

0 Comments

3