[Linux33-1] LVS Basics

1. Introduction to LVS


LVS Chinese site : http://zh.linuxvirtualserver.org/

LVS official website : http://www.linuxvirtualserver.org/


The full English name of LVS is Linux Virtual Server , that is, Linux Virtual Server. It is an open source project of Dr. Zhang Wensong in our country. In linux memory 2.6, it has become a part of the kernel, the kernel version before this needs to recompile the kernel


2. LVS functions and features


LVS is mainly used for load balancing of multiple servers.

  1. Working at the network layer, high-performance and highly available server cluster technology can be realized.
  2. Inexpensive, many low-performance servers can be combined to form a super server.
  3. Easy to use, very simple to configure, and there are multiple load balancing methods.
  4. Stable and reliable, even if one of the servers in the cluster fails to work normally, it does not affect the overall effect.
  5. Scalability is also very good

Three, LVS system architecture


Insert picture description here

<1> Load Balancer: Load balancing layer : This is the core part of LVS, which is like the Controller of our website's MVC model. It is responsible for distributing the client's request to different servers in the next layer for processing according to a certain algorithm, and does not deal with specific business itself. In addition, this layer can also be used to monitor the status of the next layer. If a server on the next layer fails to work normally, it will automatically remove it and add it again after recovery. This layer consists of one or several Director Servers.

<2> Server Array: Server group layer : This layer is responsible for specific services. It can be composed of WEB Server, mail Server, FTP Server, DNS Server, etc. Note that, in fact, the upper Director Server can also be used as a Real server.

<3> Shared Storage: Data sharing storage layer : It is mainly to improve the data of the upper layer and keep the data consistent for the upper layer.


Four, working principle


Insert picture description here

  1. When the user initiates a request to the load balancing scheduler (Director Server), the scheduler sends the request to the kernel space
  2. The PREROUTING chain will first receive the user request, determine that the target IP is the local IP, and send the data packet to the INPUT chain
  3. IPVS works on the INPUT chain. When a user request arrives at INPUT, IPVS will compare the user request with the cluster service that it has defined. If the user request is the defined cluster service, then IPVS will forcibly modify it. The destination IP address and port in the data packet, and send the new data packet to the POTROUTING chain
  4. After the POSTROUTING chain receives the data packet, it finds that the target IP address happens to be its own back-end server, then the data packet is finally sent to the back-end server through routing selection.

Five, professional terms


  1. DS : Director Server. Refers to the front-end load balancing server
  2. RS : Real Server. Back-end real server
  3. VIP : request from the outside directly to the user, as the IP address of the target of the user request
  4. DIP : Director Server IP, the IP address mainly used to communicate with internal hosts
  5. RIP : Real Server IP, the IP address of the back-end server
  6. CIP : Client IP, visit the IP address of the client

Six, LVS three load balancing modes


Comparison of the advantages and disadvantages of the three load balancing technologies:


VS/NAT VS / TUN VS/DR
Server operating system Arbitrary Support tunnel Majority (Support Non-arp)
Server network Private network LAN/WAN local area network
Number of servers (100M network) 10-20 100 More (100)
Server gateway Load balancer Own routing Own routing
effectiveness general high highest

6.1 VS/NAT


Insert picture description here

Virtual Server via Network Address Translation

Network address flipping technology realizes virtual server . When the request comes, the program processed on the Diretor server changes the target address (ie virtual IP address) in the data message to a specific Real Server, and the port is also changed to the port of the Real Server, and then sends the message to Real Server. After the Real Server processes the data, it needs to return to the Diretor Server, and then the Diretor server changes the source address and source port in the data packet to the VIP address and port, and finally sends the data out. It can be seen that the user's request and return must go through the Diretor Server. If there is too much data, the Diretor Server will definitely be overwhelmed.

6.2 VS / TUN


Insert picture description here

Virtual Server via IP Tunneling

IP tunnel technology realizes virtual server . It is basically the same as VS/NAT, but the Real server directly returns data to the client without going through the Diretor server, which greatly reduces the pressure on the Diretor server.

6.3 VS/DR


Insert picture description here

Virtual Server via Direct Routing

Direct routing technology realizes virtual server . Unlike the previous two methods, its message forwarding method is different. VS/DR sends the request to Real Server by changing the MAC address of the request message, and Real Server returns the response directly to the client, eliminating the need for VS/DR. IP tunnel overhead in TUN. This method is the highest performance among the three load scheduling mechanisms, but it must be required that the Director Server and Real Server have a network card connected to the same physical network segment.

Seven or ten scheduling algorithms


