A load balancing method, device, equipment and computer readable storage medium
By optimizing the address translation between Layer 4 and Layer 7 load balancers, the problem of Layer 7 load balancers being unable to obtain VIPs in existing technologies is solved, achieving isolation and efficient operation between applications, meeting the requirements of high performance and rapid scaling, and realizing automated linkage between distributed systems and Kubernetes through API interfaces.
Patent Information
- Application Number
- CN202211093599.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-08
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2042-09-08
AI Technical Summary
In existing technologies, Layer 4 and Layer 7 soft load balancers perform four address translations during the interaction process, which makes it impossible for Layer 7 load balancers to obtain Virtual Internet Protocol Addresses (VIPs), thus failing to achieve mutual isolation between applications and failing to meet the requirements of high performance and rapid expansion.
By using the destination MAC address in the access message sent by the client, the target Layer 4 load balancer is determined from the Layer 4 load balancer cluster. The target Layer 4 load balancer is used to receive the access message. Based on the destination IP address, the MAC address of the target Layer 7 load balancer is determined from the Layer 7 load balancer cluster. The destination MAC address is adjusted to the MAC address of the target Layer 7 load balancer. Finally, the access message is sent to the target Layer 7 load balancer so that it obtains the destination IP address.
It achieves efficient and stable operation between different applications, solves the problem that the Layer 7 load balancer cannot obtain VIP, meets the requirements of high performance and rapid expansion, and realizes the linkage between the distributed system and Kubernetes through API interface without manual intervention.
Smart Images

