Home > Article > Operation and Maintenance > How to configure a highly available database cluster on Linux
How to configure a high-availability database cluster on Linux
1. Introduction
With the continuous growth of enterprise data, the high availability of databases has become more and more important. Highly available database clusters can provide continuous and reliable data access to ensure continuous business operation. This article will introduce how to configure a high-availability database cluster on the Linux operating system and provide corresponding code examples.
2. Preparation work
Before you start configuring a high-availability database cluster, you first need to do some preparation work.
3. Configuring the database cluster
The following introduces a common database cluster architecture-the master-slave replication mode. One node is the master node, responsible for processing read and write requests, and the other nodes are backup Node for data backup and failover.
Edit the database configuration file my.cnf and find the following section:
[mysqld] server-id=1 log-bin=mysql-bin
Set server-id to a unique value to identify the master node.
Restart the database service:
service mysql restart
Edit the database configuration file my.cnf and find the following section:
[mysqld] server-id=2 log-bin=mysql-bin
Set server-id to a unique value to identify the standby node.
Restart the database service:
service mysql restart
GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'备节点IP' IDENTIFIED BY '密码'; FLUSH PRIVILEGES;
Replace replication_user with the actual Database user name, replace the standby node IP with the actual IP address of the standby node, and set a password.
Execute the following command on the standby node:
CHANGE MASTER TO MASTER_HOST='主节点IP', MASTER_USER='replication_user', MASTER_PASSWORD='密码', MASTER_LOG_FILE='主节点的binlog文件名', MASTER_LOG_POS=主节点的binlog文件位置; START SLAVE;
Replace the primary node IP with the actual IP address of the primary node, replace replication_user and password with the actual database user name and password, and replace the primary node IP with the actual IP address of the primary node. Replace the binlog file name and location with actual values.
Execute the following command on the standby node:
STOP SLAVE; RESET MASTER;
Edit the database configuration file my.cnf on the standby node and comment out the following lines:
# server-id=2 # log-bin=mysql-bin
Then Restart the database service:
service mysql restart
Now the standby node will become the new primary node, and other standby nodes can be configured as new standby nodes according to the same steps.
4. Summary
Through the above steps, we successfully configured a high-availability database cluster based on the active-standby replication mode, ensuring continuous and reliable access to data. I hope this article can provide some help to readers in configuring a high-availability database cluster on Linux. If you have any questions, please refer to relevant official documents or consult professionals.
The above is the detailed content of How to configure a highly available database cluster on Linux. For more information, please follow other related articles on the PHP Chinese website!