7.1 Static scheduling


RR (Round Robin): round robin scheduling

The principle of the round-robin scheduling algorithm is to allocate requests from users to internal servers in turn every time, starting from 1 until N (the number of internal servers), and then restarting the cycle. The advantage of the algorithm is its simplicity. It does not need to record the current state of all connections, so it is a stateless scheduling. (Hint: The processing capacity of each server is not considered here)

WRR (weight Round Robin): Weighted round-robin (scheduling between hosts based on the ratio between weights)

Due to the different configurations and installed business applications of each server, its processing capabilities will be different. Therefore, we assign different weights to each server according to the different processing capabilities of the server, so that it can accept service requests with corresponding weights.

SH (source hashing): source address hashing .

It mainly realizes session binding, which can retain the previously established session information. The source address hash scheduling algorithm is just the opposite of the target address hash scheduling algorithm. It is statically allocated according to the source IP address of the request as a hash key (Hash Key) Find the corresponding server in the hash table. If the server is available and not overloaded, send the request to the server, otherwise it returns empty. The hash function it uses is the same as that of the target address hash scheduling algorithm. Its algorithm flow is basically similar to that of the target address hash scheduling algorithm, except that the requested target IP address is replaced with the requested source IP address, so I will not describe one by one here.

DH (Destination hashing): destination address hashing

Send requests for the same IP address to the same server. The target address hash scheduling algorithm is also aimed at load balancing of target IP addresses. It is a static mapping algorithm that maps a target IP address to a server through a hash function. The target address hash scheduling algorithm first uses the requested target IP address as a hash key to find the corresponding server from the statically allocated hash table. If the server is available and not overloaded, the request is sent to the server , Otherwise it returns empty.

7.2 Dynamic scheduling


LC (Least-Connection): Least connection

The least connection scheduling algorithm is to allocate new connection requests to the server with the smallest number of current connections. The least connection scheduling is a short dynamic scheduling algorithm. It estimates the load balance of the server through the number of connections currently active on the server. The scheduler needs to record The number of connections established by each server. When a request is dispatched to a server, the number of connections is increased by 1, and when the connection is aborted or timed out, the number of connections is reduced by one. When the system is implemented, we also introduce the weight of the server When 0, it means that the server is unavailable and not scheduled.
Simple algorithm: active256+inactive (who is small, who is the pick)

the WLC (Weighted Least-Connection Scheduling): weighted least connections

The weighted least connection scheduling algorithm is a superset of the least connection scheduling, and each server uses the corresponding weight to indicate its processing performance. The default weight of the server is 1. The system administrator can dynamically set the server's authority. The weighted least connection scheduling makes the server's established connections as much as possible when scheduling new connections in proportion to its weight.
Simple algorithm: (active256+inactive)/weight[(number of active connections+1)/divided by weight](who is small, who is the pick)

SED (Shortest Expected Delay): the shortest expected delay (based on wlc algorithm)

Simple algorithm: (active+1)*256/weight [(active connections+1)*256/divided by weight]

NQ (never queue): never queue (improved sed)

No queue is required. If there is a realserver with a connection number=0, it will be allocated directly, and no sed operation is required.

LBLC (Locality-Based Least Connection): Least connection based on locality

The least connection algorithm based on locality is the load balancing scheduling for the target IP address of the request message. The non-signature is mainly used for the Cache cluster system, because the label IP address of the client request message in the Cache cluster is changed. The back-end server can handle any request. The design goal of the algorithm is to schedule requests with the same target IP address to the same server when the server load is basically balanced, so as to improve the locality of access and main memory of the individual server. Cache hit rate, thereby adjusting the processing capacity of the entire cluster system.

The least connection scheduling algorithm based on locality finds out the RealServer recently used by the target IP address based on the requested target IP address. If the Real Server is available and not overloaded, the request is sent to the server; if the server does not exist, or the If the server is overloaded and one server is at half of the workload, an available server is selected using the principle of "least link" and the request is sent to that server.

LBLCR (Locality-Based Least Connections with Replication ): The least link based on locality with replication

The locality-based least link scheduling algorithm with replication is also aimed at the load balancing of the target IP address. The algorithm finds the server group corresponding to the target IP address according to the requested target IP address, and selects the server group according to the principle of "least connection" A server, if the server is not overloaded, send the request to the server; if the server is overloaded, select a server from the cluster according to the principle of "least connection", 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, the busiest server is deleted from the server group to reduce the degree of replication.


Guess you like

Origin blog.csdn.net/weixin_46069582/article/details/112389854
LVS
LVS
lvs
LVS
LVS