Table of Contents
1. Overview
2. High availability solution
2.1. Master-slave or master-master semi-synchronous replication
2.2. Semi-synchronous replication optimization
2.2.1. Dual-channel replication
2.2.2. binlog file server
2.3. High-availability architecture optimization
2.3.1. MHA multi-node cluster
2.3.2. zookeeper proxy
2.4. Shared storage
2.4.1. SAN shared storage
2.4.2. DRBD disk replication
2.5. Distributed protocol
2.5.1. MySQL cluster
2.5.2. Galera
2.5.3. POAXS
3. Summary
Home Database Mysql Tutorial Organize and summarize five common MySQL high availability solutions

Organize and summarize five common MySQL high availability solutions

May 31, 2022 am 11:56 AM
mysql

This article brings you relevant knowledge about mysql, which mainly introduces issues related to common high-availability solutions. Here we only discuss the advantages and disadvantages of commonly used high-availability solutions and high availability. Let’s take a look at the selection of solutions. I hope it will be helpful to everyone.

Organize and summarize five common MySQL high availability solutions

Recommended learning: mysql video tutorial

1. Overview

We are considering the high availability of MySQL database When designing the architecture, we should mainly consider the following aspects:

  • If the database is down or unexpectedly interrupted, the availability of the database can be restored as soon as possible, and the downtime can be reduced as much as possible to ensure that the business will not Interrupted due to database failure.
  • The data of non-primary nodes used for functions such as backup and read-only replicas should be consistent with the data of the primary node in real time or eventually.
  • When a database switch occurs in the business, the database contents before and after the switch should be consistent, and the business will not be affected due to missing data or inconsistent data.

We will not discuss the classification of high availability in detail here. We will only discuss the advantages and disadvantages of commonly used high availability solutions and the selection of high availability solutions.

2. High availability solution

2.1. Master-slave or master-master semi-synchronous replication

Use a two-node database to build one-way or two-way semi-synchronous replication. In versions after 5.7, the introduction of a series of new features such as lossless replication and logical multi-threaded replication makes MySQL's native semi-synchronous replication more reliable.

The common architecture is as follows:
Organize and summarize five common MySQL high availability solutions
It is usually used together with third-party software such as proxy and keepalived. It can be used to monitor the health of the database and execute a series of management commands. If the primary database fails, the database can still be used after switching to the standby database.

Advantages:

  • The architecture is relatively simple, using native semi-synchronous replication as the basis for data synchronization;
  • Dual-node, there is no master selection problem after the host goes down. , you can switch directly;
  • Dual nodes require less resources and are simple to deploy;

Disadvantages:

  • Completely relies on semi-synchronous replication. If Semi-synchronous replication degenerates into asynchronous replication, and data consistency cannot be guaranteed;
  • It is necessary to additionally consider the high availability mechanisms of haproxy and keepalived.

2.2. Semi-synchronous replication optimization

The semi-synchronous replication mechanism is reliable. If semi-synchronous replication is always in effect, the data can be considered consistent. However, due to some objective reasons such as network fluctuations, semi-synchronous replication times out and switches to asynchronous replication. In this case, data consistency cannot be guaranteed. Therefore, ensuring semi-synchronous replication as much as possible can improve data consistency.

This solution also uses a two-node architecture, but has functional optimizations based on the original semi-synchronous replication, making the semi-synchronous replication mechanism more reliable.

The optimization solutions that can be referred to are as follows:

2.2.1. Dual-channel replication

Organize and summarize five common MySQL high availability solutions
Semi-synchronous replication times out due to Afterwards, the replication is disconnected. When replication is established again, two channels are established at the same time. One of the semi-synchronous replication channels starts replicating from the current position to ensure that the slave knows the progress of the current host execution. Another asynchronous replication channel begins to catch up with the lagging data of the slave. When the asynchronous replication channel catches up to the starting position of semi-synchronous replication, semi-synchronous replication is resumed.

2.2.2. binlog file server

2.2.2. binlog文件服务器

Build two semi-synchronous replication channels, including the semi-synchronous channel connected to the file server It is not enabled under normal circumstances. When the master-slave semi-synchronous replication is degraded due to network problems, the semi-synchronous replication channel with the file server is started. After the master-slave semi-synchronous replication resumes, close the semi-synchronous replication channel with the file server.

Advantages:

Dual nodes require less resources and are simple to deploy;
The architecture is simple, there is no problem of selecting the master, just switch directly;
Compared with native replication, Optimized semi-synchronous replication can better ensure data consistency.

Disadvantages:

Need to modify the kernel source code or use the mysql communication protocol. You need to have a certain understanding of the source code and be able to do a certain degree of secondary development.
Still relies on semi-synchronous replication, which does not fundamentally solve the data consistency problem.

2.3. High-availability architecture optimization

Expand the dual-node database to a multi-node database or a multi-node database cluster. You can choose a cluster with one master and two slaves, one master and multiple slaves, or multiple masters and multiple slaves according to your needs.

Due to semi-synchronous replication, there is a feature that semi-synchronous replication is considered successful when a successful response from a slave is received, so the reliability of multi-slave semi-synchronous replication is better than the reliability of single-slave semi-synchronous replication. Moreover, the probability of multiple nodes going down at the same time is less than the probability of a single node going down. Therefore, to a certain extent, the multi-node architecture can be considered to have better high availability than the dual-node architecture.

However, due to the large number of databases, database management software is needed to ensure the maintainability of the database. You can choose MMM, MHA or various versions of proxy, etc. Common solutions are as follows:

2.3.1. MHA multi-node cluster

Organize and summarize five common MySQL high availability solutions
MHA Manager will regularly detect the master node in the cluster. When the master appears In the event of a failure, it can automatically promote the slave with the latest data to the new master, and then redirect all other slaves to the new master. The entire failover process is completely transparent to the application.

