Setting up MariaDB Master-Slave replication with SSL on Ubuntu Linux involves the following steps:
- Install MariaDB on both the master and the slave servers.
- On the master server, open the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
- Add the following lines to the file:
server-id = 1
log_bin = /var/log/mysql/mariadb-bin.log
bind-address = <master_server_ip>
- Save and close the file.
- Restart MariaDB:
sudo systemctl restart mariadb
- Log in to the MariaDB shell:
sudo mysql
- 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>';
- Flush the privileges:
FLUSH PRIVILEGES;
- Take a backup of the master server’s databases:
mysqldump --all-databases --master-data > dump.sql
- On the slave server, open the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
- Add the following lines to the file:
server-id = 2
relay-log = /var/log/mysql/mariadb-relay-bin.log
bind-address = <slave_server_ip>
- Save and close the file.
- Restart MariaDB:
sudo systemctl restart mariadb
- Log in to the MariaDB shell:
sudo mysql
- Import the backup:
source dump.sql
- 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>;
- Start the slave:
START SLAVE;
- Check the status of the slave:
SHOW SLAVE STATUS\G
- 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
- On the master server, open the MariaDB configuration file:
sudo nano