Method and equipment for realizing high availability of multi-node database and medium

By deploying a virtual IP address control program on MGR cluster nodes, the problem of application access failure during MGR cluster master database failover is solved, database high availability is improved, the architecture is simplified, and VIP drift and DNS cache resolution errors are avoided, achieving Provides applications with accurate and fast access to the database.

CN118535359APending Publication Date: 2024-08-23SHANDONG BRANCH OF BEST TONE INFORMATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410423588.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-09
Publication Date
2024-08-23

AI Technical Summary

Technical Problem

When the MGR cluster completes master database failover, applications that use Keepalived VIP or DNS domain names to access the database are prone to access failures, and the existing technology is susceptible to network jitters and DNS cache resolution errors.

Method used

By deploying a virtual IP address control program on each node, run the program regularly to determine whether the master database has switched, and perform the addition or deletion of the virtual IP address according to the situation, so that the virtual IP address is always on the master node to avoid VIP Drift and DNS resolution errors.

Benefits of technology

It enables applications to access the database accurately and quickly during MGR cluster master database failover, improves database high availability, avoids access failures caused by VIP drift and DNS cache parsing errors, simplifies the architecture and reduces resource usage costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535359A
    Figure CN118535359A
Patent Text Reader

Abstract

The invention relates to a multi-node database high availability implementation method and device and a medium, and the method comprises the following steps: S1, deploying MySQL databases at a plurality of nodes respectively to form a MySQL group replication cluster in a single master mode, the MySQL group replication cluster comprises a master database and a plurality of slave databases, and the nodes corresponding to the master database are master nodes; s2, an application program accesses the main database through a virtual IP address, a virtual IP address control program is deployed and regularly operated on each node, the virtual IP address control program is used for obtaining data of each node, whether the main database is switched or not is judged accordingly, virtual IP address adding or deleting operation is executed according to different conditions, and the main database is switched according to the virtual IP address. And enabling the virtual IP address to be always on the main node. Compared with the prior art, the problem that the application program fails to access the database under the condition that the MGR cluster completes the fault switching of the main database can be solved, and the high availability of the database is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of IT and software development technology, and in particular relates to a method, device and medium for realizing high availability of a multi-node database. Background Art

[0002] High availability is one of the technologies that database administrators focus on. It can avoid single point failures in the database and ensure the stability and availability of the database. The key technologies for database high availability include data synchronization between database nodes, automatic database failover, and unified access portal. As an open source relational database management system, MySQL has launched the MGR (MySQL Group Replication) group replication plug-in based on the Paxos protocol since version 5.7.17, which ensures that the data in all MySQLs in the same group remains consistent and has a conflict detection and resolution mechanism. MGR group replication provides single-master mode and multi-master mode deployment. The single-master mode includes a master database and several slave databases, which can provide the ability of automatic master selection and automatic failover. Therefore, the MGR cluster can provide data synchronization between database nodes and automatic database failover. Another important function in database high availability technology is the unified access portal, which provides transparent access to applications. Applications use the unified access portal to connect to the MySQL master database. When the MySQL master database fails, the unified access portal selects the slave database as the new master database to continue to provide services to the outside world. Using a unified access portal can prevent applications from modifying database connection configurations, which can be achieved through a variety of technologies, such as VIP (Virtual IP address) and DNS (Domain Name System).