MHA Node runs on each MySQL server. Its main function is to process the binary log during switchover to ensure that the switchover minimizes data loss.

MHA can also be extended to the following multi-node clusters:
Organize and summarize five common MySQL high availability solutions
Advantages:

Can perform automatic detection and transfer of faults;
The scalability is relatively high Well, the number and structure of MySQL nodes can be expanded as needed;
Compared with two-node MySQL replication, three-node/multi-node MySQL has a lower probability of being unavailable

Disadvantages:

At least three nodes are required, which requires more resources than two nodes;
The logic is more complex, and it is more difficult to troubleshoot and locate problems after a failure occurs;
Data consistency is still guaranteed by native semi-synchronous replication. There is still a risk of data inconsistency;
Split-brain may occur due to network partitions;

2.3.2. zookeeper proxy

Zookeeper uses distributed algorithms to ensure clustering For data consistency, using zookeeper can effectively ensure the high availability of the proxy and better avoid network partitions.

Organize and summarize five common MySQL high availability solutions

Advantages:

Better guarantees the high availability of the entire system, including proxy, MySQL;
Good scalability, can be expanded to Large-scale cluster;

Disadvantages:

Data consistency still relies on native mysql semi-synchronous replication;
With the introduction of zk, the logic of the entire system becomes more complex;

2.4. Shared storage

Shared storage realizes the decoupling of database servers and storage devices. Data synchronization between different databases no longer relies on MySQL’s native replication function, but through disk data synchronization. , to ensure data consistency.

2.4.1. SAN shared storage

The concept of SAN allows a direct high-speed network to be established between storage devices and processors (servers) (compared to LAN ) connection, through which centralized storage of data is achieved. Commonly used architectures are as follows:

Organize and summarize five common MySQL high availability solutions
When using shared storage, the MySQL server can mount the file system normally and operate it. If the main database goes down, the standby database can mount the same file system, ensuring The primary database and the standby database use the same data.

Advantages:

Two nodes are enough, simple deployment, simple switching logic;
Good guarantee of strong consistency of data;
No logical errors will occur due to MySQL Data inconsistency;

Disadvantages:

Need to consider the high availability of shared storage;
Expensive;

2.4.2. DRBD disk replication

DRBD is a software-based, network-based block replication storage solution. It is mainly used for data mirroring of disks, partitions, logical volumes, etc. between servers. When users write data locally When the disk is connected, the data will also be sent to the disk of another host in the network, so that the data of the local host (primary node) and the remote host (standby node) can be synchronized in real time. The commonly used architecture is as follows:
Organize and summarize five common MySQL high availability solutions

When a problem occurs on the local host, a copy of the same data is still retained on the remote host and can continue to be used, ensuring data security.

DRBD is a fast-level synchronous replication technology implemented by the Linux kernel module, which can achieve the same shared storage effect as SAN.

Advantages:

Only two nodes are needed, simple deployment and simple switching logic;
Compared with SAN storage network, the price is low;
Ensure strong consistency of data;

Disadvantages:

Has a greater impact on io performance;
The slave library does not provide read operations;

2.5. Distributed protocol

Distributed protocol It can solve the problem of data consistency very well. The more common solutions are as follows:

2.5.1. MySQL cluster

MySQL cluster is the official cluster deployment solution. It uses the NDB storage engine to back up redundant data in real time to achieve high availability and data consistency of the database. .
Organize and summarize five common MySQL high availability solutions

Advantages:

All use official components and do not rely on third-party software;
Can achieve strong consistency of data;

Disadvantages :

It is rarely used in China;
The configuration is more complex and requires the use of NDB storage engine, which is somewhat different from the regular MySQL engine;
At least three nodes;

2.5.2. Galera

MySQL high-availability cluster based on Galera is a MySQL cluster solution for multi-master data synchronization. It is simple to use, has no single point of failure, and has high availability. Common architectures are as follows:

Organize and summarize five common MySQL high availability solutions

Advantages:

Multi-master writing, no-delay replication, ensuring strong data consistency;
There is a mature community , used by Internet companies on a large scale;
Automatic failover, automatic addition and removal of nodes;

Disadvantages:

Requires wsrep patching for native MySQL nodes
Only supported innodb storage engine
At least three nodes;

2.5.3. POAXS

The problem solved by the Paxos algorithm is how a distributed system reaches a consensus on a certain value (resolution). This algorithm is considered the most efficient of its kind. The combination of Paxos and MySQL can achieve strong consistency in distributed MySQL data. Common architectures are as follows:

Organize and summarize five common MySQL high availability solutions
Advantages:

Multi-master writing, no-delay replication, ensuring strong data consistency;
Has a mature theoretical basis;
Automatic failover, automatic addition and removal of nodes;

Disadvantages:

Only supports innodb storage engine
At least three nodes;

3. Summary

As people's requirements for data consistency continue to increase, more and more methods are being tried to solve the problem of distributed data consistency, such as the optimization of MySQL itself, the optimization of MySQL cluster architecture, Paxos, Raft, The introduction of 2PC algorithm and so on.

The method of using distributed algorithms to solve the problem of MySQL database data consistency is becoming more and more accepted by people. A series of mature products such as PhxSQL, MariaDB Galera Cluster, Percona XtraDB Cluster, etc. are becoming more and more popular. It is increasingly being used on a large scale.

With the official GA of MySQL Group Replication, using distributed protocols to solve data consistency problems has become a mainstream direction. It is expected that more and more excellent solutions will be proposed, and the MySQL high availability problem can be better solved.

Recommended learning: mysql video tutorial

The above is the detailed content of Organize and summarize five common MySQL high availability solutions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

See all articles