当前位置:网站首页>Mysql5 available clusters
Mysql5 available clusters
2022-06-09 05:25:00 【Anonymous s】
1. summary
We are thinking about MySQL High availability architecture of database , We should mainly consider the following aspects :
- If the database is down or accidentally interrupted , Can restore database availability as soon as possible , Reduce downtime as much as possible , Ensure that the business will not be interrupted due to database failure .
- For backup 、 The data of non primary node with read-only copy and other functions should be consistent with the data of primary node in real time or finally .
- When a database switch occurs in the business , The database content before and after the switch should be consistent , It will not affect the business because of missing or inconsistent data .
We won't discuss the high availability rating in detail here , This paper only discusses the advantages and disadvantages of common high availability solutions and the selection of high availability solutions .
2. High availability solution
2.1. Master slave or master master master semi synchronous replication
Using a two node database , Set up one-way or two-way semi synchronous replication . stay 5.7 In later versions , because lossless replication、logical The introduction of some new features such as multithreading replication , bring MySQL Native semi synchronous replication is more reliable .
Common architectures are as follows :

Usually with proxy、keepalived Third party software is used at the same time , It can be used to monitor the health of the database , It can also execute a series of administrative commands . If the main warehouse fails , After switching to the standby database, the database can still be used .
advantage :
- The architecture is relatively simple , Using native semi synchronous replication as the basis for data synchronization ;
- Two knots , There is no host selection problem after the host is down , Switch directly ;
- Two knots , Less resources are needed , Simple deployment ;
shortcoming :
- Completely dependent on semi synchronous replication , If semi synchronous replication degenerates to asynchronous replication , Data consistency cannot be guaranteed ;
- Need extra consideration haproxy、keepalived High Availability Mechanism of .
2.2. Semi synchronous replication optimization
The semi synchronous replication mechanism is reliable . If semi synchronous replication is always in effect , Then the data can be considered consistent . But because of some objective reasons such as network fluctuation , Causes the semi synchronous replication to time out and switch to asynchronous replication , Then the consistency of the data cannot be guaranteed . So try to ensure semi synchronous replication as much as possible , Then you can improve the consistency of the data .
The scheme also uses a two node architecture , But on the basis of the original semi identical replication, the function is optimized , Make the mechanism of semi synchronous replication more reliable .
The reference optimization scheme is as follows :
2.2.1. Dual channel replication

Redeposit failed Upload again Cancel 
Semi synchronous replication due to timeout , Copy break , When replication is established again , Set up two channels at the same time , One of the semi synchronous replication channels starts at the current location , Ensure that the slave machine knows the progress of the current host execution . The asynchronous machine starts by catching up on another data channel . When the asynchronous replication channel catches up to the start of semi synchronous replication , Resume semi synchronous replication .
2.2.2. binlog File server

Build two semi synchronous replication channels , The semi synchronous channel connecting to the file server is not enabled normally , When the master-slave semi synchronous replication network problems degenerate , Start the semi synchronous replication channel with the file server . When the master-slave semi synchronous replication is restored , Close the semi synchronous replication channel with the file server .
advantage :
- Two knots , Less resources are needed , Simple deployment ;
- Simple architecture , There's no election question , Switch directly ;
- Compared to native replication , The optimized semi synchronous replication can ensure the consistency of data .
shortcoming :
- Need to modify the kernel source code or use mysql Communication protocol . Need to have a certain understanding of the source code , And can do a certain degree of secondary development .
- Still rely on semi synchronous replication , There is no fundamental solution to the problem of data consistency .
2.3. High availability architecture optimization
Extend dual node database to multi node database , Or a multi node database cluster . You can choose one master and two slaves according to your own needs 、 A cluster with one master and many slaves or a cluster with multiple masters and multiple slaves .
Because of semi synchronous replication , There is a feature that the successful semi synchronous replication is considered successful after receiving a successful response from a slave , Therefore, the reliability of multiple semi synchronous replication is better than that of single semi synchronous replication . And the probability of multi node downtime is less than that of single node , Therefore, to some extent, multi node architecture can be considered as better than dual node architecture .
But because of the large number of databases , So we need database management software to ensure the maintainability of the database . You can choose MMM、MHA Or various versions of proxy wait . Common solutions are as follows :
2.3.1. MHA+ Multi node cluster