[0003] Chinese patent application CN114035997A discloses a high-availability fault switching method based on MGR, in which an application is connected to an MGR database cluster through a Keepalived VIP. When the main database fails, the MGR cluster switches nodes in priority order, and Keepalived switches VIP in the same priority order, so that the application switches to use a new database. The problem with this solution is that the use of Keepalived is easily affected by network jitter problems. If Keepalived is in the startup state on multiple MGR cluster nodes, VIP will drift to other slave nodes, resulting in KeepalivedVIP and the MGR cluster master node not being on the same host. After the application accesses the VIP, the actual access is to the slave node read-only database, causing a business write error; another problem with this solution is that when the database on the MGR cluster master node fails, but the MGR cluster master node server and system are normal, if there is no management node to control the VIP, the Keepalived VIP will not switch, resulting in the Keepalived VIP and the MGR cluster master node not being on the same host. After the application accesses the VIP, the actual access is to the slave node read-only database, causing a business write error. Chinese patent application CN114546427A discloses a MySQL high availability implementation method based on DNS and MGR, which uses a probe to detect the running database MGR cluster, and judges whether the database cluster is running normally based on the database cluster, transaction accumulation and domain name IP information obtained by the detection. If a master node failure is found, in the failover process, the probe is used to judge whether the new master node transaction has been applied. If the transaction is applied, the probe is used to switch the DNS, map the domain name with the new IP, and verify the domain name and IP after the DNS switch is completed. Successful verification indicates that the failover is successful, and the application can automatically connect to the new master database. The problem with this solution is that the use of DNS is prone to client DNS cache resolution errors. The application client accesses the database through the domain name. If the domain name and IP address mapping information in the DNS cache on the application client is inconsistent with the updated DNS resolution information, if the DNS cache on the client is not expired, it will cause the application to fail to access the database.

[0004] In summary, when the MGR cluster completes the master database failover, the application will fail to access the database using KeepalivedVIP or DNS domain name. Therefore, it is necessary to design a database high availability implementation method to solve the problem of application access failure to the database when the MGR cluster completes the master database failover and improve the database high availability. Summary of the invention

[0005] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and to provide a multi-node database high availability implementation method, device and medium, to solve the problem of application program access failure to the database when the MGR cluster completes the primary database failover, and to improve the database high availability.

[0006] The purpose of the present invention can be achieved by the following technical solutions:

[0007] The present invention provides a method for realizing high availability of a multi-node database, comprising the following steps:

[0008] S1. Deploy MySQL databases on multiple nodes to form a MySQL group replication cluster in single-master mode, including a master database and several slave databases, where the node corresponding to the master database is the master node;

[0009] S2. The application accesses the main database through the virtual IP address. A virtual IP address control program is deployed and regularly run on each node. The virtual IP address control program is used to obtain data from each node, thereby determining whether the main database has been switched. The virtual IP address is added or deleted according to different situations, so that the virtual IP address is always on the main node.

[0010] Furthermore, in step S2, before running the virtual IP address control program, the database virtual IP address, host network card name, host name, database user and password are configured.

[0011] Furthermore, in step S2, the virtual IP address control program is run once per second by setting a scheduled task.

[0012] Furthermore, in step S2, the specific process of performing the virtual IP address addition or deletion operation according to different situations is as follows:

[0013] If the node is the master node and does not have a virtual IP address, and the node does not have a virtual IP address on the network, the virtual IP address addition operation is triggered, a virtual IP address is added to the host network card of the node, an address resolution protocol broadcast is performed externally, and a virtual IP address addition record is recorded in the output log;

[0014] If the node is not the master node and has a virtual IP address, the virtual IP address deletion operation is triggered to delete the virtual IP address on the host network card of the node, and a virtual IP address deletion record is recorded in the output log;

[0015] If other situations occur, the status quo is maintained without any processing, and a record indicating that the virtual IP address has not changed is recorded in the output log.

[0016] Furthermore, the output log includes the time when the virtual IP address is added or deleted.

[0017] Furthermore, after the master database fails, the MySQL group replication cluster promotes a slave database as a new master database to continue to provide read and write services to the outside world.

[0018] Furthermore, after a failure occurs in the master database or the slave database, a fault recovery operation is performed, and the specific process of the fault recovery operation is as follows: repair the operating system, network and database problems, start the MySQL database of the failed node and rejoin the MySQL group replication cluster, and after the failed node successfully joins, deploy and regularly run the virtual IP address control program.

[0019] Furthermore, the MySQL group replication cluster automatically completes the data synchronization operation of the newly added node.

[0020] The present invention also provides an electronic device, comprising a memory, a processor, and a program stored in the memory, wherein the processor implements the above method when executing the program.

[0021] The present invention also provides a computer-readable storage medium on which a computer program is stored, and the program implements the above method when executed by a processor.

[0022] Compared with the prior art, the present invention has the following beneficial effects:

[0023] 1. The present invention deploys MySQL databases on multiple nodes respectively to form a MySQL group replication cluster in a single-master mode, including a master database and several slave databases. The application program accesses the master database through a virtual IP address. A virtual IP address control program is deployed on each node and runs regularly. The virtual IP address control program is used to obtain data from each node, thereby determining whether the master database is switched. The virtual IP address is added or deleted according to different situations, so that the virtual IP address is always on the master node corresponding to the master database. The problem of Keepalived VIP drift between MySQL group replication cluster nodes in the existing method will not occur. When the master database fails to switch, the application program can accurately and quickly access the master database without modifying the configuration, thereby improving the high availability of the database.

[0024] 2. In the present invention, the application uses a virtual IP address to access the database, which can avoid the problem of DNS service unavailability and incorrect DNS configuration, and also avoid the problem of application access to the database failure caused by the IP mapped in the client DNS cache not being the main database node IP.

[0025] 3. The present invention has a simple architecture and is easy to maintain. It does not use or maintain other software and services (such as Keepalived and DNS), and will not be affected by problems with other software or services. The method of obtaining node data through the virtual IP address control program is controllable and the judgment logic is simple. It can be developed in different programming languages ​​and is easy to maintain.

[0026] 4. In the present invention, the virtual IP address control program shares server resources with the database, and does not generate additional resource usage costs. The virtual IP address control program uses small amounts of resources, does not save host data and database data, only performs simple result comparisons on partial data, and only saves virtual IP address operation logs, and does not compete for database resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 A topological diagram of a three-node database in an embodiment;

[0028] Figure 2 This is the flow chart of VIP control program;

[0029] Figure 3 Add a logic judgment flow chart for VIP deletion operations;

[0030] Figure 4 This is the logic judgment flow chart of the MGR cluster master database in MySQL5.7. DETAILED DESCRIPTION

[0031] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process, but the protection scope of the present invention is not limited to the following embodiments.

[0032] Example 1

[0033] This embodiment provides a method for implementing high availability of a multi-node database, including the following steps:

[0034] S1. Deploy, configure, and run a single-master MGR (MySQL Group Replication) cluster.

[0035] like Figure 1As shown, taking a three-node database as an example, refer to the MySQL8.0 official document, deploy MySQL8.0 software on three hosts with the same configuration, configure MySQL parameters and MGR parameters, initialize the MySQL instance, and use the MGR group replication plug-in to deploy the three nodes as a single-master mode MGR cluster, which contains a master database and two slave databases. At this time, the single-master mode MGR cluster is started successfully. After the MGR cluster is running, the first database to join the MGR cluster will become the master database, and the other databases will be read-only slave databases. When the master database of the MGR cluster fails, the MGR cluster will automatically select the master and automatically fail over. The MGR cluster will promote a slave database as the new master database to continue to provide read and write services to the outside world; when a slave database of the MGR cluster fails, it will not affect the use of the master database of the MGR cluster.

[0036] S2. Deploy, configure, and run the VIP control program.

[0037] The application accesses the main database through VIP (Virtual IP address). The VIP control program (i.e., virtual IP address control program) is deployed on each MGR cluster node. The VIP control program is run once a second through timed tasks and other methods. The VIP control program process is as follows: Figure 2 As shown, the following steps are included:

[0038] (1) Node information configuration: Before running the VIP control program, configure the database VIP, host network card name, host name, database user and password.

[0039] (2) Data acquisition: Data acquisition work is performed on each node of the database MGR cluster, including host data and database data.

[0040] Query the performance_schema.replication_group_members table. If the value of the MEMBER_ROLE column is PRIMARY, the value of the MEMBER_HOST column is the host name of this node, and the value of the MEMBER_STATE column is ONLINE, it means that this local machine is the primary node of the MGR cluster.

[0041] Query the VIP information on the local node and execute the ifconfig command. If VIP exists in the feedback result, it means that VIP exists on the local machine.

[0042] Query the VIP information on the network of the local node and execute the nmap-sP$VIP command. If the feedback result shows "Hostis up", it means that the VIP exists on the network of the local node.

[0043] (3) Data analysis, VIP operation and log output: Based on the acquired host data and database data, determine whether the MGR cluster master database has switched, and perform VIP addition or deletion operations according to different situations to ensure that the virtual IP address is always on the master node.

