IT Log

Record various IT issues and difficulties.

Linux MySQL 5.7 Master-Slave Replication Setup Guide: One Master Multiple Slaves


  

🏡Author’s Homepage:Click Here

🐧Linux Basics (Beginner):Click Here

🐧Advanced Linux Management, Protection, and Clustering:Click Here

🔐Firewalld Firewall in Linux:Click Here

⏰️ Creation Time: July 24, 2024 at 2:10 PM

🀄️ Article Quality: 93 points


Table of Contents

1. All Node Configuration

Establishing Time Synchronization Environment

Main Node

Secondary Node

2.MySQL Database Installation

3.Configuring Traditional Replication with Single Master

Master Server (Master 1)

Slave Server (Master 2)

4.Testing Master-Slave Synchronization


🔥Cool Website Recommendations🔥

A few days ago, I came across an outstanding 🤖 artificial intelligence learning website. It’s easy to understand, funny and engaging, so I couldn’t help but share it with everyone. Whether you’re interested in AI or machine algorithms, this site is worth checking out. Click here to visit! https://www.captainbed.cn/sis

 🔥Office AI Tool Recommendations🔥

BaoYueAI – Your Intelligent AI Reading AssistantBaoYueAI is your intelligent AI reading assistant. It supports one-click summaries, AI Q&A, multi-language translation, and works with web reading, academic papers, legal documents, research reports, product manuals, market analysis, eBooks, and more. BaoYueAI helps you read broadly, understand deeply, and work efficiently.icon-default.png?t=O83Ahttps://baoyueai.com/?utm_id=237582

Click on the above link to redirect to the official website


1. All node configurations

  1. Configure IP address, gateway, DNS, and hostname
    Set up network-related information through appropriate configuration files or commands to ensure proper communication between all nodes.

  2. Stop and disable the firewall

    These commands are used to shut down SELinux and the firewall to prevent them from blocking communication between nodes.

  3. Download required components

    Install development tools and file transfer tools to ensure the system has the necessary development and transfer environment.

Build time-synchronized environment
Main node
  1. Install NTP

    Install the NTP service to ensure time synchronization.

  2. Configure NTP

    Add the following two lines:

    Configure NTP service to use local time as a reference.

  3. Restart service and set to start automatically on boot

    Restart the NTP service and set it to start automatically at boot to ensure continuous operation of the time synchronization service.

From Node
  1. Install ntpdate

    Install the ntpdate tool to manually synchronize time.

  2. Synchronize Time

    Use NTP server IP to synchronize time. For example:

Lingban AI Free ChatGPT4 Artificial Intelligence Browser Plugin (Multi-functional)

Open MethodClick!icon-default.png?t=O83Ahttps://ilingban.com/browser_extension?from=smqnz

(Click to add to Edge browser), very convenient! You can try it!

2.MySQL Database Installation

  1. Download MySQL 5.7.29 installer package

    Download the official MySQL installation package from the source.

  2. Extract and create MySQL yum repository

    Extract the installation package and create a local YUM repository.

  3. Configure yum repository

    Configure the local YUM repository for subsequent installation.

  4. Refresh yum and install MySQL server

    Install the MySQL server.

  5. Start and change default management password

    [/crayon]

    Start MySQL and change the default management password.

mysqladmin uroot p password “Abc-1234”  // Change the default password using Abc-1234

Start the MySQL service and change the default root user password.

3. Configure Traditional Replication Single Master

Master Server (master1)
  1. Edit MySQL configuration file

    Add the following content:

    Set server ID and enable binary logging.

  2. Restart MySQL service

    Restart the MySQL service to apply configuration changes.

  3. Create a user with replication permissions

    Create a user for replication and grant necessary permissions.

  4. View master server status

    Obtain binary log file and position to configure the slave server.

From Server (master2)
  1. Edit MySQL Configuration File

    Add the following content:

    Set the slave server ID.

  2. Restart MySQL Service

    Restart the MySQL service to apply configuration changes.

  3. Connect to Master Server

    Configure the slave server’s replication information based on the master server status.

  4. Start Slave Server

  5. Check Slave Status

    Check the slave server replication status to ensure successful connection and synchronization.

4. Testing Master-Slave Synchronization

Create the database and table on the master server, and insert data:

Check if the data is synchronized on the slave server:

The above operations ensure that the data on the master server is successfully replicated to the slave server, achieving master-slave synchronization.

Summary

Through this article’s introduction, we have successfully configured MySQL database master-slave replication on a Linux system, ensuring real-time data synchronization and backup. This not only improves data security but also provides convenience for future expansion and maintenance. We hope readers can apply the knowledge learned to further explore and optimize their own database management solutions, laying a solid foundation for more efficient business operations.

There are no shortcuts on the road to success; only continuous effort and perseverance. If you believe, like me, that effort brings rewards, please follow me, give me a thumbs-up, and embrace an even brighter tomorrow together!

“Every creation is a learning process. If there are shortcomings in this article, please understand. Your support and encouragement are my greatest motivation. Welcome to share your valuable opinions and suggestions to help me improve continuously.”

The Enigmatic Crying Man


, , , , , , , , ,

10 responses to “Linux MySQL 5.7 Master-Slave Replication Setup Guide: One Master Multiple Slaves”

  1. Thanks for sharing such a comprehensive guide! The tips on testing master-slave synchronization were invaluable for ensuring everything works smoothly.

  2. The step-by-step approach made the complex process of MySQL replication feel manageable. I’ll definitely refer back to this guide if I run into issues.

  3. This guide not only taught me how to set up master-slave replication but also introduced me to useful AI tools like BaoYueAI and Lingban AI.

  4. The part about configuring NTP was something I wasn’t sure about, but this guide clarified everything. Highly recommended!

  5. I appreciated the emphasis on disabling firewalls and SELinux temporarily during setup. It saved me from a lot of headaches!

  6. This article is perfect for Linux beginners like me. The clear instructions and commands helped me avoid common pitfalls during setup.

  7. The guide made me realize how important time synchronization is for database replication. I’ll make sure to set that up properly next time.

  8. Great resource for anyone looking to implement traditional replication in MySQL 5.7. The section on creating a replication user was particularly useful.

  9. Thanks to this article, I successfully configured my first MySQL master-slave setup. The tips on firewall and SELinux settings were crucial and not mentioned elsewhere!

  10. This guide was incredibly helpful for setting up MySQL 5.7 master-slave replication. The step-by-step instructions made it easy to follow, especially the part about time synchronization which I initially overlooked.

Leave a Reply