MHA Manager It will detect the master node , When master Failure time , It can automatically send the latest data to slave Upgrade to a new master, And then put all the other slave Point back to the new master, The entire failover process is completely transparent to the application .
MHA Node Run on each MySQL Server , The main function is to process binary log when switching , Make sure to switch as little data as possible .
MHA It can also be extended to the following multi node clusters :

advantage :
- It can detect and transfer faults automatically ;
- Good scalability , It can be expanded as needed MySQL The number and structure of the nodes ;
- Compared to the two node MySQL Copy , Three nodes / Multinode MySQL The probability of unavailability is lower
shortcoming :
- At least three nodes are needed , It needs more resources than two nodes ;
- The logic is more complicated , Troubleshooting after failure , Positioning is more difficult ;
- Data consistency is still guaranteed by native semi synchronous replication , There is still a risk of data inconsistency ;
- It may be because of the split brain phenomenon in the network partition ;
2.3.2. zookeeper+proxy
Zookeeper Using distributed algorithm to ensure the consistency of cluster data , Use zookeeper Can effectively guarantee proxy High availability , Can better avoid network partition phenomenon .

advantage :
- Better guarantee the high availability of the whole system , Include proxy、MySQL;
- Good expansibility , It can be expanded into large-scale clusters ;
shortcoming :
- Data consistency still depends on native mysql Semi-synchronous replication ;
- introduce zk, The logic of the whole system becomes more complicated ;
2.4. Shared memory
Shared storage realizes the decoupling of database server and storage device , Data synchronization between different databases no longer depends on MySQL The native copy function of , But by means of disk data synchronization , To ensure data consistency .
2.4.1. SAN Shared storage
SAN The concept of processors and storage devices is allowed to ( The server ) Between the establishment of a direct high-speed network ( And LAN comparison ) Connect , Through this connection, data can be stored in a centralized way . The common architectures are as follows :

When using shared storage ,MySQL The server can mount the file system and operate normally , If the master database goes down , The standby database can mount the same file system , Ensure that the master database and the standby database use the same data .
advantage :
- Two nodes , Simple deployment , The switching logic is simple ;
- Good to ensure strong consistency of data ;
- Not because MySQL The data is inconsistent due to the logic error of ;
shortcoming :
- High availability of shared storage needs to be considered ;
- Expensive ;
2.4.2. DRBD Disk copy
DRBD It's software based 、 Network based block replication storage solution , It is mainly used for disks between servers 、 Partition 、 Logical volume and so on , When a user writes data to a local disk , It also sends data to the disk of another host in the network , Such a local host ( Master node ) With the remote host ( For the node ) To ensure real-time synchronization . The common architectures are as follows :

When something goes wrong with the local host , A copy of the same data remains on the remote host , Can continue to use , Data security is guaranteed .
DRBD yes linux Fast level synchronous replication technology implemented by kernel module , It can be done with SAN Achieve the same shared storage effect .
advantage :
- Two nodes , Simple deployment , The switching logic is simple ;
- Compared with SAN Storage network , The price is low ;
- Ensure strong consistency of data ;
shortcoming :
- Yes io High performance impact ;
- No read operation is provided from the library ;
2.5. Distributed protocol
Distributed protocol can solve the problem of data consistency . The common solutions are as follows :
2.5.1. MySQL cluster
MySQL cluster It is the deployment scheme of the official cluster , By using NDB The storage engine backs up redundant data in real time , Realize the high availability and data consistency of database .

