🏡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
Establishing Time Synchronization Environment
3.Configuring Traditional Replication with Single Master
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🔥
Click on the above link to redirect to the official website
1. All node configurations
-
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. -
Stop and disable the firewall
123setenforce 0systemctl stop firewalldsystemctl disable firewalldThese commands are used to shut down SELinux and the firewall to prevent them from blocking communication between nodes.
-
Download required components
123setenforce 0systemctl stop firewalldsystemctl disable firewalldInstall development tools and file transfer tools to ensure the system has the necessary development and transfer environment.
Build time-synchronized environment
Main node
-
Install NTP
123setenforce 0systemctl stop firewalldsystemctl disable firewalldInstall the NTP service to ensure time synchronization.
-
Configure NTP
123setenforce 0systemctl stop firewalldsystemctl disable firewalldAdd the following two lines:
123setenforce 0systemctl stop firewalldsystemctl disable firewalldConfigure NTP service to use local time as a reference.
-
Restart service and set to start automatically on boot
123systemctl restart ntpd<pre>systemctl enable ntpdRestart the NTP service and set it to start automatically at boot to ensure continuous operation of the time synchronization service.
From Node
-
Install ntpdate
1yum install –y ntpdateInstall the ntpdate tool to manually synchronize time.
-
Synchronize Time
1yum install –y ntpdateUse NTP server IP to synchronize time. For example:
1yum install –y ntpdate
Lingban AI Free ChatGPT4 Artificial Intelligence Browser Plugin (Multi-functional)
Open Method:Click!https://ilingban.com/browser_extension?from=smqnz
(Click to add to Edge browser), very convenient! You can try it!
2.MySQL Database Installation
-
Download MySQL 5.7.29 installer package
1wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tarDownload the official MySQL installation package from the source.
-
Extract and create MySQL yum repository
1wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tarExtract the installation package and create a local YUM repository.
-
Configure yum repository
1wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tarConfigure the local YUM repository for subsequent installation.
-
Refresh yum and install MySQL server
1wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29-1.el7.x86_64.rpm-bundle.tarInstall the MySQL server.
-
Start and change default management password
12[crayon–67f9d6a5deabf725806065 inline=“true” class=“language-bash”]systemctl start mysqldgrep “password” /var/log/mysqld.log //Get default 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)
-
Edit MySQL configuration file
1vim /etc/my.cnfAdd the following content:
1vim /etc/my.cnfSet server ID and enable binary logging.
-
Restart MySQL service
1vim /etc/my.cnfRestart the MySQL service to apply configuration changes.
-
Create a user with replication permissions
1vim /etc/my.cnfCreate a user for replication and grant necessary permissions.
-
View master server status
1vim /etc/my.cnfObtain binary log file and position to configure the slave server.
From Server (master2)
-
Edit MySQL Configuration File
1vim /etc/my.cnfAdd the following content:
1vim /etc/my.cnfSet the slave server ID.
-
Restart MySQL Service
1systemctl restart mysqldRestart the MySQL service to apply configuration changes.
-
Connect to Master Server
1mysql –u username –pConfigure the slave server’s replication information based on the master server status.
-
Start Slave Server
1systemctl start mysqld -
Check Slave Status
1mysql –u username –pCheck 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:
1 2 3 4 5 6 7 8 9 10 |
mysql> create database smqnz; mysql> use smqnz; mysql> create table test(age int); mysql> insert into test values(1); mysql> select * from test; +———+ | age | +———+ | 1 | +———+ |
Check if the data is synchronized on the slave server:
1 2 3 4 5 6 7 8 9 10 |
mysql> create database smqnz; mysql> use smqnz; mysql> create table test(age int); mysql> insert into test values(1); mysql> select * from test; +———+ | age | +———+ | 1 | +———+ |
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
Leave a Reply
You must be logged in to post a comment.