[0044] The judgment process is as follows Figure 3 As shown, if this node is the master node of the MGR cluster, and there is no VIP on this node, and there is no VIP on the network of this node, it means that the MGR cluster has changed. Now this node has become the new master node and needs to start the VIP. Then the VIP startup process is triggered, which includes: executing the ip addr add command to add a VIP on the network card of this node, and then executing the arping command to perform ARP broadcast to the outside world, and record a VIP addition record including the time in the output log, indicating that the VIP has been added successfully.

[0045] If this node is not the master node of the MGR cluster and this node has a VIP, it means that the MGR cluster has changed and this node is no longer the master node. Regardless of whether the database status of this node is normal, the VIP needs to be closed, which triggers the VIP closing process, including: executing the ip addr delete command to delete the VIP, and recording a VIP deletion record including the time in the output log, indicating that the VIP has been deleted successfully.

[0046] If other situations occur, the status quo will be maintained without any processing, but a VIP unchanged record including the time will still be recorded in the output log, indicating that no operation was performed.

[0047] At this time, the VIP control program will automatically exit after completing all operations and wait for the next run.

[0048] When the original master database or slave database of the MGR cluster fails, the failed node needs to perform a failure recovery operation, which includes the following steps:

[0049] (1) Faulty database recovery: Repair the operating system, network, and database problems, start the MySQL database and rejoin the MGR cluster. The MGR cluster will automatically complete the data synchronization operation of the new node without affecting the operation of the GMR cluster master database.

[0050] (2) VIP control program recovery: When the faulty database is successfully added to the MGR cluster, the VIP control program can be started and set to execute every second.

[0051] (3) When the VIP control program starts successfully and the output log displays normal status, it means that the faulty node has been restored.

[0052] If the above method is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0053] In summary, this embodiment uses MGR cluster technology and VIP technology, adds a VIP control program, introduces MGR cluster master database judgment and VIP survival judgment, and achieves high availability of the three-node database by deleting VIP on the original master node of the MGR cluster and adding VIP on the new master node of the MGR cluster. The application uses VIP to access the MGR cluster master database, and solves the problem of application access failure when the MGR cluster completes the master database failover. The application does not need to modify the configuration to ensure that the VIP is on the MGR cluster master node, ensuring that the application can accurately and quickly access the MGR cluster master database using VIP.

[0054] Compared with the methods proposed in the two Chinese patent applications in the background art, the method of the present invention not only has the technical effect of stable and reliable database clustering, but also has the following beneficial effects:

[0055] 1. VIP is stable and reliable. The VIP control program is used to determine the node where the MGR cluster master database is located and the survival of the VIP. The stable and reliable use of VIP is achieved by adding VIP to the network card of the MGR cluster master node. Regardless of whether the MGR cluster master database fails over, as long as the MGR cluster prompts that the master database is normal, the VIP will be on the MGR cluster master node, and the VIP pointing to the master database is correct. There will be no problem that the MGR cluster master database and the Keepalived VIP are not on the same host, there will be no problem of Keepalived VIP drifting between MGR cluster nodes, and the VIP will not be taken offline or online for no reason.

[0056] 2. The application can access the database without any worries. The application uses VIP to access the database instead of DNS resolution, which avoids the problem of DNS service unavailability and incorrect DNS configuration, and also avoids the problem of application access failure due to the IP mapped in the client DNS cache not being the IP of the primary database node.

[0057] 3. Simple architecture, easy to maintain. No other software or services (such as Keepalived and DNS) are used or maintained, and will not be affected by other software or service problems. The VIP control program can obtain data in a controllable way, with simple judgment logic, and can be developed in different programming languages ​​for easy maintenance.

[0058] 4. Resource usage is controllable. The VIP control program shares server resources with the database, and does not incur additional resource usage costs. The VIP control program uses small amounts of resources, does not save host data and database data, only performs simple result comparisons on some data, and only saves VIP operation logs, and does not compete for database resources.

[0059] Example 2

[0060] The difference between this embodiment and embodiment 1 is that this embodiment selects MySQL5.7 to deploy the MGR cluster. Figure 4 As shown, because the query methods of the MGR cluster master database provided by MySQL5.7 and MySQL8.0 are different, it is necessary to adjust the code for obtaining database data in the VIP control program and adjust the logical judgment process of the MGR cluster master database.