advantage :
- All using official components , Don't rely on third-party software ;
- Can achieve strong consistency of data ;
shortcoming :
- Less used in China ;
- Complex configuration , Need to use NDB Storage engine , And MySQL There are some differences in conventional engines ;
- At least three nodes ;
2.5.2. Galera
be based on Galera Of MySQL High availability cluster , It's multi master data synchronization MySQL Clustering solutions , Easy to use , No single point of failure , High availability . Common architectures are as follows :

advantage :
- Multi master write , No delay replication , It can ensure strong data consistency ;
- There is a mature community , There are Internet companies using it on a large scale ;
- Automatic failover , Automatic addition 、 Remove nodes ;
shortcoming :
- Need to be native MySQL Node beating wsrep Patch
- Only support innodb Storage engine
- At least three nodes ;
2.5.3. POAXS
Paxos The algorithm solves the problem of how a distributed system works with respect to a certain value ( The resolution ) To reach an agreement . This algorithm is considered to be the most effective of its kind .Paxos And MySQL It can be realized in distributed MySQL Strong consistency of data . Common architectures are as follows :

advantage :
- Multi master write , No delay replication , It can ensure strong data consistency ;
- There is a mature theoretical basis ;
- Automatic failover , Automatic addition 、 Remove nodes ;
shortcoming :
- Only support innodb Storage engine
- At least three nodes ;
3. summary
With the increasing demand for data consistency , More and more methods are being used to solve the problem of distributed data consistency , Such as MySQL Self optimization 、MySQL Optimization of cluster architecture 、Paxos、Raft、2PC The introduction of algorithm and so on .
And using distributed algorithms to solve MySQL Database data consistency problem method , More and more people accept it , A series of mature products such as PhxSQL、MariaDB Galera Cluster、Percona XtraDB Cluster More and more are being used on a large scale .
With the official MySQL Group Replication Of GA, Using distributed protocol to solve the problem of data consistency has become the mainstream direction . Expect more and more excellent solutions to be presented ,MySQL High availability problems can be better solved .
reference
[2015 OTN] Peng Lixun -DoubleBinlog programme .pdf
边栏推荐
- “Ran out of input” while use WikiExtractor
- In 2022, the database audit manufacturer will choose cloud housekeeper! Powerful!
- Myql error expression 1 of select list is not in group by claim and contains nonaggregated column
- 爬取html入mysql插入失败
- Sonarlint代码规范改造实践及一些想法
- array
- The 27th issue of product weekly report | members' new interests of black users; CSDN app v5.1.0 release
- Recommend this UI automation testing framework and write use cases as colloquially as possible
- ^25 processes and threads
- Camtasia studio2022 free key serial number installation trial detailed graphic tutorial
猜你喜欢

IP address division and subnet

2022焊工(初级)特种作业证考试题库及模拟考试

Windows10 installs both MySQL 5 and MySQL 8

Alibaba cloud AI training camp - machine learning 3:lightgbm

Pull down the new project code and make it red

ps如何给图像加边框

2022 welder (elementary) special operation certificate examination question bank and simulation examination

Windows uses php to start ThinkPHP project and deploy configuration

Apache Devlake 代码库导览

Design owlook network novel recommendation system
随机推荐
When classical music meets NFT
How WPS ppt pictures come out one by one
Pattern recognition big job PCA & Fisher & KNN & kmeans
Test question bank and online simulation test for operation certificate of main principals of hazardous chemical business units in 2022
Remove duplicates from sort array -leetcode
Lighting - 光的亮度衰减
Thinking about global exception capture - real global exception capture
[django learning notes - 12]: database operation
SQL optimization notes - forward
Why do I need a thread pool? What is pooling technology?
Deque of STL
Rsync synchronous backup
^25进程与线程
Load research of Marathon LB
IP address division and subnet
Product weekly report issue 28 | CSDN editor upgrade, adding the function of inserting existing videos
Three paradigms of database
Cuijian hasn't changed. BAIC Jihu should make a change
AQS 之 CountdownLatch 源码分析
2022 "Cyberspace Security" event module B of Jiangxi secondary vocational group - SQL injection test