MasterIP: 192.168.43.100
SlaveIP: 192.168.43.101
ReplicationUser: replicator
If MySQL is not already installed, install it using the following commands on both servers:
sudo dnf install @mysql
sudo systemctl start mysqld
sudo systemctl enable mysqld
- Edit the MySQL configuration file (
/etc/my.cnf
or/etc/my.cnf.d/server.cnf
):
sudo nano /etc/my.cnf
- Add the following lines to configure the master server:
[mysqld]
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
bind-address = 192.168.43.100
- Restart MySQL to apply the changes:
sudo systemctl restart mysqld
- Create a replication user on the master server:
mysql -u root -p
CREATE USER 'replicator'@'192.168.43.101' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'192.168.43.101';
FLUSH PRIVILEGES;
- Lock the master database and get the binary log file and position:
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
Note the File
and Position
values. You will need these for the slave configuration. Keep the session open to maintain the lock.
- Edit the MySQL configuration file on the slave server (
/etc/my.cnf
or/etc/my.cnf.d/server.cnf
):
sudo nano /etc/my.cnf
- Add the following lines to configure the slave server:
[mysqld]
server-id = 2
relay-log = /var/log/mysql/mysql-relay-bin.log
bind-address = 192.168.43.101
- Restart MySQL to apply the changes:
sudo systemctl restart mysqld
- Configure the slave server to connect to the master:
mysql -u root -p
CHANGE MASTER TO
MASTER_HOST='192.168.43.100',
MASTER_USER='replicator',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000001', # Use the File value from SHOW MASTER STATUS
MASTER_LOG_POS=123; # Use the Position value from SHOW MASTER STATUS
- Start the slave replication:
START SLAVE;
- Verify the replication status:
SHOW SLAVE STATUS\G
Look for Slave_IO_Running
and Slave_SQL_Running
both being Yes
.
After setting up the slave, you can unlock the master database:
UNLOCK TABLES;
On the master server, make some changes (e.g., insert data into any database), and verify that these changes appear on the slave server.
- Check MySQL logs on both servers for errors (
/var/log/mysqld.log
). - Ensure network connectivity between master and slave.
- Check firewall rules to ensure that the slave can connect to the master on the MySQL port (default is 3306).
- Use SSL/TLS for secure replication traffic.
- Monitor replication to ensure it is working as expected.
- Consider additional configurations for performance tuning and failover scenarios.
This updated setup will bind the MySQL server on the master to IP 192.168.43.100
and on the slave to IP 192.168.43.101
, ensuring proper network configuration for replication.