[0061] The performance_schema.replication_group_members table in MySQL 5.7 does not have a MEMBER_ROLE column and does not display PRIMARY information. Therefore, you need to first check the results of the MEMBER_HOST and MEMBER_STATE columns in the table and query them using the following command:

[0062] select MEMBER_STATE from performance_schema.replication_group_memberswhere MEMBER_HOST='$HOSTNAME';"|grep ONLINE

[0063] If the result value of the MEMBER_HOST column is the host name of this node, and the result value of the MEMBER_STATE column is ONLINE, it means that the node belongs to one of the nodes in the MGR cluster, and you can proceed to the next step.

[0064] Then, by checking the database status group_replication_primary_member value and the database variable parameter server_uuid value, we can indirectly help determine whether this node is the primary node of the MGR cluster. Query it with the following command:

[0065] SHOW GLOBAL STATUS LIKE'group_replication_primary_member';

[0066] SHOW GLOBAL VARIABLES LIKE'server_uuid';

[0067] If the two values ​​are the same and the node belongs to one of the nodes in the MGR cluster, it means that the node is the master node of the MGR cluster.

[0068] Example 2 has some changes in the method of determining the MGR cluster master database, and the other steps are the same as Example 1 using MySQL 8.0.

[0069] The above description of the embodiments is to facilitate the understanding and use of the invention by those skilled in the art. It is obvious that those skilled in the art can easily make various modifications to these embodiments and apply the general principles described herein to other embodiments without creative work. Therefore, the present invention is not limited to the above embodiments, and improvements and modifications made by those skilled in the art based on the disclosure of the present invention without departing from the scope of the present invention should be within the scope of protection of the present invention.

Claims

1. A method for implementing high availability of a multi-node database, characterized in that: The following steps are involved: S1. Deploy MySQL databases on multiple nodes to form a MySQL group replication cluster in single-master mode, including a master database and several slave databases, where the node corresponding to the master database is the master node; S2. The application accesses the main database through the virtual IP address. A virtual IP address control program is deployed and regularly run on each node. The virtual IP address control program is used to obtain data from each node, thereby determining whether the main database has been switched. The virtual IP address is added or deleted according to different situations, so that the virtual IP address is always on the main node.

2. A method for implementing high availability of a multi-node database according to claim 1, characterized in that: In step S2, before running the virtual IP address control program, the database virtual IP address, host network card name, host name, database user and password are configured.

3. A method for implementing high availability of a multi-node database according to claim 1, characterized in that: In step S2, the virtual IP address control program is run once a second by setting a scheduled task.

4. A method for implementing high availability of a multi-node database according to claim 1, characterized in that: In step S2, the specific process of performing the virtual IP address addition or deletion operation according to different situations is as follows: If the node is the master node and does not have a virtual IP address, and the node does not have a virtual IP address on the network, the virtual IP address addition operation is triggered, a virtual IP address is added to the host network card of the node, an address resolution protocol broadcast is performed externally, and a virtual IP address addition record is recorded in the output log; If the node is not the master node and has a virtual IP address, the virtual IP address deletion operation is triggered to delete the virtual IP address on the host network card of the node, and a virtual IP address deletion record is recorded in the output log; If other situations occur, the status quo is maintained without any processing, and a record indicating that the virtual IP address has not changed is recorded in the output log.

5. A method for implementing high availability of a multi-node database according to claim 4, characterized in that: The output log includes the time when the virtual IP address is added or deleted.

6. A method for implementing high availability of a multi-node database according to claim 1, characterized in that: After the master database fails, the MySQL group replication cluster promotes a slave database as a new master database to continue to provide read and write services to the outside world.

7. A method for implementing high availability of a multi-node database according to claim 1, characterized in that: After the master database or slave database fails, a fault recovery operation is performed. The specific process of the fault recovery operation is as follows: repair the operating system, network and database problems, start the MySQL database of the failed node and rejoin the MySQL group replication cluster. After the failed node successfully joins, deploy and regularly run the virtual IP address control program.

8. A method for implementing high availability of a multi-node database according to claim 7, characterized in that: The MySQL group replication cluster automatically completes the data synchronization operation of the newly added node.

9. An electronic device comprising a memory, a processor, and a program stored in the memory, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 8 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.