Configuring MySQL Cluster (Debian 11)
Part 1: Install MySQL Server (Do this on Server 4, 5 and 6)
1. Install Mariadb Server Packages
apt update
apt install mariadb-server -y
2. Run the security script to enhance MySQL security:
mysql_secure_installation
Press enter when prompted for root password.
Select n when prompted to Switch to unix_socket authentication [Y/n]
Select Y when prompted to Change the root password? [Y/n]
Make sure to set the root password (e.g. imsql)
Select Y when prompted to Remove anonymous users? [Y/n]
Select Y when prompted to Disallow root login remotely? [Y/n]
Select Y when prompted to Remove test database and access to it? [Y/n]
Select Y when prompted to Reload privilege tables now? [Y/n]
Part 2: Configure the Master (Do this on Server 4)
3. Navigate to the working directory:
cd /home/netadmin/Documents/
4. Edit the MySQL Configuration on the Master:
Prepared by Dr. Ozy on 22 September 2024
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Under [mysqld] change the bind address to listen to all interfaces
Set server_id and Enable Binary Logging. In the [mariadb] section, modify or add the
following:
5. Restart MariaDB:
systemctl restart mariadb
6. Log in to MariaDB as root and create a user for replication. You will need the MySQL root
password:
mariadb -u root -p
Run the following command in sequence to create a user named repl whose password is
imsrep:
CREATE USER 'repl'@'%' IDENTIFIED BY 'imsrep';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
FLUSH PRIVILEGES;
7. Lock the database to ensure data consistency for replication, and get File and Position
values for replication. Run the following commands while still logged into MySQL
Prepared by Dr. Ozy on 22 September 2024
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
Write down the file and position values: mariadb-bin.000001, 766
8. With the database still locked in the first terminal, open another Bash terminal and run the
to take a backup of the master database. You will be asked for MySQL root password:
mysqldump -u root -p --all-databases --master-data >
/home/netadmin/Documents/master-dump.sql
9. After the backup is complete, unlock the tables in the first Bash terminal:
UNLOCK TABLES;
10. Logout of MySQL using quit
11. Transfer the saved database to server 5 and 6
rsync -avz /home/netadmin/Documents/master-dump.sql
[email protected]:Documents/
rsync -avz /home/netadmin/Documents/master-dump.sql
[email protected]: Documents/
Part 2: Configure the Slaves (Do this on Server 5 and 6)
Do this on Server 5
12. Open the MariaDB configuration file:
nano /etc/mysql/mariadb.conf.d/50-server.cnf
Prepared by Dr. Ozy on 22 September 2024
13. Set a unique server_id. We use 2 since the master uses 1. In the [mariadb] section, modify
or add the following:
14. Restart MariaDB:
systemctl restart mariadb
15. Restore the Master Database on the Slave
mysql -u root -p < /home/netadmin/Documents/master-dump.sql
16. Configure the Slave to Start Replication. Log in to MariaDB as root – you will need the
MySQL root password.
mariadb -u root -p
17. Configure the slave for replication using this SQL command (Where 192.168.100.230 is
master server IP address. Master log file and pos are the values from SHOW MASTER
STATUS in step 7):
CHANGE MASTER TO MASTER_HOST='192.168.100.230', MASTER_USER='repl',
MASTER_PASSWORD=’imsrep’, MASTER_LOG_FILE='mariadb-bin.000001',
MASTER_LOG_POS= 766;
Start the slave
START SLAVE;
18. Check the slave status should display both slave_io and slave_sql as running:
SHOW SLAVE STATUS\G
Prepared by Dr. Ozy on 22 September 2024
19. Display the current databases on the slave using the following SQL command.
show databases;
20. Test that replication is working
Do this on Master (Server 4)
a. Log in to MariaDB as root and create a database. You will need the MySQL root
password:
mariadb -u root -p
b. First display the list of databases: show databases;
c. Then create a new database: create database cnstest;
d. Run show databases again. Can you see the databases added to master server?
Prepared by Dr. Ozy on 22 September 2024
Do this on slave (Server 5)
e. Repeat the command in step 19. Has the new database been replicated to the slave
server?
21. Configure the second slave server (Server 6). Repeat steps 12 to step 19.
Note: Use server_id = 3 in step 13.
22. Are all databases created on the Master server visible on the second slave?
23. If No in step (20.e) or step (22) you need to investigate the logs.
24. You can repeat step 20 by adding more databases, tables and even data into the tables and
verify all changes on the master are replicated to the slaves.
Prepared by Dr. Ozy on 22 September 2024