Load balancing method and device, equipment and storage medium
The load balancing method addresses HAProxy's single point failure by automatically switching to a backup node, reducing downtime and enhancing system stability and user satisfaction.
Patent Information
- Application Number
- CN202411042489.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-12-03
AI Technical Summary
HAProxy's single point failure problem causes service interruptions and potential economic losses due to service downtime when the main node fails.
A load balancing method that automatically switches to a backup HAProxy node upon failure, adjusting configuration parameters, performing real-time health checks, and synchronizing information using heartbeat mechanisms and shared storage solutions.
Reduces service interruption time and ensures stable operation of backend services by seamlessly switching to a backup node, improving user satisfaction and system availability.
Smart Images

Figure CN119071141A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a load balancing method, device, equipment and storage medium. Background Art
[0002] The stability and availability of network services are of vital importance to enterprises and users. In view of the continuous growth of business volume and the continuous improvement of service quality requirements, the traditional single server architecture has gradually become unable to meet the business needs of high concurrency and high reliability. Therefore, load balancing technology came into being.
[0003] HAProxy, as the industry's recognized leading load balancing solution, has won wide acclaim for its efficiency and accuracy in distributing network traffic. HAProxy can effectively optimize server performance, improve network response speed, and ensure that users can have a smooth experience when enjoying services. However, even though HAProxy has so many advantages, its single point failure problem cannot be ignored. When the main HAProxy node fails, it may cause service interruption, which will directly affect the user experience and may even cause obstacles to business operations, thereby bringing potential economic losses.
[0004] It can be seen that the existing technology still needs to be improved and enhanced. Summary of the invention
[0005] In order to overcome the shortcomings of the prior art, the purpose of the present invention is to provide a load balancing method, which can automatically switch to the backup HAProxy node when a failure occurs in the main HAProxy node, greatly reducing the service interruption time caused by the failure of the main HAProxy node and improving user satisfaction.
[0006] A first aspect of the present invention provides a load balancing method, comprising: adjusting configuration parameters of a master HAProxy node and configuration parameters of a standby HAProxy node according to a preset configuration file; running the master HAProxy node, and adjusting the working state of the master HAProxy node in real time based on a preset distribution strategy; performing periodic health checks on servers connected to the master HAProxy node according to a preset health check mechanism to periodically adjust the working state of the master HAProxy node; monitoring real-time status information fed back by the master HAProxy node, and triggering an alarm mechanism when the real-time status information indicates that an abnormal situation exists; and switching to the standby HAProxy node when the real-time status information indicates that a fault problem occurs in the master HAProxy node, and synchronizing the running information of the master HAProxy node to the standby HAProxy node.
[0007] Optionally, in a first implementation manner of the first aspect of the present invention, adjusting the configuration parameters of the master HAProxy node and the configuration parameters of the standby HAProxy node according to a preset configuration file includes: obtaining a preset configuration file, the preset configuration file including a listening port, a backend server list, and network parameters; based on the preset configuration file, adjusting the configuration parameters of the master HAProxy node and the configuration parameters of the standby HAProxy node, and establishing a communication connection between the master HAProxy node and the standby HAProxy node; writing a heartbeat sending text in the master HAProxy node, writing a heartbeat receiving text in the standby HAProxy node, and setting a heartbeat timeout.
[0008] Optionally, in a second implementation manner of the first aspect of the present invention, the running of the main HAProxy node adjusts the working state of the main HAProxy node in real time based on a preset distribution strategy, including: obtaining a preset distribution strategy, the preset distribution strategy including weighted polling and least connections; adjusting the working state of the main HAProxy node in real time based on the weighted polling distribution strategy, and obtaining real-time load status information fed back by a server connected to the main HAProxy node; determining whether the real-time load status information meets a preset policy switching condition, and if so, adjusting the working state of the main HAProxy node in real time based on the least connection distribution strategy.
[0009] Optionally, in a third implementation manner of the first aspect of the present invention, performing periodic health checks on servers connected to the master HAProxy node according to a preset health check mechanism to periodically adjust the working status of the master HAProxy node includes: obtaining a preset health check mechanism, wherein the preset health check mechanism includes an interval parameter, a failure parameter, a success parameter, and an indicator to be monitored; performing periodic health checks on servers connected to the master HAProxy node based on the interval parameter and the indicator to be monitored, and obtaining feedback inspection information; comparing the inspection information, failure parameters, and success parameters to determine whether there is an abnormal server; when an abnormal server exists, removing the information of the abnormal server from the backend server list of the master HAProxy node, updating the backend server list, and updating the log file of the master HAProxy; and adjusting the working status of the master HAProxy node based on the updated backend server list.
[0010] Optionally, in a fourth implementation manner of the first aspect of the present invention, the real-time status information fed back by the monitoring master HAProxy node is monitored, and when the real-time status information indicates that an abnormal situation exists, an alarm mechanism is triggered, including: monitoring the real-time status information fed back by the monitoring master HAProxy node, the real-time status information including log files and node monitoring indicators; using an awk log analysis tool to analyze the obtained log files to determine whether there is an abnormality, and if so, triggering the alarm mechanism; obtaining a preset threshold standard table, comparing the obtained node monitoring indicators with the preset threshold standard table to determine whether there is an abnormality, and if so, triggering the alarm mechanism.
[0011] Optionally, in a fifth implementation manner of the first aspect of the present invention, when the real-time status information indicates that the primary HAProxy node has a fault problem, switching to the backup HAProxy node includes: the real-time status information includes heartbeat information and process status information, and judging whether the primary HAProxy node has a fault problem based on the heartbeat information and the process status information; when the heartbeat information indicates that the primary HAProxy node has a fault problem, or when the process status information indicates that the primary HAProxy node has a fault problem, using Keepalived to switch to the backup HAProxy node; obtaining user address information of the primary HAProxy node, and binding the user address information to the backup HAProxy node.
[0012] Optionally, in a sixth implementation manner of the first aspect of the present invention, synchronizing the running information of the master HAProxy node to the standby HAProxy node includes: the running information includes a configuration file and session information; using an inotify tool in combination with an rsync tool to synchronize the configuration file of the master HAProxy node to the standby HAProxy node, and sharing the session information of the master HAProxy node to the standby HAProxy node based on a SAN shared storage solution; recording the synchronization process in a log file of the standby HAProxy node, and regularly backing up the configuration file of the standby HAProxy node according to the regular tasks of the rsync tool.
[0013] A second aspect of the present invention provides a load balancing device, including: a parameter adjustment module, used to adjust the configuration parameters of the main HAProxy node and the configuration parameters of the backup HAProxy node according to a preset configuration file; a real-time adjustment module, used to run the main HAProxy node, and adjust the working state of the main HAProxy node in real time based on a preset distribution strategy; a periodic adjustment module, used to perform periodic health checks on the server connected to the main HAProxy node according to a preset health check mechanism to periodically adjust the working state of the main HAProxy node; a monitoring module, used to monitor the real-time status information fed back by the main HAProxy node, and trigger an alarm mechanism when the real-time status information indicates that there is an abnormal situation; a switching module, used to switch to the backup HAProxy node when the real-time status information indicates that the main HAProxy node has a fault problem, and synchronize the operation information of the main HAProxy node to the backup HAProxy node.
[0014] Optionally, in a first implementation manner of the second aspect of the present invention, the parameter adjustment module includes: a first acquisition unit, used to acquire a preset configuration file, the preset configuration file including a listening port, a back-end server list, and network parameters; a first adjustment unit, used to adjust the configuration parameters of the master HAProxy node and the configuration parameters of the standby HAProxy node based on the preset configuration file, and to establish a communication connection between the master HAProxy node and the standby HAProxy node; a setting unit, used to write a heartbeat sending text in the master HAProxy node, write a heartbeat receiving text in the standby HAProxy node, and set a heartbeat timeout.
[0015] Optionally, in a second implementation of the second aspect of the present invention, the real-time adjustment module includes: a second acquisition unit, used to acquire a preset distribution strategy, the preset distribution strategy including weighted polling and least connection; a second adjustment unit, used to adjust the working status of the main HAProxy node in real time based on the weighted polling distribution strategy, and obtain real-time load status information fed back by the server connected to the main HAProxy node; a first judgment unit, used to judge whether the real-time load status information meets the preset policy switching condition, and if so, adjust the working status of the main HAProxy node in real time based on the least connection distribution strategy.
[0016] Optionally, in a third implementation of the second aspect of the present invention, the periodic adjustment module includes: a third acquisition unit, used to acquire a preset health check mechanism, wherein the preset health check mechanism includes an interval parameter, a failure parameter, a success parameter, and an indicator to be monitored; an inspection unit, used to perform a periodic health check on a server connected to the main HAProxy node based on the interval parameter and the indicator to be monitored, and obtain feedback inspection information; a second judgment unit, used to compare the inspection information, failure parameters, and success parameters to determine whether there is an abnormal server; an update unit, used to remove the information of the abnormal server from the backend server list of the main HAProxy node, update the backend server list, and update the log file of the main HAProxy when an abnormal server exists; and a third adjustment unit, used to adjust the working status of the main HAProxy node based on the updated backend server list.
[0017] Optionally, in a fourth implementation of the second aspect of the present invention, the monitoring module includes: a monitoring unit, used to monitor real-time status information fed back by the main HAProxy node, the real-time status information including log files and node monitoring indicators; an analysis unit, used to analyze the acquired log files using an awk log analysis tool to determine whether there is an abnormality, and if so, trigger an alarm mechanism; a comparison unit, used to obtain a preset threshold standard table, compare the acquired node monitoring indicators with the preset threshold standard table to determine whether there is an abnormality, and if so, trigger an alarm mechanism.
[0018] Optionally, in a fifth implementation of the second aspect of the present invention, the switching module includes: a third judgment unit, used to judge whether a fault occurs in the primary HAProxy node based on heartbeat information and process status information; a switching unit, used to use Keepalived to switch to a backup HAProxy node when the heartbeat information indicates that a fault occurs in the primary HAProxy node, or when the process status information indicates that a fault occurs in the primary HAProxy node; and a binding unit, used to obtain user address information of the primary HAProxy node and bind the user address information to the backup HAProxy node.
[0019] Optionally, in a sixth implementation of the second aspect of the present invention, the switching module further includes: a synchronization unit, used to synchronize the configuration file of the primary HAProxy node to the backup HAProxy node using the inotify tool in combination with the rsync tool, and share the session information of the primary HAProxy node to the backup HAProxy node based on the SAN shared storage solution; a backup unit, used to record the synchronization process in a log file of the backup HAProxy node, and regularly back up the configuration file of the backup HAProxy node according to the regular tasks of the rsync tool.
[0020] The third aspect of the present invention provides a load balancing device, which includes: a memory and at least one processor, wherein the memory stores instructions; at least one of the processors calls the instructions in the memory so that the load balancing device executes each step of the load balancing method described in any one of the above items.
[0021] A fourth aspect of the present invention provides a computer-readable storage medium, on which instructions are stored, and when the instructions are executed by a processor, the steps of any of the above-mentioned load balancing methods are implemented.
[0022] In the technical solution of the present invention, the configuration parameters of the main HAProxy node and the configuration parameters of the backup HAProxy node are adjusted according to a preset configuration file; the main HAProxy node is run, and the working status of the main HAProxy node is adjusted in real time based on a preset distribution strategy, and the working status of the main HAProxy node is periodically adjusted based on a preset health check mechanism; when the real-time status information indicates that there is an abnormal situation, an alarm mechanism is triggered; when the real-time status information indicates that a fault occurs in the main HAProxy node, the backup HAProxy node is switched to, and the synchronization operation of the running information is performed; the method disclosed in the present application can automatically switch to the backup HAProxy node when a fault occurs in the main HAProxy node, which greatly reduces the service interruption time caused by the failure of the main HAProxy node, ensures that the back-end services connected to the node can continue to run stably, avoid service interruption, and improve user satisfaction. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 A first flow chart of a load balancing method provided by an embodiment of the present invention;
[0024] Figure 2 A second flow chart of the load balancing method provided by an embodiment of the present invention;
[0025] Figure 3 A third flow chart of the load balancing method provided by an embodiment of the present invention;
[0026] Figure 4 A fourth flow chart of the load balancing method provided by an embodiment of the present invention;
[0027] Figure 5 A fifth flow chart of the load balancing method provided by an embodiment of the present invention;
[0028] Figure 6 A sixth flow chart of the load balancing method provided by an embodiment of the present invention;
[0029] Figure 7 A seventh flow chart of the load balancing method provided by an embodiment of the present invention;
[0030] Figure 8 A schematic diagram of the structure of a load balancing device provided by an embodiment of the present invention;
[0031] Fig. 9 A schematic diagram of the structure of a load balancing device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0032] The present invention provides a load balancing method, apparatus, device and storage medium. In the present invention, the terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0033] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the load balancing method in the embodiment of the present invention includes:
[0034] 101. According to the preset configuration file, adjust the configuration parameters of the main HAProxy node and the configuration parameters of the standby HAProxy node;
[0035] In this embodiment, HAProxy is a common high-availability load balancing solution for distributing network traffic to a backend server cluster; adjusting the configuration parameters of the primary and backup nodes can ensure that the load balancer effectively processes network requests according to preset policies and rules, while improving the stability and availability of the entire system; and can ensure the communication connection between the primary and backup nodes, so that the backup HAProxy node can monitor the working status of the primary node. When the primary HAProxy node fails, the backup HAProxy node can quickly take over the work and continue to provide services to ensure the high availability of the system.
[0036] 102. Run the main HAProxy node and adjust the working status of the main HAProxy node in real time based on the preset distribution strategy;
[0037] In this embodiment, by adjusting the working status of the main HAProxy node in real time, load balancing and high availability are ensured, and the stability and reliability of the backend server when working can be improved.
[0038] 103. Perform periodic health checks on servers connected to the main HAProxy node according to a preset health check mechanism to periodically adjust the working status of the main HAProxy node;
[0039] In this embodiment, by performing periodic health checks, unhealthy servers can be discovered in time, and the distribution strategy of the main HAProxy node can be adjusted in time to ensure that only backend servers that are working normally receive traffic requests from clients.
[0040] 104. Monitor the real-time status information fed back by the main HAProxy node, and trigger the alarm mechanism when the real-time status information indicates an abnormal situation;
[0041] In this embodiment, by monitoring the real-time status information fed back by the main HAProxy node and setting a corresponding alarm mechanism, these abnormal situations can be quickly discovered and responded to; once an abnormality is detected, the alarm mechanism will be triggered immediately to notify the administrator or automated script to take corresponding measures, such as restarting the service, adjusting the configuration, etc., to ensure the continuity and availability of the service.
[0042] 105. When the real-time status information indicates that a fault occurs in the primary HAProxy node, switch to the backup HAProxy node, and synchronize the operation information of the primary HAProxy node to the backup HAProxy node.
[0043] The present application discloses a load balancing method, which adjusts the configuration parameters of a main HAProxy node and a backup HAProxy node according to a preset configuration file; runs the main HAProxy node, adjusts the working status of the main HAProxy node in real time based on a preset distribution strategy, and periodically adjusts the working status of the main HAProxy node based on a preset health check mechanism; triggers an alarm mechanism when real-time status information indicates that an abnormal situation exists; switches to a backup HAProxy node when real-time status information indicates that a failure problem occurs in the main HAProxy node, and performs a synchronization operation of operation information; the method disclosed in the present application can automatically switch to a backup HAProxy node when a failure problem occurs in the main HAProxy node, thereby greatly reducing the service interruption time caused by the failure of the main HAProxy node, ensuring that the backend services connected to the node can continue to run stably, avoiding service interruption, and improving user satisfaction.
[0044] See also Figure 2, a second embodiment of the load balancing method in an embodiment of the present invention includes:
[0045] 201. Obtain a preset configuration file, wherein the preset configuration file includes a listening port, a backend server list, and network parameters;
[0046] In this embodiment, the network parameters of the active and standby nodes are adjusted to ensure normal communication between the active HAProxy node and the standby HAProxy node.
[0047] 202. Based on a preset configuration file, adjust configuration parameters of the primary HAProxy node and configuration parameters of the backup HAProxy node, and establish a communication connection between the primary HAProxy node and the backup HAProxy node;
[0048] 203. Write the heartbeat sending text in the main HAProxy node, write the heartbeat receiving text in the standby HAProxy node, and set the heartbeat timeout;
[0049] In this embodiment, the failover of the master and standby nodes is realized through auxiliary monitoring of the heartbeat mechanism; specifically, the master HAProxy node will continue to send survival signals (heartbeat signals) to the standby HAProxy node, indicating that the master HAProxy node is currently in normal operation; the standby HAProxy node will monitor these signals and judge the status of the master HAProxy node according to the reception of the signals; once the standby HAProxy node does not receive the heartbeat signal of the master HAProxy node within a period of time, specifically, within the preset heartbeat timeout period (that is, the master HAProxy node stops sending signals), it is considered that the master HAProxy node has failed, and the standby HAProxy node will automatically switch to the master HAProxy node and take over the service.
[0050] See also Figure 3 , a third embodiment of the load balancing method in the embodiment of the present invention includes:
[0051] 301. Obtain a preset distribution strategy, where the preset distribution strategy includes weighted round-robin and least connections;
[0052] In this embodiment, the weighted round-robin distribution strategy means that HAProxy assigns a weight value to each server according to the performance or importance of the server, and then HAProxy distributes requests to each server according to the size of the weight value to achieve load balancing.
[0053] In this embodiment, the least connection distribution strategy means that HAProxy will continuously monitor the number of connections of the backend servers and distribute new requests to the server with the least number of connections, thereby ensuring that the load of each server can be maintained in a relatively balanced state.
[0054] 302. Adjust the working status of the main HAProxy node in real time based on the weighted round-robin distribution strategy, and obtain real-time load status information fed back by the server connected to the main HAProxy node;
[0055] 303. Determine whether the real-time load status information meets the preset policy switching condition. If so, adjust the working state of the main HAProxy node in real time based on the least connection distribution strategy;
[0056] In this embodiment, when the real-time load status information indicates that the load of a server exceeds a preset load threshold or the response speed of a server is less than a preset minimum response speed, the working status of the main HAProxy node is adjusted in real time based on the least connection distribution strategy.
[0057] In this embodiment, a suitable load balancing strategy, such as weighted round-robin and minimum number of connections, is selected according to business requirements and server performance to ensure that traffic can be evenly distributed to each server and reduce the impact of unhealthy servers on overall performance.
[0058] See also Figure 4 , a fourth embodiment of the load balancing method in the embodiment of the present invention includes:
[0059] 401. Obtain a preset health check mechanism, where the preset health check mechanism includes an interval parameter, a failure parameter, a success parameter, and an indicator to be monitored;
[0060] In the configuration file of HAProxy, it is usually necessary to set the check option of the server section to enable health checks; in this embodiment, the interval parameter is the time interval for starting the health check, and the failure parameter and the success parameter are used to confirm whether the backend server is healthy, that is, how many failures will be marked as unhealthy, or how many successes will be marked as healthy.
[0061] 402. Perform periodic health checks on the servers connected to the primary HAProxy node based on the interval parameters and the indicators to be monitored, and obtain feedback check information;
[0062] 403. Compare the check information, failure parameters and success parameters to determine whether there is an abnormal server;
[0063] In this embodiment, the inspection information includes the number of successful connections and the number of failed connections of each backend server connected to the main HAProxy node, and the number of failed connections and the failure parameters are compared, as well as the number of successful connections and the success parameters are compared to determine whether there is an abnormal server, that is, whether there is an unhealthy server.
[0064] 404. When an abnormal server exists, remove the information of the abnormal server from the backend server list of the master HAProxy node, update the backend server list, and update the log file of the master HAProxy;
[0065] 405. Adjust the working status of the main HAProxy node based on the updated backend server list;
[0066] In this embodiment, when the master HAProxy node detects that a server is unhealthy, the information of the abnormal server is removed from the backend server list of the master HAProxy node to remove it from the load balancing pool. The removed server no longer receives new traffic requests, and the master HAProxy node distributes newly received traffic requests according to the backend server list after the removal. By performing health checks regularly, unhealthy servers can be effectively removed and the stability and reliability of the load balancing system can be ensured.
[0067] See also Figure 5 , a fifth embodiment of the load balancing method in the embodiment of the present invention includes:
[0068] 501. Monitor the real-time status information fed back by the main HAProxy node, where the real-time status information includes log files and node monitoring indicators;
[0069] In this embodiment, the process status of the master HAProxy node can be queried by writing a ps command to confirm the real-time status information of the master HAProxy node.
[0070] 502. Analyze the obtained log file using the awk log analysis tool to determine whether there is an abnormality. If there is an abnormality, trigger the alarm mechanism;
[0071] In this embodiment, the "error" line of the log file can be searched through the awk script to determine whether there is an abnormal problem in the running process of the main HAProxy node; when an abnormal problem occurs and the alarm mechanism is triggered, the alarm can be sent via email, SMS or an integrated monitoring platform, and the alarm is sent according to the configured relevant sending services (such as SMTP server, SMS gateway, etc.) and recipient information.
[0072] 503. Obtain a preset threshold standard table, compare the obtained node monitoring index with the preset threshold standard table to determine whether there is an abnormality, and if there is an abnormality, trigger an alarm mechanism;
[0073] In this embodiment, node monitoring indicators such as CPU usage, memory usage, and number of connections of the main HAProxy node can be collected by writing a script, and the node monitoring indicators can be obtained through the stats socket function of the main HAProxy node; the threshold standard table is provided with a plurality of node monitoring indicators and their corresponding alarm thresholds, and the alarm thresholds can be set according to actual conditions and business requirements; the obtained node monitoring indicators and their corresponding alarm thresholds are compared one by one to confirm whether there is an abnormality in the running process of the main HAProxy node.
[0074] See also Figure 6 , a sixth embodiment of the load balancing method in the embodiment of the present invention includes:
[0075] The real-time status information includes heartbeat information and process status information;
[0076] In this embodiment, the track_script module of Keepalived is used to write a custom script to monitor the process status of the main HAProxy node to obtain process status information. The script will regularly check whether the main HAProxy node process exists, whether it responds normally, and other key indicators.
[0077] 601. Determine whether the main HAProxy node has a fault problem based on the heartbeat information and process status information;
[0078] In this embodiment, the detection of the main HAProxy node fault problem is achieved by coordinating the heartbeat information with the process status information, the fault problem can be discovered in time and the master and standby nodes can be switched, the automatic identification, processing and recovery of the fault can be realized, the continuity and availability of the service can be ensured, and the operation and maintenance efficiency can be improved and the operation and maintenance cost can be reduced; further, the cause of the fault can be accurately located, and the operation and maintenance personnel can be helped to quickly troubleshoot the problem, which improves the fault handling efficiency and reduces the troubleshooting time.
[0079] 602. When the heartbeat information indicates that the primary HAProxy node has a fault problem, or when the process status information indicates that the primary HAProxy node has a fault problem, use Keepalived to switch to the backup HAProxy node;
[0080] In this embodiment, Keepalived is used to implement the switching of the primary and standby nodes. Keepalived is a lightweight Linux high-availability solution based on VRRP (Virtual Router Redundancy Protocol), which is mainly used for load balancing and fault switching between servers in Linux systems. Its purpose is to solve problems that may occur in a single node and provide service reliability.
[0081] 603. Obtain user address information of the primary HAProxy node, and bind the user address information to the standby HAProxy node;
[0082] In this embodiment, when a failure occurs in the main HAProxy node, such as failure to receive heartbeat information from the main node for multiple consecutive times, serious abnormalities in key performance indicators, etc., the traffic switching mechanism will be immediately started, and Keepalived will automatically promote the backup HAProxy node to the main HAProxy node according to its internal election algorithm, and bind the user address to the backup HAProxy node, so that the client can continue to access the service through VIP without perceiving the node switching, thereby improving the user experience.
[0083] See also Figure 7 , a seventh embodiment of the load balancing method in the embodiment of the present invention includes:
[0084] The operation information includes configuration files and session information;
[0085] 701. Use the inotify tool in combination with the rsync tool to synchronize the configuration file of the primary HAProxy node to the backup HAProxy node, and share the session information of the primary HAProxy node to the backup HAProxy node based on the SAN shared storage solution;
[0086] In this embodiment, inotifywait is used to monitor changes in the source directory. When inotifywait detects file changes, the rsync command is triggered for synchronization. During the synchronization process, SSH keys are used for identity authentication to avoid the need to enter a password each time synchronization is performed.
[0087] In this embodiment, the configuration file of the main HAProxy node is synchronized to the standby HAProxy node using the inotify tool in combination with the rsync tool. inotify is a function provided by the Linux kernel, which is used to monitor events such as creation, deletion, movement or attribute change of files in the file system; when a file system event occurs, the kernel can notify the event information to the process in the user space through the inotify interface; rsync is a tool for synchronizing files and directories, which can synchronize data in a local or remote file system; rsync optimizes data transmission efficiency by transmitting only the difference between two files or directories (i.e., incremental backup), which makes it particularly effective when processing large amounts of data; rsync can also maintain file attributes such as symbolic links, special and device files, modification time, and permissions.
[0088] In this embodiment, a SAN shared storage solution is used to allow the active and standby nodes to access the same session information storage area. When the active and standby nodes switch, the standby HAProxy node can directly read the latest session information; that is, based on the SAN shared storage solution, no matter which node becomes the active node, the latest session information can be directly read in the session information storage area.
[0089] 702. Record the synchronization process in the log file of the standby HAProxy node, and regularly back up the configuration file of the standby HAProxy node according to the regular task of the rsync tool;
[0090] In this embodiment, by recording the synchronization process in the log file of the standby HAProxy node, when a problem occurs during the synchronization process, it can be discovered and solved in time; further, the rsync tool can be used to set a regular task to implement regular backup of the configuration file, and the configuration file of the standby HAProxy node can be backed up regularly so that it can be quickly restored when a problem occurs.
[0091] The load balancing method in the embodiment of the present invention is described above. The load balancing device in the embodiment of the present invention is described below. Figure 8 , an embodiment of the load balancing device in the embodiment of the present invention includes:
[0092] The parameter adjustment module 801 is used to adjust the configuration parameters of the main HAProxy node and the configuration parameters of the backup HAProxy node according to a preset configuration file; the real-time adjustment module 802 is used to run the main HAProxy node and adjust the working state of the main HAProxy node in real time based on a preset distribution strategy; the periodic adjustment module 803 is used to perform periodic health checks on the servers connected to the main HAProxy node according to a preset health check mechanism to periodically adjust the working state of the main HAProxy node; the monitoring module 804 is used to monitor the real-time status information fed back by the main HAProxy node, and trigger the alarm mechanism when the real-time status information indicates that there is an abnormal situation; the switching module 805 is used to switch to the backup HAProxy node when the real-time status information indicates that the main HAProxy node has a fault problem, and synchronize the operation information of the main HAProxy node to the backup HAProxy node.
[0093] In this embodiment, the parameter adjustment module 801 includes: a first acquisition unit 8011, used to obtain a preset configuration file, wherein the preset configuration file includes a listening port, a backend server list, and network parameters; a first adjustment unit 8012, used to adjust the configuration parameters of the master HAProxy node and the configuration parameters of the standby HAProxy node based on the preset configuration file, and to establish a communication connection between the master HAProxy node and the standby HAProxy node; a setting unit 8013, used to write a heartbeat sending text in the master HAProxy node, write a heartbeat receiving text in the standby HAProxy node, and set a heartbeat timeout.
[0094] In this embodiment, the real-time adjustment module 802 includes: a second acquisition unit 8021, used to acquire a preset distribution strategy, wherein the preset distribution strategy includes weighted polling and least connection; a second adjustment unit 8022, used to adjust the working state of the main HAProxy node in real time based on the weighted polling distribution strategy, and obtain the real-time load state information fed back by the server connected to the main HAProxy node; a first judgment unit 8023, used to judge whether the real-time load state information meets the preset policy switching condition, and if so, adjust the working state of the main HAProxy node in real time based on the least connection distribution strategy.
[0095] In this embodiment, the period adjustment module 803 includes: a third acquisition unit 8031, which is used to obtain a preset health check mechanism, and the preset health check mechanism includes an interval parameter, a failure parameter, a success parameter, and an indicator to be monitored; a check unit 8032, which is used to perform a periodic health check on the server connected to the main HAProxy node based on the interval parameter and the indicator to be monitored, and obtain feedback inspection information; a second judgment unit 8033, which is used to compare the inspection information, the failure parameter, and the success parameter to determine whether there is an abnormal server; an update unit 8034, which is used to remove the information of the abnormal server from the backend server list of the main HAProxy node when there is an abnormal server, update the backend server list, and update the log file of the main HAProxy; a third adjustment unit 8035, which is used to adjust the working status of the main HAProxy node based on the updated backend server list.
[0096] In this embodiment, the monitoring module 804 includes: a monitoring unit 8041, which is used to monitor the real-time status information fed back by the main HAProxy node, and the real-time status information includes log files and node monitoring indicators; an analysis unit 8042, which is used to analyze the obtained log files using an awk log analysis tool to determine whether there is an abnormality, and if there is an abnormality, trigger an alarm mechanism; a comparison unit 8043, which is used to obtain a preset threshold standard table, compare the obtained node monitoring indicators with the preset threshold standard table, to determine whether there is an abnormality, and if there is an abnormality, trigger an alarm mechanism.
[0097] In this embodiment, the switching module 805 includes: a third judgment unit 8051, which is used to judge whether the main HAProxy node has a fault problem according to the heartbeat information and the process status information; a switching unit 8052, which is used to use Keepalived to switch to the backup HAProxy node when the heartbeat information indicates that the main HAProxy node has a fault problem, or when the process status information indicates that the main HAProxy node has a fault problem; a binding unit 8053, which is used to obtain the user address information of the main HAProxy node and bind the user address information to the backup HAProxy node.
[0098] In this embodiment, the switching module 805 also includes: a synchronization unit 8054, which is used to synchronize the configuration file of the primary HAProxy node to the backup HAProxy node using the inotify tool in combination with the rsync tool, and share the session information of the primary HAProxy node to the backup HAProxy node based on the SAN shared storage solution; a backup unit 8055, which is used to record the synchronization process in the log file of the backup HAProxy node, and regularly back up the configuration file of the backup HAProxy node according to the regular tasks of the rsync tool.
[0099] above Figure 8 The load balancing device in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The load balancing device in the embodiment of the present invention is described in detail from the perspective of hardware processing.
[0100] Fig. 9 is a schematic diagram of the structure of a load balancing device provided in an embodiment of the present invention. The load balancing device 900 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 910 (for example, one or more processors) and a memory 920, and one or more storage media 930 (for example, one or more mass storage devices) storing application programs 933 or data 932. Among them, the memory 920 and the storage medium 930 may be temporary storage or permanent storage. The program stored in the storage medium 930 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the load balancing device 900. Furthermore, the processor 910 may be configured to communicate with the storage medium 930, and execute a series of instruction operations in the storage medium 930 on the load balancing device 900 to implement the steps of the load balancing method provided in the above-mentioned method embodiments.
[0101] The load balancing device 900 may also include one or more power supplies 940, one or more wired or wireless network interfaces 950, one or more input and output interfaces 960, and / or one or more operating systems 931, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. It will be appreciated by those skilled in the art that Fig. 9 The illustrated load balancing device structure does not constitute a limitation on the load balancing device, and may include more or less components than illustrated, or a combination of certain components, or a different arrangement of components.
[0102] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the load balancing method.
[0103] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system, device, or unit can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.
[0104] If the integrated unit 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 is essentially or the part that contributes to the prior art or all or 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 a number of instructions to enable 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), random access memory (RAM), disk or optical disk and other media that can store program codes.
[0105] Finally, it should be noted that the above description is only a preferred example of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A load balancing method, characterized in that: include: Adjust the configuration parameters of the active HAProxy node and the standby HAProxy node according to the preset configuration files; Run the main HAProxy node and adjust the working status of the main HAProxy node in real time based on the preset distribution strategy; Perform periodic health checks on servers connected to the master HAProxy node according to the preset health check mechanism to periodically adjust the working status of the master HAProxy node; Monitor the real-time status information fed back by the main HAProxy node, and trigger the alarm mechanism when the real-time status information indicates an abnormal situation; When the real-time status information indicates that the primary HAProxy node has a fault, switch to the backup HAProxy node and synchronize the running information of the primary HAProxy node to the backup HAProxy node.
2. The load balancing method according to claim 1, characterized in that: The step of adjusting the configuration parameters of the main HAProxy node and the configuration parameters of the standby HAProxy node according to the preset configuration file includes: Obtain a preset configuration file, wherein the preset configuration file includes a listening port, a backend server list, and network parameters; Based on the preset configuration files, adjust the configuration parameters of the primary HAProxy node and the backup HAProxy node, and establish a communication connection between the primary HAProxy node and the backup HAProxy node; Write the heartbeat sending text in the primary HAProxy node, write the heartbeat receiving text in the standby HAProxy node, and set the heartbeat timeout.
3. The load balancing method according to claim 1, characterized in that: The running of the main HAProxy node and adjusting the working state of the main HAProxy node in real time based on a preset distribution strategy include: Obtaining a preset distribution strategy, wherein the preset distribution strategy includes weighted round-robin and least connection; Adjust the working status of the main HAProxy node in real time based on the weighted polling distribution strategy, and obtain the real-time load status information fed back by the server connected to the main HAProxy node; Determine whether the real-time load status information meets the preset policy switching conditions. If so, adjust the working status of the main HAProxy node in real time based on the least connection distribution strategy.
4. The load balancing method according to claim 1, characterized in that: The performing periodic health check on the server connected to the main HAProxy node according to the preset health check mechanism to periodically adjust the working state of the main HAProxy node includes: Obtain a preset health check mechanism, wherein the preset health check mechanism includes an interval parameter, a failure parameter, a success parameter, and an indicator to be monitored; Perform periodic health checks on the servers connected to the primary HAProxy node based on the interval parameters and the metrics to be monitored, and obtain feedback on the check information; Compare the check information, failure parameters and success parameters to determine whether there is an abnormal server; When an abnormal server exists, remove the abnormal server information from the backend server list of the master HAProxy node, update the backend server list, and update the log file of the master HAProxy; Adjust the working status of the main HAProxy node based on the updated backend server list.
5. The load balancing method according to claim 1, characterized in that: The real-time status information fed back by the monitoring master HAProxy node is monitored, and when the real-time status information indicates an abnormal situation, an alarm mechanism is triggered, including: Monitor the real-time status information fed back by the main HAProxy node, which includes log files and node monitoring indicators; Use the awk log analysis tool to analyze the obtained log files to determine whether there are any abnormalities. If there are any abnormalities, trigger the alarm mechanism; Obtain a preset threshold standard table, compare the obtained node monitoring indicators with the preset threshold standard table to determine whether there is an abnormality. If there is an abnormality, trigger the alarm mechanism.
6. The load balancing method according to claim 1, characterized in that: When the real-time status information indicates that a failure occurs in the primary HAProxy node, switching to the backup HAProxy node includes: The real-time status information includes heartbeat information and process status information, and whether the main HAProxy node has a fault problem is determined according to the heartbeat information and process status information; When the heartbeat information indicates that the primary HAProxy node has a fault, or when the process status information indicates that the primary HAProxy node has a fault, use Keepalived to switch to the backup HAProxy node; Obtain the user address information of the active HAProxy node, and bind the user address information to the standby HAProxy node.
7. The load balancing method according to claim 6, characterized in that: The step of synchronizing the operation information of the main HAProxy node to the standby HAProxy node includes: The operation information includes configuration files and session information; Use the inotify tool combined with the rsync tool to synchronize the configuration files of the active HAProxy node to the standby HAProxy node, and share the session information of the active HAProxy node to the standby HAProxy node based on the SAN shared storage solution; The synchronization process is recorded in the log file of the standby HAProxy node, and the configuration file of the standby HAProxy node is backed up regularly according to the regular task of the rsync tool.
8. A load balancing device, characterized in that: include: A parameter adjustment module, used to adjust the configuration parameters of the main HAProxy node and the configuration parameters of the standby HAProxy node according to a preset configuration file; The real-time adjustment module is used to run the main HAProxy node and adjust the working status of the main HAProxy node in real time based on the preset distribution strategy; A periodic adjustment module is used to perform periodic health checks on servers connected to the main HAProxy node according to a preset health check mechanism to periodically adjust the working status of the main HAProxy node; The monitoring module is used to monitor the real-time status information fed back by the main HAProxy node. When the real-time status information indicates an abnormal situation, the alarm mechanism is triggered; The switching module is used to switch to the backup HAProxy node when the real-time status information indicates that the main HAProxy node has a fault problem, and synchronize the operation information of the main HAProxy node to the backup HAProxy node.
9. A load balancing device, characterized in that: The load balancing device comprises: a memory and at least one processor, wherein instructions are stored in the memory; At least one of the processors calls the instructions in the memory to enable the load balancing device to execute each step of the load balancing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by the processor, the steps of the load balancing method as described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Load balancing service method and system based on SAN (Storage Area Network) storage
CN120010769A
Millisecond-level switching method and system for load balancing main and standby equipment based on DPDK (Data Platform Development Kit)
CN120567655A
