MariaDB Master-to-Master Replication Setup Guide on RHEL
Configuring a MariaDB Master-to-Master replication on RHEL 8 involves several steps. Below is a comprehensive guide that you can use for your blog, including tips and tricks to ensure a smooth setup:
### Pre-requisites:
1. **Two RHEL 8 Servers:** Ensure each server has MariaDB installed.
2. **Network Connectivity:** Both servers should be able to communicate with each other.
3. **Identical MariaDB Versions:** Ensure MariaDB versions are the same on both servers.
4. **Secure Environment:** Consider using a VPN or private networking for security.
### Step-by-Step Configuration:
#### Step 1: Configure MariaDB on Both Servers
1. **Edit MariaDB Configuration:**
- Open `/etc/my.cnf.d/mariadb-server.cnf` on both servers.
- Set `server-id` to a unique value (e.g., 1 on the first server and 2 on the second).
- Enable binary logging by adding `log-bin`.
- Optionally, set `binlog_do_db` to specify databases to replicate.
- Configure `bind-address` to the server's IP address for network accessibility.
2. **Restart MariaDB:**
- Run `systemctl restart mariadb` to apply changes.
#### Step 2: Create Replication User on Both Servers
1. **Log in to MariaDB:** Use `mysql -u root -p`.
2. **Create a Replication User:**
- Run `CREATE USER 'replicator'@'%' IDENTIFIED BY 'password';`.
- Grant replication privileges: `GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';`.
- Flush privileges: `FLUSH PRIVILEGES;`.
#### Step 3: Obtain Binary Log Coordinates
1. **On both servers**, run `SHOW MASTER STATUS;`.
2. **Record the `File` and `Position` values.** You'll need these for the next steps.
#### Step 4: Configure Replication
1. **On Server 1**, configure it to replicate from Server 2:
- Run `CHANGE MASTER TO MASTER_HOST='server2_ip', MASTER_USER='replicator', MASTER_PASSWORD='password', MASTER_LOG_FILE='recorded_file_from_server_2', MASTER_LOG_POS=recorded_position_from_server_2;`.
2. **On Server 2**, configure it to replicate from Server 1 using the same method.
3. **Start Replication:**
- Run `START SLAVE;` on both servers.
#### Step 5: Verify Replication
1. **Check Replication Status:**
- Use `SHOW SLAVE STATUS\G;`.
- Ensure `Slave_IO_Running` and `Slave_SQL_Running` are set to `Yes`.
### Tips and Tricks:
- **Data Consistency:** Ensure data consistency before starting replication.
- **Firewall Configuration:** Adjust firewalls to allow traffic on MariaDB port (default 3306).
- **Regular Backups:** Implement a backup strategy for your databases.
- **Monitoring:** Use tools to monitor replication and database performance.
- **Testing:** Test failover scenarios to ensure high availability.
### Troubleshooting:
- **Replication Errors:** Check MariaDB logs for any replication errors.
- **Connection Issues:** Verify network connectivity and firewall settings.
- **Data Synchronization:** Ensure initial data on both servers is identical.
### Conclusion
Master-to-Master replication in MariaDB on RHEL 8 can significantly enhance database availability and redundancy. Regular monitoring and proper security measures are crucial for maintaining a healthy replication environment.
0 Comments