LVS (Linux virtual server)
Linux virtual server (LVS) is designed to meet the needs of highly scalable and highly available network services. It provides a load balancing scheduling solution based on the IP layer and content request distribution, these methods are implemented in the Linux kernel to form a group of servers as a virtual server that implements scalable and highly available network services. Therefore, LVS requires kernel ipvs support. After kernel supports ipvs, you only need to install ipvsadm to configure a server as a Load balancer ). The IP address that provides external services, that is, the IP address we access is called VIP. The scheduler LB mainly distributes requests and processes real servers ).
Three Load Balancing models of LVS:
To distinguish these three models, we can first make a comparison
|
Nat Model |
Dr Model |
Tun Model |
Cluster node (RIP and DIP) |
Must be in the same subnet |
Must be in the same physical network |
Do not need to be in a physical network |
Rip requirements |
Private address, used only between nodes |
You can use a public IP address. |
It must not be a private address. |
Request processed by ctor |
Process inbound and outbound traffic |
Process inbound only |
Process inbound only |
Real-Server Gateway |
To point to dip |
It cannot point to dip, but to vro. |
It cannot point to dip, but to vro. |
Port ing |
Yes |
Cannot be implemented |
Cannot be implemented |
Real-server requirements |
Any Operating System |
Supports most operating systems |
It must be an operating system that supports tunneling. |
Note: rip is the real-Server IP address and dip is the director IP address.
LVS-NAT data forwarding process is: Director machine received external requests, rewrite the destination address of the packet, according to the corresponding scheduling algorithm to send it to the corresponding real server, after the real server processing the request, return the result packet to the default gateway, that is, the Director machine. Then, rewrite the source address of the data packet and return it to the outside world. This completes a load scheduling.
Load Balancing cluster in LVS-NAT mode (figure 1)
Note: In a LVS-NAT cluster, Real Server can be any operating system without any special settings. The only thing to do is to direct its default gateway to the Director machine. Real Server can use the internal IP address of the LAN (192.168.0.0/24 ). Director has two NICs. One is bound to an external IP address (10.0.0.1) and the other is bound to an internal IP address (192.168.0.254) of the LAN. This serves as the default gateway of the Real Server.
The LVS-DR's data forwarding process is: Director machine receives external requests, according to the corresponding scheduling algorithm to directly send it to the corresponding real server, after the real server processing the request, return the result packet directly to the customer to complete a load scheduling.
Load Balancing cluster in LVS-DR mode (figure 2)
In the LVS-DR cluster, note that the kernel of the Real Server must also be installed with Kernel patches to fix ARP problems.
The LVS-TUN's data forwarding process is: Director machine receives external requests, according to the corresponding scheduling algorithm to send it through the IP tunnel to the corresponding real server, after the real server processes the request, return the result packet directly to the customer. So far, a load scheduling is completed.
LVS-TUN Load Balancing cluster (figure 3)
Note in the LVS-TUN cluster that the kernel of the Real Server must be patched with Kernel patches that fix ARP issues. In this method, ctor distributes customer requests to different real servers, and the real server directly responds to the user after processing the requests. In this way, Director only processes half of the connections between the client and the server, the scheduling and processing capabilities of ctor are greatly improved, so that the cluster system can accommodate more nodes. In addition, the real server in the Tun mode can run on any LAN or WAN, so as to build a cross-region cluster, and its ability to respond to disasters is also stronger, however, the server requires a certain amount of resource overhead for IP encapsulation, And the backend Real Server must be an operating system that supports IP tunneling.
Ten LVS Scheduling Methods
The RR scheduler distributes external requests in turn to the real servers in the cluster. It treats each server equally, regardless of the actual number of connections on the server and system load, each server has the same quantity.
The Weighted Round Robin (WRR) scheduler schedules access requests based on different processing capabilities of the Real Server. This ensures that servers with high processing capabilities can process more access traffic. The scheduler can automatically query the actual server load and dynamically adjust its weight.
The target address hash identifies the corresponding server from the static allocation hash list based on the target IP address of the request as the hash key. If the server is available and not overloaded, send the request to the server. Otherwise, null is returned.
The source address hashing identifies the corresponding server from the static allocation hash list based on the requested source IP address as the hash key. If the server is available and not overloaded, send the request to the server. Otherwise, null is returned.
The least Link (LC) Schedules requests to servers with the least number of established connections based on the RS Algorithm.
Rs = active * 256 + inactive = overhead active connections, inactive connections, the smaller the overhead value, the more connected
When the server performance of the weighted least Link (wlc) in the cluster system varies greatly, we must consider the server performance based on the RS Algorithm, servers with higher weights will bear a large proportion of the active connection load.
The shortest expected latency (SED) is based on the wlc, but it changes. Based on (Active + 1) * 256/Weight = overhead, the smaller the value, the server connected.
No queue is required for minimum queue Scheduling (NQ. If the number of connections to a RealServer is equal to 0, the server is directly allocated. You do not need to perform the SED operation.
Load Balancing Based on the local least Link (lblc) for the target IP address is currently mainly used in the cache cluster system. This algorithm finds the Server recently used by the target IP address of the request. If the server is available and is not overloaded, the request is sent to the server. If the server does not exist, alternatively, if the server is overloaded and has half of the server's workload, select an available server based on the "minimum link" principle and send the request to the server.
The local least Link (lblcr) with replication is also used for load balancing of the target IP address. It is mainly used in the cache cluster system. It differs from the lblc Algorithm in that it maintains the ing from a target IP address to a group of servers. The lblc algorithm maintains the ing from a target IP address to a server. This algorithm finds the server group corresponding to the target IP address based on the requested target IP address, and selects a server from the server group based on the "minimum connection" principle. If the server is not overloaded, send the request to the server. If the server is overloaded, select a server from the cluster based on the "minimum connection" principle, add the server to the server group, and send the request to the server. At the same time, when the server group has not been modified for a period of time, delete the busiest server from the server group to reduce the degree of replication.
This article is from the "too many others blog", please be sure to keep this source http://fengjunfei.blog.51cto.com/4356100/834800