Figure CN116781625B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of cloud computing technology, and includes, but is not limited to, a load balancing method, apparatus, device, and computer-readable storage medium. Background Technology
[0002] With the increasing number of business products and the exponential growth of the user base, a high-performance, multi-functional load balancer is needed. It must possess extremely high performance and rapid scalability, while also meeting the diverse needs of various businesses, such as providing an Application Programming Interface (API) for business users, supporting integration with open-source container orchestration systems (Kubernetes), and supporting canary deployments and blue-green deployments.
[0003] However, in related technologies, client requests first pass through a Layer 4 soft load balancer, then a Layer 7 soft load balancer, before finally reaching the application server. The application server's response then passes through the Layer 7 and Layer 4 soft load balancers before reaching the client. During the interaction between the Layer 4 and Layer 7 soft load balancers, four address translations occur. Furthermore, the Layer 7 soft load balancer cannot obtain the Virtual Internet Protocol (VIP) address, thus preventing the isolation of applications. Summary of the Invention
[0004] In view of this, embodiments of this application provide a load balancing method, apparatus, device, and computer-readable storage medium.
[0005] The technical solution of this application embodiment is implemented as follows:
[0006] This application provides a load balancing method applied to a distributed system, the distributed system including a Layer 4 load balancer cluster and a Layer 7 load balancer cluster, the method comprising:
[0007] The target Layer 4 load balancer is determined from the Layer 4 load balancer cluster based on the destination Media Access Control (MAC) address in the access message sent by the client.
[0008] The target Layer 4 load balancer is used to receive the access packet, wherein the access packet carries the source IP address and the destination IP address;
[0009] The target Layer 4 load balancer is controlled to determine the target Layer 7 load balancer and its MAC address from the Layer 7 load balancer cluster based on the destination IP address.
[0010] The destination MAC address is adjusted to the MAC address of the target layer 7 load balancer through the target layer 4 load balancer;
[0011] The target Layer 4 load balancer is controlled to send the access packet to the target Layer 7 load balancer based on the MAC address of the target Layer 7 load balancer, so that the target Layer 7 load balancer can obtain the destination IP address.
[0012] This application provides a load balancing device, the load balancing device comprising:
[0013] The first determining module is used to determine the target Layer 4 load balancer from the Layer 4 load balancer cluster based on the destination Media Access Control Address (MAC address) in the access message sent by the client.
[0014] The first receiving module is used to receive the access message using the target Layer 4 load balancer, wherein the access message carries a source IP address and a destination IP address;
[0015] The second determining module is used to control the target Layer 4 load balancer to determine the target Layer 7 load balancer and the MAC address of the target Layer 7 load balancer cluster based on the destination IP address.
[0016] The first adjustment module is used to adjust the destination MAC address to the MAC address of the target layer 7 load balancer through the target layer 4 load balancer.
[0017] The first sending module is used to control the target Layer 4 load balancer to send the access packet to the target Layer 7 load balancer based on the MAC address of the target Layer 7 load balancer, so that the target Layer 7 load balancer can obtain the destination IP address.
[0018] This application embodiment provides a load balancing device, the load balancing device comprising:
[0019] Processor; and
[0020] Memory for storing computer programs that can run on the processor;
[0021] The computer program, when executed by the processor, implements the aforementioned load balancing method.
[0022] This application provides a computer-readable storage medium storing computer-executable instructions configured to execute the above-described load balancing method.
[0023] This application provides a load balancing method, apparatus, device, and computer-readable storage medium. The load balancing method is applied to a distributed system, which includes a Layer 4 load balancer cluster and a Layer 7 load balancer cluster. Based on this, the load balancing method includes: the distributed system obtaining a destination Media Access Control (MAC) address carried in an access message sent by a client; determining a target Layer 4 load balancer from the Layer 4 load balancer cluster based on the destination MAC address; and then using the target Layer 4 load balancer to receive the access message, wherein the access message carries an active (Internet...)... The process involves several steps: First, the target Layer 4 load balancer selects the target Layer 7 load balancer from the Layer 7 load balancer cluster based on the destination IP address. It also determines the MAC address of the target Layer 7 load balancer, which is accessible through the destination IP address. Based on this, the target Layer 4 load balancer adjusts its destination MAC address to match that of the target Layer 7 load balancer. Finally, the target Layer 4 load balancer sends the access packet to the target Layer 7 load balancer using the target Layer 7 load balancer's MAC address. This allows the target Layer 7 load balancer to obtain the destination IP address from the access packet, thereby achieving isolation between different applications based on the destination IP address and ensuring the efficient and stable operation of each application. Attached Figure Description
[0024] In the accompanying drawings (which are not necessarily drawn to scale), similar reference numerals may describe similar parts in different views. The drawings illustrate, by way of example and not limitation, the various embodiments discussed herein.
[0025] Figure 1 This is a schematic diagram of an architecture of a soft load balancing system in related technologies.
[0026] Figure 2 This is a schematic diagram illustrating the implementation principle of the FULLNAT mode in related technologies;
[0027] Figure 3 This is a schematic diagram illustrating an implementation process of the load balancing method provided in an embodiment of this application;
[0028] Figure 4 A schematic diagram illustrating an implementation process of a method for determining a target Layer 7 load balancer and its MAC address, provided in an embodiment of this application.
[0029] Figure 5 A schematic diagram illustrating another implementation process of the load balancing method provided in the embodiments of this application;
[0030] Figure 6This is a schematic diagram illustrating an implementation flow of the method for determining a target application server provided in an embodiment of this application;
[0031] Figure 7 A schematic diagram illustrating an implementation process of a method for interaction between a distributed system and an application deployment platform provided in an embodiment of this application;
[0032] Figure 8 A schematic diagram of the APISIX architecture provided in this application embodiment;
[0033] Figure 9 A schematic diagram illustrating an implementation flow of a method for interaction between a Kubernetes platform and a distributed system provided in an embodiment of this application;
[0034] Figure 10 This is a schematic diagram of the composition structure of the load balancing device provided in the embodiments of this application;
[0035] Figure 11 This is a schematic diagram of the composition structure of the load balancing device provided in the embodiments of this application. Detailed Implementation
[0036] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0037] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0038] In the following description, the terms "first, second, third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0039] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0040] A schematic diagram of the architecture of a soft load balancing system based on related technologies is shown below. Figure 1As shown, the software load balancing system includes a client 101, a Layer 4 load balancer cluster (a load balancer cluster typically contains multiple Layer 4 load balancers 102), a Layer 7 load balancer cluster (a Layer 7 load balancer cluster typically contains multiple Layer 7 load balancers 103), and multiple application servers 104. The Layer 4 load balancer 102 is a high-performance load balancer based on the DataPlane Development Kit (DPDK). The Layer 7 load balancer 103 uses a high-performance Hypertext Transfer Protocol (HTTP) and reverse proxy for a WorldWide Web (WWW) server, which can be abbreviated as Nginx; the Layer 7 load balancer 103 can also use OpenResty.
[0041] refer to Figure 1 The soft load balancing system architecture uses DPVS as a Layer 4 soft load balancer and Nginx or OpenResty as a Layer 7 soft load balancer. Requests sent by the user through client 101 will first pass through Layer 4 soft load balancer 102, then through Layer 7 soft load balancer 103, and finally reach application server 104. The response returned by application server 104 will pass through Layer 7 soft load balancer 103 and Layer 4 soft load balancer 102 in sequence, and finally be delivered to the user through client 101.
[0042] Layer 4 software load balancers are used to configure independent VIPs for each application, and then distribute the load to Layer 7 software load balancers based on the VIP and port, resulting in extremely high performance. Layer 7 load balancers configure load balancing strategies based on domain name, access path, headers / cookies, etc.
[0043] In related technologies, the commonly used working mode of DPVS is FULLNAT mode. The implementation principle of FULLNAT is as follows: Figure 2 As shown:
[0044] Client 201 sends a VIP access message to DPVS server 202; DPVS server 202 modifies the destination address of the request message to the backend real server (DNAT) and the source address to its own IP address (SNAT), and sends it to backend real server 203; after processing, backend server 203 returns a response message to DPVS server 202; DPVS server 202 modifies the source address of the returned data packet to its own (SNAT) and the destination address to the client (DNAT), and sends it to client 201. Here, backend real server 203 refers to a Layer 7 load balancer.
[0045] refer to Figure 2 Client 201 requests the VIP address 10.87.5.45, but when transmitting the data to DPVS server 202, the source IP address is the actual VIP address, and the destination IP address changes to 220.67.8.10. Then, when DPVS server 202 transmits the data to the backend real server 203, the source IP address changes to 192.168.1.10, and the destination IP address changes to 192.168.10.11. As a result, backend server 203 cannot obtain the requested VIP address 10.87.5.45.
[0046] DPVS FULLNAT mode is similar to NAT mode, but unlike NAT mode which only performs two address translations, FULLNAT mode performs four address translations in the above process, causing the backend real server to fail to obtain the VIP due to a 203 error.
[0047] For the DPVS FULLNAT mode mentioned above, the user request IP address can be obtained by adding the toa module; however, regardless of whether the Layer 7 load balancer uses Nginx, Openresty, or APISIX, it cannot obtain the VIP, and therefore cannot isolate applications from each other.
[0048] To address the problems existing in related technologies, this application provides a load balancing method. This method can be implemented by a computer program, which, when executed, performs the load balancing method provided in this application. In some embodiments, the computer program can be executed on a processor in a distributed system. Figure 3 This application provides an implementation flow of a load balancing method, which is applied to a distributed system including a Layer 4 load balancer cluster and a Layer 7 load balancer cluster. Based on this, as follows... Figure 3 As shown, the load balancing method includes:
[0049] Step S301: Determine the target Layer 4 load balancer from the Layer 4 load balancer cluster based on the destination Media Access Control Address (MAC address) in the access message sent by the client.
[0050] Here, the client refers to the terminal that accesses the application, which can be a computer, smartphone, smart wearable device, etc.
[0051] In this embodiment, the access message carries a destination MAC address, which indicates the destination location of the access message at this stage; that is, the destination MAC address is the MAC address of the target Layer 4 load balancer. Based on this, the target load balancer can be determined from the Layer 4 load balancer cluster based on the destination MAC address.
[0052] In practice, when the client and the Layer 4 load balancer cluster are on the same network, the MAC address in the access packet sent by the client is the MAC address of the target Layer 4 load balancer. However, when the client and the Layer 4 load balancer cluster are not on the same network, the MAC address in the access packet will change every time it passes through a router or Layer 3 switch, and the changed MAC address is the MAC address of the target Layer 4 load balancer.
[0053] Step S302: Receive access packets using the target Layer 4 load balancer.
[0054] Here, after the target Layer 4 load balancer is determined, it is used to receive access packets. In actual implementation, the other Layer 4 load balancers besides the target Layer 4 load balancer do not receive the access packets.
[0055] In this embodiment, the access message carries a source IP address and a destination IP address. The source IP address refers to the client's IP address, and the destination IP address refers to the IP address of the application to be accessed. Specifically, when an application is created, the Layer 4 load balancer cluster configures a unique VIP address for each application; this VIP address is the destination IP address.
[0056] Step S303: Control the target Layer 4 load balancer to determine the target Layer 7 load balancer and its MAC address from the Layer 7 load balancer cluster based on the destination IP address.
[0057] Here, after the access packet reaches the target Layer 4 load balancer, it will control the target Layer 4 load balancer to first determine the target Layer 7 load balancer based on the destination IP address, and also determine the MAC address of the target Layer 7 load balancer.
[0058] In practical implementation, the target Layer 4 load balancer can be used to obtain the first mapping table between IP addresses and MAC addresses. Then, the target Layer 4 load balancer can be controlled to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address based on the first mapping table; this is the MAC address of the target Layer 7 load balancer. Furthermore, the target Layer 4 load balancer will also identify the Layer 7 load balancer corresponding to the MAC address of the target Layer 7 load balancer as the target Layer 7 load balancer.
[0059] Step S304: Adjust the destination MAC address to the target Layer 7 load balancer's MAC address through the target Layer 4 load balancer.
[0060] Here, the destination MAC address of the access packet is changed from the original MAC address of the target Layer 4 load balancer to the MAC address of the target Layer 7 load balancer, so that the access packet is sent to the target Layer 7 load balancer.
[0061] Step S305: Control the target Layer 4 load balancer to send access packets to the target Layer 7 load balancer based on the MAC address of the target Layer 7 load balancer, so that the target Layer 7 load balancer can obtain the destination IP address.
[0062] Here, the target load balancer is controlled to send access packets to the target load balancer based on the target Layer 7 load balancer's MAC address. When the target Layer 7 load balancer receives the access packet, it also receives the destination IP address carried in the access packet.
[0063] In some embodiments, the target Layer 7 load balancer may also send access packets to the corresponding target application server based on the destination IP address, so that the required application can be successfully accessed based on the target application server.
[0064] This application provides a load balancing method applied to a distributed system, which includes a Layer 4 load balancer cluster and a Layer 7 load balancer cluster. Based on this, the load balancing method includes: the distributed system obtaining a destination Media Access Control (MAC) request sent by a client. The system receives a MAC address access message and determines the target Layer 4 load balancer from the Layer 4 load balancer cluster based on the destination MAC address. Then, it receives the access message from the target Layer 4 load balancer, which carries the source (Internet Protocol, IP) address and the destination IP address. Next, the system controls the target Layer 4 load balancer to determine the target Layer 7 load balancer from the Layer 7 load balancer cluster based on the destination IP address, and also determines the MAC address of the target Layer 7 load balancer. The target Layer 7 load balancer can access the destination IP address. Based on this, the target Layer 4 load balancer adjusts the destination MAC address to the MAC address of the target Layer 7 load balancer. Finally, the system controls the target Layer 4 load balancer to send the access message to the target Layer 7 load balancer based on the MAC address of the target Layer 7 load balancer. This allows the target Layer 7 load balancer to obtain the destination IP address from the access message, thereby achieving isolation between different applications based on the destination IP address and ensuring the efficient and stable operation of each application.
[0065] In some embodiments, such as Figure 4 As shown, the above step S303, "controlling the target Layer 4 load balancer to determine the target Layer 7 load balancer and its MAC address from the Layer 7 load balancer cluster based on the destination IP address," can be achieved through the following steps S3031 to S3034:
[0066] Step S3031: Use the target Layer 4 load balancer to obtain the first mapping table of IP address and MAC address.
[0067] Here, when each application is created, the corresponding target Layer 7 load balancer for each application is also established. Furthermore, APISIX software can be deployed on the target Layer 7 load balancer to match the destination IP address. Based on this, the Layer 4 load balancer cluster stores a first mapping table between the IP addresses of each application and the MAC addresses of the corresponding target Layer 7 load balancer.
[0068] Step S3032: Control the target Layer 4 load balancer to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address based on the first mapping table.
[0069] Here, the target Layer 4 load balancer can be controlled to determine the MAC address corresponding to the destination IP address from the first mapping table.
[0070] Step S3033: Control the target Layer 4 load balancer to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address as the MAC address of the target Layer 7 load balancer.
[0071] Here, the MAC address corresponding to the destination IP address is the MAC address of the target Layer 7 load balancer.
[0072] Step S3034: Control the target Layer 4 load balancer to determine the Layer 7 load balancer corresponding to the MAC address of the target Layer 7 load balancer as the target Layer 7 load balancer.
[0073] Here, the target Layer 7 load balancer can be identified by its MAC address.
[0074] In this embodiment of the application, through the above steps S3031 to S3034, the first mapping table of IP address and MAC address can be obtained through the target Layer 4 load balancer. Then, the target Layer 4 load balancer is controlled to determine the MAC address corresponding to the destination IP address based on the first mapping table, which is the MAC address of the target Layer 7 load balancer. The target Layer 7 load balancer is also determined accordingly. In this way, the MAC address of the target Layer 7 load balancer and the target Layer 7 load balancer can be determined quickly and accurately, providing preparation conditions for the forwarding of subsequent access packets.
[0075] In some embodiments, the purpose of the client sending the access message is to access the target application server to obtain the corresponding resources. This involves interaction between the target Layer 7 load balancer and the target application server. Therefore, the distributed system also includes multiple application servers, such as... Figure 5 As shown, after step S305, "controlling the target Layer 4 load balancer to send access packets to the target Layer 7 load balancer based on the MAC address of the target Layer 7 load balancer, so that the target Layer 7 load balancer obtains the destination IP address," the load balancing method further includes the following steps S306 to S309:
[0076] Step S306: Control the target Layer 7 load balancer to determine the target application server from multiple target servers based on the destination IP address.
[0077] In actual implementation, such as Figure 6 As shown, step S306 above can be achieved through the following steps S3061 to S3063:
[0078] Step S3061: Utilize the target Layer 7 load balancer to receive the second mapping table between the destination IP address and the deployment unit IP address list sent by the application deployment platform.
[0079] Here, the application deployment platform sends a second mapping table between the destination IP address and the deployment unit IP address list to the target Layer 7 load balancer based on the trigger command. For example, the application deployment platform can be a containerized application deployment platform.
[0080] In this embodiment, the deployment unit IP address can be the IP address of an application container engine. For example, when the application deployment platform is Kubernetes, the deployment unit IP address can be a pod IP address, wherein there is a correspondence between the pod IP address and the application server. The second mapping table is used to represent the relationship between the destination IP address and the list of deployment unit IP addresses.
[0081] Step S3062: Control the target Layer 7 load balancer to determine the list of target deployment unit IP addresses corresponding to the destination IP address based on the second mapping relationship table.
[0082] Here, since the second mapping table stores the mapping relationship between the destination IP address and the list of deployment unit IP addresses, the target deployment unit IP address list corresponding to the destination IP address can be determined from the second mapping table by the target Layer 7 load balancer.
[0083] In practice, there is a one-to-one correspondence between IP addresses and applications. Furthermore, an application can be deployed across multiple deployment units; that is, there is a one-to-many correspondence between applications and deployment units. Based on this, a one-to-many correspondence exists between IP addresses and deployment units.
[0084] Step S3063: Control the target Layer 7 load balancer to determine the target application server based on the target deployment unit IP address list.
[0085] Here, based on the mapping between deployment unit IP addresses and application servers, the target Layer 7 load balancer can be controlled to determine the corresponding target application server based on the target deployment unit IP address list. The mapping between deployment unit IP addresses and application servers can be one-to-one.
[0086] Step S307: Use the target Layer 7 load balancer to send the access message to the target application server.
[0087] Here, the target Layer 7 load balancer is used to forward the access packets to the target application server so that the client can access the server successfully.
[0088] Step S308: Obtain the access resource by utilizing the target application server's response to the received access message.
[0089] Here, after the target application server receives the access message, it will obtain the corresponding resource information from itself based on the access message, that is, obtain the accessed resource.
[0090] Step S309: Control the target application server to return the accessed resources to the client through the target Layer 7 load balancer.
[0091] Here, when returning the accessed resource to the client, the return path of the accessed resource goes through the target Layer 7 load balancer and finally reaches the client.
[0092] In this embodiment, through steps S306 to S309, the target Layer 7 load balancer first receives a second mapping table between the destination IP address and the deployment unit IP address list sent by the application deployment platform. Based on the second mapping table, the target deployment unit IP address list and the target application server are determined sequentially. Next, the target Layer 7 load balancer sends the access packet to the target application server. Then, the target application server responds to the received access packet by obtaining the access resource. Finally, the access resource passes sequentially through the target Layer 7 load balancer and the target Layer 4 load balancer, ultimately returning to the client, completing one access operation for the client. Throughout the access process, the target Layer 4 load balancer sends the destination IP address to the target Layer 7 load balancer via direct routing, enabling the target Layer 7 load balancer to obtain the destination IP address. Furthermore, the target Layer 7 load balancer can achieve mutual isolation between different destination IP addresses based on the destination IP address, that is, mutual isolation between different applications.
[0093] In some embodiments, the application deployment platform may pre-build a second mapping table. Based on this, before executing step S306 above, steps one and two may be executed to enable the application deployment platform to complete the construction of the second mapping table.
[0094] Step 1: Use the target Layer 4 load balancer to send the destination IP address to the application deployment platform.
[0095] Here, when the target application is created, the target Layer 4 load balancer will configure a destination IP address for the target application. Based on this, the client can use the destination IP address to access the target application.
[0096] In this embodiment, the target Layer 4 load balancer also sends the destination IP address to the application deployment platform. The application deployment platform is used to deploy various applications on a distributed system.
[0097] Step 2: The application deployment platform constructs a second mapping table between the destination IP address and the list of deployment unit IP addresses based on the destination IP address.
[0098] Here, after obtaining the destination IP address, the application deployment platform will automatically establish a second mapping relationship between the destination IP address and the list of deployment unit IP addresses, and will also complete the deployment of the target application, that is, deploy the target application to the target application server.
[0099] In some embodiments, in order to obtain the second mapping table of the newly deployed application, the distributed system also involves an interaction process with the application deployment platform, such as... Figure 7 As shown, the interaction process includes:
[0100] Step S701: Determine whether the distributed system has deployed new applications on multiple application servers.
[0101] Here, the status of each application server can be monitored to determine whether a new application is being deployed in the distributed system. If application registration and related resource information are detected being written to the application server, it is determined that the distributed system is deploying a new application on multiple application servers, and the process proceeds to step S702. If no application registration and related resource information are detected being written to any application server, that is, the data stored in all application servers has not changed, it is determined that the distributed system is not deploying a new application on multiple application servers, and the process proceeds to step S706.
[0102] Step S702: Control the Layer 4 load balancer cluster to create a new destination IP address corresponding to the new application.
[0103] Here, when a distributed system deploys a new application on multiple application servers, it controls the Layer 4 load balancer cluster to create a new destination IP address for the new application. This new destination IP address is different from any existing destination IP address.
[0104] Step S703: Control the Layer 4 load balancer cluster to send the new destination IP address to the application deployment platform.
[0105] Here, in order to achieve automatic linkage between the distributed platform and the application deployment platform, the Layer 4 load balancer cluster will also send the new destination IP address to the application deployment platform.
[0106] Step S704: The application deployment platform constructs a new second mapping table between the new destination IP address and the list of deployment unit IP addresses based on the new destination IP address.
[0107] Here, the implementation process of step S704 is similar to that of step two above. Therefore, the implementation process of step S704 can refer to the implementation process of step two above.
[0108] Step S705: Control the Layer 7 load balancer cluster to receive the new second mapping table through the application programming interface (API).
[0109] To simplify the configuration process and improve efficiency, the distributed system also controls the Layer 7 load balancer cluster to receive the new second mapping table via an API interface. This eliminates the need to modify or reload the entire configuration file.
[0110] Step S706: Determine whether there are any faulty application servers among the multiple application servers in the distributed system.
[0111] Here, the distributed system does not deploy new applications on multiple application servers. Instead, it checks whether there are any faulty application servers among the multiple application servers. In actual implementation, heartbeat detection can be used to determine whether there are any faulty application servers.
[0112] In this embodiment of the application, if there is a faulty application server, the process proceeds to step S707; otherwise, it returns to step S701.
[0113] In step S707, the list of deployment unit IP addresses of the application deployment platform changes. The application deployment platform updates the second mapping table corresponding to the faulty application based on the changed list of deployment unit IP addresses to obtain the updated second mapping table.
[0114] Here, if a faulty application server exists, it will cause a change in the deployment unit IP address list. The application deployment platform then updates the second mapping table corresponding to the faulty application based on the changed deployment unit IP address list. That is, it replaces the deployment unit IP address with the changed deployment unit IP address list, thereby obtaining an updated second mapping table containing the changed deployment unit IP address list. Here, the faulty application is the application deployed on the faulty application server.
[0115] Step S708: Control the Layer 7 load balancer cluster to receive the updated second mapping table through the API interface.
[0116] Here, the implementation process of step S708 is similar to that of step S705 above. Therefore, the implementation process of step S708 can refer to the implementation process of step S705 above.
[0117] In this embodiment, through steps S701 to S708, on the one hand, when deploying a new application, the Layer 4 load balancer cluster creates a new destination IP address for the new application and sends it to the application deployment platform. This allows the application deployment platform to build a new second mapping table between the new destination IP address and the deployment unit IP address list. Finally, the Layer 7 load balancer cluster receives the new second mapping table through the API interface. On the other hand, when a faulty application server exists, the application deployment platform updates the second mapping table of the faulty application based on the changed deployment unit IP address list, thus obtaining the updated second mapping table. The Layer 7 load balancer cluster still receives the updated second mapping table through the API interface. Thus, when the second mapping table is created or changes, automatic linkage between the distributed system and the application deployment platform can be achieved without external intervention, improving the operating efficiency of the distributed system. Furthermore, the configuration process can be simplified based on the API interface, improving configuration efficiency without needing to modify or load the entire configuration file.
[0118] Based on the above embodiments, this application further provides a load balancing method, which includes:
[0119] First, use the microservice API gateway (APISIX) instead of traditional Nginx or Openresty.
[0120] Here, APISIX is an open-source cloud-native API gateway. However, using it as a Layer 7 soft load balancer not only meets performance requirements but also offers advantages such as supporting API call configuration modification, real-time configuration changes taking effect, using a database as a configuration center, and rapid horizontal scaling. The APISIX architecture is as follows: Figure 8 As shown, the architecture includes an API client 801, a Layer 4 load balancer (LB) 802, a Layer 7 load balancer (APISIX API Gateway) 803, and a database (etcd) 804. The Layer 7 load balancer (APISIX API Gateway) 803 contains multiple application servers (RealServers) 8031.
[0121] Second, Layer 4 DPVS uses Direct Routing (DR) mode.
[0122] Here, the fourth-layer DPVS uses the DR mode instead of the commonly used FULLNAT mode. The principle of the DR mode is as follows:
[0123] The client sends an access VIP message to the DPVS server; the DPVS server modifies the destination MAC address of the request message to the MAC address of the backend APISIX server, but does not modify the source and destination IP addresses. After processing, the APISIX server returns a response message to the user.
[0124] In this embodiment of the application, after using DR mode, the data packet only modifies the destination MAC address of the data packet after passing through DPVS, while the source IP (i.e., client IP) and destination IP (i.e. VIP) are retained, so that the Layer 7 load balancer can obtain the VIP.
[0125] Third, based on the open-source apisix-ingress, we added integration with the four-layer DPVS platform.
[0126] Here, when creating an application, the application name is used as a unique identifier to request a VIP from the Layer 4 platform; after successful request, the VIP is recorded. An Agent is then developed, which calls the Agent's REST API interface to bind the VIP to the network interface card of each Layer 7 soft load balancer node. Here, `ingress` is a script in the Kubernetes platform.
[0127] In the embodiments of this application, Figure 9 This provides an interaction diagram between the Kubernetes platform and the distributed system. Figure 9 In this process, Ingress obtains configuration information from the Kubernetes platform. Based on this, the interaction process includes steps S901 to S904:
[0128] Step S901: When creating an instance, call the Layer 4 load balancer cluster management interface to create the instance and obtain the VIP.
[0129] This means that when creating an instance, Ingress will obtain the VIP from the Layer 4 load balancer cluster.
[0130] Step S902: After the pod changes, call the Layer 7 load balancer cluster management interface to create routes and upstreams.
[0131] This refers to the creation of a pod when an instance is created or when the pod changes.
[0132] Step S903: The four-layer load balancer cluster adopts DR mode.
[0133] In step S904, the Layer 7 load balancer cluster interacts with the application server via HTTP.
[0134] Fourth, instances are isolated from each other when creating routes to APISIX.
[0135] Here, after DPVS is changed to DR mode, the destination IP is the VIP. When creating a route to APISIX, the VIP is used as the matching condition for the route's "destination IP". If the user comes from another application, the destination IP will not be the same, and the policy will not be matched, thus achieving the purpose of isolation between different applications.
[0136] The load balancing method provided in this application allows for the configuration of both Layer 4 and Layer 7 load balancing via REST API calls, eliminating the need to reload configuration files and ensuring real-time configuration validity without waiting. It also resolves the jitter issues caused by nginx or openresty. Applications are isolated from each other via VIPs, eliminating reliance on domain names and DNS services. The distributed system integrates with Kubernetes, automatically requesting and configuring VIPs via ingress without manual intervention.
[0137] Based on the foregoing embodiments, this application provides a load balancing device. The modules and units included in the device can be implemented by a processor in a computer device; of course, they can also be implemented by corresponding logic circuits. In the implementation process, the processor can be a central processing unit (CPU), a microprocessor unit (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA), etc.
[0138] This application embodiment further provides a load balancing device. Figure 10 This is a schematic diagram of the composition structure of the load balancing device provided in the embodiments of this application, as shown below. Figure 10 As shown, the load balancing device 1000 includes:
[0139] The first determining module 1001 is used to determine the target Layer 4 load balancer from the Layer 4 load balancer cluster based on the destination Media Access Control Address (MAC address) in the access message sent by the client.
[0140] The first receiving module 1002 is used to receive the access message using the target Layer 4 load balancer, wherein the access message carries a source IP address and a destination IP address;
[0141] The second determining module 1003 is used to control the target Layer 4 load balancer to determine the target Layer 7 load balancer and the MAC address of the target Layer 7 load balancer from the Layer 7 load balancer cluster based on the destination IP address.
[0142] The first adjustment module 1004 is used to adjust the destination MAC address to the MAC address of the target layer 7 load balancer through the target layer 4 load balancer.
[0143] The first sending module 1005 is used to control the target Layer 4 load balancer to send the access packet to the target Layer 7 load balancer based on the MAC address of the target Layer 7 load balancer, so that the target Layer 7 load balancer can obtain the destination IP address.
[0144] In some embodiments, the second determining module 1003 includes:
[0145] The first acquisition submodule is used to obtain the first mapping table between IP address and MAC address using the target Layer 4 load balancer;
[0146] The first determining submodule is used to control the target Layer 4 load balancer to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address based on the first mapping table.
[0147] The second determining submodule is used to control the target Layer 4 load balancer to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address as the MAC address of the target Layer 7 load balancer.
[0148] The third determination submodule is used to control the target layer 4 load balancer to determine the layer 7 load balancer corresponding to the MAC address of the target layer 7 load balancer as the target layer 7 load balancer.
[0149] In some embodiments, the load balancing device 1000 further includes:
[0150] The third determining module is used to control the target Layer 7 load balancer to determine the target application server from the plurality of target servers based on the destination IP address;
[0151] The second sending module is used to send the access message to the target application server using the target Layer 7 load balancer.
[0152] In some embodiments, the third determining module includes:
[0153] The first receiving submodule is used to receive, using the target Layer 7 load balancer, a second mapping table between the destination IP address and the deployment unit IP address list sent by the application deployment platform;
[0154] The fourth determining submodule is used to control the target Layer 7 load balancer to determine the list of target deployment unit IP addresses corresponding to the destination IP address based on the second mapping relationship table;
[0155] The fifth determination submodule is used to control the target Layer 7 load balancer to determine the target application server based on the target deployment unit IP address list.
[0156] In some embodiments, the load balancing device 1000 further includes:
[0157] The third sending module is used to send the destination IP address to the application deployment platform using the target Layer 4 load balancer, so that the application deployment platform can construct a second mapping table between the destination IP address and the deployment unit IP address list based on the destination IP address.
[0158] In some embodiments, the load balancing device 1000 further includes:
[0159] The first creation module is used to control the Layer 4 load balancer cluster to create a new destination IP address corresponding to the new application when the distributed system deploys a new application on the multiple application servers, and send the new destination IP address to the application deployment platform so that the application deployment platform can construct a new second mapping relationship table between the new destination IP address and the deployment unit IP address list based on the new destination IP address;
[0160] The first receiving module is used to control the seven-layer load balancer cluster to receive the new second mapping table through the application programming interface (API).
[0161] The second creation module is used to cause a change in the deployment unit IP address list when there is a faulty application server among the multiple application servers in the distributed system, so that the application deployment platform updates the second mapping relationship table corresponding to the faulty application based on the changed deployment unit IP address list, and obtains the updated second mapping relationship table.
[0162] The second receiving module is used to control the Layer 7 load balancer cluster to receive the updated second mapping table through the API interface, wherein the faulty application is the application deployed in the faulty application server.
[0163] In some embodiments, the load balancing device 1000 further includes:
[0164] The response module is used to obtain access resources by utilizing the target application server's response to the received access message;
[0165] The return module is used to control the target application server to return the accessed resources to the client through the target Layer 7 load balancer.
[0166] It should be noted that the description of the load balancing device in this application embodiment is similar to the description of the method embodiment described above, and has similar beneficial effects. For technical details not disclosed in this device embodiment, please refer to the description of the method embodiment of this application for understanding.
[0167] It should be noted that, in the embodiments of this application, if the above-described load balancing method is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, or the part that contributes to the related technology, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.
[0168] Accordingly, embodiments of this application provide a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the load balancing method provided in the above embodiments.
[0169] This application provides a load balancing device. Figure 11 This is a schematic diagram of the composition structure of the load balancing device provided in the embodiments of this application, as shown below. Figure 11 As shown, the load balancing device 1100 includes: a processor 1101, at least one communication bus 1102, a user interface 1103, at least one external communication interface 1104, and a memory 1105. The communication bus 1102 is configured to enable communication between these components. The user interface 1103 may include a display screen, and the external communication interface 1104 may include standard wired and wireless interfaces. The processor 1101 is configured to execute a program of a load balancing method stored in the memory to implement the load balancing method provided in the above embodiment.
[0170] The descriptions of the load balancing devices and storage media embodiments above are similar to those of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the load balancing devices and storage media embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0171] It should be noted that the descriptions of the above embodiments of the storage medium and load balancing device are similar to the descriptions of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the embodiments of the storage medium and load balancing device of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0172] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely descriptive and do not represent the superiority or inferiority of the embodiments.
[0173] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0174] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.
[0175] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of the embodiments of this application, depending on actual needs.
[0176] In addition, each functional unit in the various embodiments of this application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0177] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0178] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an AC to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0179] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A load balancing method applied to a distributed system, characterized in that, The distributed system includes a Layer 4 load balancer cluster and a Layer 7 load balancer cluster, and the method includes: The target Layer 4 load balancer is determined from the Layer 4 load balancer cluster based on the destination Media Access Control (MAC) address in the access message sent by the client, wherein the destination Media Access Control (MAC) address is the MAC address of the target Layer 4 load balancer. The target Layer 4 load balancer receives the access packet, wherein the access packet carries a source IP address and a destination IP address, and the destination IP address is an independent VIP address configured by the Layer 4 load balancer cluster for the application. Controlling the target Layer 4 load balancer to determine the target Layer 7 load balancer and its MAC address from the Layer 7 load balancer cluster based on the destination IP address includes: using the target Layer 4 load balancer to obtain a first mapping table between IP address and MAC address. The target Layer 4 load balancer is controlled to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address based on the first mapping table. The target Layer 4 load balancer is controlled to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address as the MAC address of the target Layer 7 load balancer; Control the target Layer 4 load balancer to determine the Layer 7 load balancer corresponding to the MAC address of the target Layer 7 load balancer as the target Layer 7 load balancer; The destination MAC address is adjusted to the MAC address of the target layer 7 load balancer through the target layer 4 load balancer; The target Layer 4 load balancer is controlled to send the access packet to the target Layer 7 load balancer based on the MAC address of the target Layer 7 load balancer, so that the target Layer 7 load balancer can obtain the destination IP address. The distributed system also includes multiple application servers, and the method further includes: Controlling the target Layer 7 load balancer to determine the target application server from the plurality of application servers based on the destination IP address includes: The target Layer 7 load balancer receives a second mapping table between the destination IP address and the list of deployment unit IP addresses sent by the application deployment platform. The target Layer 7 load balancer is controlled to determine the list of target deployment unit IP addresses corresponding to the destination IP address based on the second mapping table. The target Layer 7 load balancer is controlled to determine the target application server based on the target deployment unit IP address list; The access message is sent to the target application server using the target Layer 7 load balancer.
2. The method according to claim 1, characterized in that, The method further includes: The target Layer 4 load balancer sends the destination IP address to the application deployment platform, so that the application deployment platform can construct a second mapping table between the destination IP address and the list of deployment unit IP addresses based on the destination IP address.
3. The method according to claim 1, characterized in that, The method further includes: When the distributed system deploys a new application on the multiple application servers, it controls the Layer 4 load balancer cluster to create a new destination IP address corresponding to the new application and sends the new destination IP address to the application deployment platform, so that the application deployment platform can construct a new second mapping table between the new destination IP address and the deployment unit IP address list based on the new destination IP address; The control system receives the new second mapping table through the application programming interface (API). When a faulty application server exists among the multiple application servers in the distributed system, the IP address list of the deployment unit is changed, so that the application deployment platform updates the second mapping table corresponding to the faulty application based on the changed IP address list of the deployment unit, and obtains the updated second mapping table. The control layer 7 load balancer cluster receives the updated second mapping table through the API interface, wherein the faulty application is the application deployed in the faulty application server.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: The target application server responds to the received access message to obtain the access resource; The target application server is controlled to return the accessed resources to the client through the target Layer 7 load balancer.
5. A load balancing device, characterized in that, The load balancing device includes: The first determining module is used to determine the target Layer 4 load balancer from the Layer 4 load balancer cluster based on the destination Media Access Control Address (MAC address) in the access message sent by the client, wherein the destination Media Access Control Address (MAC address) is the MAC address of the target Layer 4 load balancer. The first receiving module is used to receive the access message using the target Layer 4 load balancer, wherein the access message carries a source IP address and a destination IP address, and the destination IP address is an independent VIP address configured by the Layer 4 load balancer cluster for the application. The second determining module is used to control the target Layer 4 load balancer to determine the target Layer 7 load balancer and the MAC address of the target Layer 7 load balancer from the Layer 7 load balancer cluster based on the target IP address, including: using the target Layer 4 load balancer to obtain a first mapping table between IP address and MAC address; The target Layer 4 load balancer is controlled to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address based on the first mapping table. The target Layer 4 load balancer is controlled to determine the MAC address of the Layer 7 load balancer corresponding to the destination IP address as the MAC address of the target Layer 7 load balancer; Control the target Layer 4 load balancer to determine the Layer 7 load balancer corresponding to the MAC address of the target Layer 7 load balancer as the target Layer 7 load balancer; The first adjustment module is used to adjust the destination MAC address to the MAC address of the target layer 7 load balancer through the target layer 4 load balancer. The first sending module is used to control the target Layer 4 load balancer to send the access packet to the target Layer 7 load balancer based on the MAC address of the target Layer 7 load balancer, so that the target Layer 7 load balancer can obtain the destination IP address. The distributed system also includes multiple application servers, and the device is further used for: Controlling the target Layer 7 load balancer to determine the target application server from the plurality of application servers based on the destination IP address includes: The target Layer 7 load balancer receives a second mapping table between the destination IP address and the list of deployment unit IP addresses sent by the application deployment platform. The target Layer 7 load balancer is controlled to determine the list of target deployment unit IP addresses corresponding to the destination IP address based on the second mapping table. The target Layer 7 load balancer is controlled to determine the target application server based on the target deployment unit IP address list; The access message is sent to the target application server using the target Layer 7 load balancer.
6. A load balancing device, characterized in that, The load balancing device includes: Processor; and Memory for storing computer programs that can run on the processor; The computer program, when executed by a processor, implements the load balancing method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions configured to perform the load balancing method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Message sending method, device, system, electronic device and storage medium
CN109495526A
Load balancing method and system
CN110928637A