How to set up MariaDB Master Slave replication with SSL on Ubuntu Linux

Setting up MariaDB Master-Slave replication with SSL on Ubuntu Linux involves the following steps:

  1. Install MariaDB on both the master and the slave servers.
  2. On the master server, open the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
  1. Add the following lines to the file:
server-id = 1
log_bin = /var/log/mysql/mariadb-bin.log
bind-address = <master_server_ip>
  1. Save and close the file.
  2. Restart MariaDB:
sudo systemctl restart mariadb
  1. Log in to the MariaDB shell:
sudo mysql
  1. Create a user and grant replication privileges:
CREATE USER 'repl'@'<slave_server_ip>' IDENTIFIED BY '<password>';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'<slave_server_ip>';
  1. Flush the privileges:
FLUSH PRIVILEGES;
  1. Take a backup of the master server’s databases:
mysqldump --all-databases --master-data > dump.sql
  1. On the slave server, open the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
  1. Add the following lines to the file:
server-id = 2
relay-log = /var/log/mysql/mariadb-relay-bin.log
bind-address = <slave_server_ip>
  1. Save and close the file.
  2. Restart MariaDB:
sudo systemctl restart mariadb
  1. Log in to the MariaDB shell:
sudo mysql
  1. Import the backup:
source dump.sql
  1. Change the master on the slave server:
CHANGE MASTER TO
MASTER_HOST='<master_server_ip>',
MASTER_USER='repl',
MASTER_PASSWORD='<password>',
MASTER_LOG_FILE='<log_file>',
MASTER_LOG_POS=<log_pos>;
  1. Start the slave:
START SLAVE;
  1. Check the status of the slave:
SHOW SLAVE STATUS\G
  1. To set up SSL, create a SSL certificate:
sudo openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /etc/ssl/private/mariadb-cert.key -out /etc/ssl/certs/mariadb-cert.crt
  1. On the master server, open the MariaDB configuration file:
sudo nano

Leave a Comment