1.LVS Introduction
LVS is a Linux virtual server, a Linux VPN. Can achieve simple load balancing under Linux platform. In general, LVS uses a three-tier structure: Load scheduler, server pool, shared storage. Work in the TCP/IP protocol layer Four, its forwarding is dependent on the characteristics of the four layer protocol forwarding, because its forwarding to rely on the characteristics of the Protocol to be forwarded, so it needs to filter the TCP/IP protocol stack in the kernel, it is conceivable that this needs to be done in the kernel module, And such filtering and forwarding rules are defined by the administrator, so, LVs is a two-segment architecture design, in the kernel space to work is "Ipvs", and in the user space, to define the Cluster service rules is "Ipvsadm". Similar to iptables, it works on the input chain and cannot be used simultaneously because it is in conflict with Iptables.
2.LVS type
1). NAT Model
This is through the network address translation method to achieve scheduling. First the dispatcher (director) receives the client's request packet (the destination IP for the request is VIP), and according to the scheduling algorithm, decides which backend to send the request to the real server (RS). The scheduler then changes the destination IP address and port of the request packet sent by the client to the IP address (RIP) of the backend real server, so that the real server (RS) can receive the client's request packet. After the real server responds to the request, look at the default route (NAT mode we need to set the RS default route to the director server.) After sending the response data packets to Director,director and receiving the response packet, the source address of the package is changed to the virtual address (VIP) and then sent back to the client.
Nat Mode Features:
The cluster node and director must be in the same IP network;
RIP is usually a private address and is used only for communication between cluster nodes;
The director is located between the client and the real server and is responsible for handling all incoming and outgoing communications;
Realserver must point the gateway to the dip;
Support port mapping;
Realserver can use any OS;
In larger-scale scenarios, director becomes a bottleneck in the system.
2). Dr Model
The DR Mode sends the request to the real server by overwriting the destination MAC address of the request message, and the processing result of the real server response is returned directly to the client user. As with Tun mode, Dr Mode can greatly improve the scalability of the cluster system. And Dr Mode does not have the overhead of IP tunneling, and it is not necessary to support the requirements of IP tunneling protocol for real servers in the cluster. But requires that the scheduler lb and real server RS have a NIC connected to the same physical network segment, must be in the same LAN environment.
Dr Model features:
The cluster node and director must be in the same physical network;
RIP can use the public network address, to achieve convenient remote management and monitoring;
The Director is only responsible for processing inbound requests, and the response messages are sent directly to the client by Realserver;
Realserver cannot point the gateway to the dip;
Port mappings are not supported;
3). Tun model
When using NAT mode, the Scheduler processing power becomes a bottleneck as the request and response messages must be rewritten through the dispatcher address. To solve this problem, the scheduler forwards the requested message over the IP tunnel to the real server. The real server returns the response processed data directly to the client. In this way, the dispatcher only processes the request inbound message, because the General Network Service answer data is much larger than the request message, after adopting the Vs/tun mode, the maximum throughput of the cluster system can be increased 10 times times.
Tun Model Features:
Cluster nodes can span the Internet;
RIP must be a public network address;
The Director is only responsible for processing inbound requests, and the response messages are sent directly to the client by Realserver;
Realserver Gateway cannot point to Director;
Only the tunnel-enabled OS can be used for realserver;
Port mappings are not supported;
3.LVS Scheduling method
LVs scheduling method is divided into two types: static scheduling method and dynamic scheduling method.
Static Scheduling method:
RR: The scheduler uses the "round-robin" scheduling algorithm to sequentially allocate external requests to real servers in the cluster in a sequential manner, treating each server equally, regardless of the actual number of connections and system load on the server.
WRR: The weighted round call scheduling algorithm is based on the weights of the high and low and round-robin allocation requests to each server. A server that has a high weight value receives a connection that has a higher weight than a server that has a lower weight value and handles more connections than a server with the same number of weights.
DH: The target address hash scheduling algorithm first based on the destination IP address of the request, as hash keys (hash key) from the static distribution of the hash list to find the corresponding server, if the server is available and not overloaded, send the request to the server, otherwise return null, mainly for the cache server.
sh: Source address Hash Scheduling algorithm is exactly the same as the target address hash scheduling algorithm, it is based on the requested source IP address, as a hash key (hash key) from the static distribution of the hash list to find the corresponding server, if the server is available and not overloaded, send the request to the server, Otherwise, NULL is returned. Used primarily for session binding.
Dynamic Scheduling Method:
LC: Minimum link, referred to as LC. The schedule is to assign a new connection request to the server with the smallest number of current connections. Minimum connection scheduling is a dynamic scheduling algorithm that estimates the server's load by the number of connections currently active on the server. Calculates the current Realserver load condition calculation method: Active*256+inactive.
sed : Shortest expected delay, referred to as SED. Assign a incoming request with the shortest expected latency mode to the server. Calculates the current Realserver load Condition calculation method: (active+1) *256/weight.
LBLC: "Least-Link based on locality" scheduling algorithm is a load balancing target IP address, which is mainly used in cache cluster system. According to the target IP address of the request, the algorithm finds the most recently used server, if the server is available and not overloaded, sends the request to the server, if the server does not exist, or if the server is overloaded and has half of the workload of the server, the principle of "least link" is used to select an available server. , the request is sent to the server.
LBLCR: "Local least-link with replication" Scheduling algorithm is also targeted at the target IP address load balancing, is mainly used in the cache cluster system. It differs from the LBLC algorithm in that it maintains a mapping from a destination IP address to a set of servers, while the LBLC algorithm maintains a mapping from a destination IP address to a server. According to the target IP address of the request, the algorithm finds the corresponding server group of the target IP address, selects a server from the server group according to the principle of "minimum connection", if the server is not overloaded, sends the request to the server, and if the server is overloaded, select a server from this cluster according to the "minimum connection" principle. Join the server to the server group and send the request to the server. Also, when the server group has not been modified for some time, the busiest server is removed from the server group to reduce the degree of replication.
Note: active: A connection that represents an established connection and data transfer is in progress. Inactive: An inactive connection that represents an established connection but does not transmit data.
Resources:
Description of LVS principle: http://atong.blog.51cto.com/2393905/1348602
LVS working mode and principle: http://blog.csdn.net/caoshuming_500/article/details/8291940
LVS working mode and scheduling algorithm introduction: http://www.xmydlinux.org/201102/331.html
Detailed description of LVS type and its scheduling method