Comparison of three implementation modes of load balancing software LVS

A load balancing cluster, as the name suggests, is to let multiple servers share the pressure. Load balancing is an important module required for enterprise-level large-scale projects.

The current excellent open source software for implementing load balancing clusters include LVS, Nginx, haproxy, keepalived, etc., while excellent commercial load balancing devices include F5, NetScaler, etc. Commercial load balancing equipment is stable, but expensive.

Next, let's introduce the load balancing software LVS.

 

1. Introduction to LVS

LVS (Linux Virtual Server) is an open source load balancing software developed by domestic Daniel Zhang Wensong. It is a four-layer load balancing software, that is, the forwarding and routing of the TCP/IP protocol (IP+port) based on the fourth-layer transport layer of the OSI model. High stability and efficiency.

The LVS architecture is shown in the figure. The core role is the scheduler LB (Load Blancer), which is used to distribute user requests; and the remaining real server RS ​​(Real Server), which is used to process user requests.

The LB is the gateway server, and the public IP is used for external services. It is also called VIP (Virtual IP) in the cluster, that is, virtual IP, or floating IP. The server relies on this IP to provide services to the outside world, but this IP is not the IP of the real server RS ​​that actually handles user requests, so it is called a virtual IP.

 

 

Two, three LVS modes

LVS can be divided into three types according to different implementation methods: NAT mode, IP Tunnel (IP tunnel) mode, and DR mode.

(1) NAT mode

NAT (Network Address Translation, Network Address Translation), a solution to solve the problem of insufficient ipv4 addresses. The main idea is to divide the network into public and private networks, a LAN is controlled by a gateway, and the NAT gateway has two network cards, the public IP and the intranet IP, so that the hosts of a LAN only need to use one public IP, reducing resource occupation.

The NAT mode of LVS uses the NAT standard, and the scheduler LB is a NAT gateway, which forwards the user's request to the back-end RS through the preset iptables rules using the switch/router . The LB has two IPs, one is the public IP and the other is the internal IP, while the RS has only the internal IP. The user access address is the public IP of the LB. After receiving the user request, the LB will use the scheduling algorithm to calculate the request and forward it to the RS in the intranet. The source and destination addresses are forwarded through the intranet IP of the LB and the RS.

The advantage of this mode is to save public network IP, but the performance of LB is the bottleneck.

The architecture is shown in the figure.

 

 

(2) IP Tunnel mode

IP tunneling technology: It is a process in which a router encapsulates a network layer protocol into another protocol to transmit it across the network to another router.
Tunneling is a packet encapsulation technique that encapsulates an original IP packet (whose header contains the original sender and final destination) in the data payload of another packet (called an encapsulated IP packet) for transmission.
In this way, the packet can be forwarded to another IP address in the package after reaching the first IP address, such as the well-known VPN technology.
 
In the IP tunnel architecture of LVS, because it is a server cluster, it is impossible to statically establish a one-to-one corresponding tunnel. Instead, it is necessary to encapsulate and forward packets to a dynamically selected RS, so that the packets on a group of servers can be encapsulated and forwarded. Network services form a virtual network service on an IP.
Tunnel mode operation: After the LB receives the packet requested by the user as the cluster VIP (virtual IP for external services), it selects a target RS through the scheduling algorithm, and uses its IP address to encapsulate the request packet and forward it to the RS. After receiving the packet, the target RS parses the packet and obtains the packet whose source and destination address is the VIP. The server finds that the VIP address is configured on the local IP tunnel device, so it processes the request, and then directly responds to the packet according to the routing table iptables. returned to the user.
In this mode, it is necessary to allocate public IPs to the LB and all RSs, which is a waste of public IPs.
The architecture is shown in the figure.

 

 

(3) DR mode

The principle is the same as the Tunnel mode. However, instead of using tunneling technology and IP encapsulation, the MAC address of the data frame is changed to the MAC address of the RS. The LB and RS must be in the same network segment before they can be directly forwarded through the MAC address. Finally, the RS directly returns the response result to the user.

The architecture is shown in the figure.

 

 

3. Summary

NAT mode is suitable for small server clusters, and has the advantage of saving public IP. The difference between TUN and DR is similar, and both can support large-scale clusters, but the disadvantage is that the public network IP is wasted.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324733613&siteId=291194637