I. The concept of LVS
- LVS (Linux Vsan): Linux virtual server;
- LVS is a load balancing device. It does not provide whatever service. When the user requests to be here. It is the service that forwards the customer's needs to the backend to truly deliver the service. So, the backend service is called real server;
- LVS is divided into two sections, the previous section called IPVSADM (Command-line tool for managing the Cluster service), and the latter section is called Ipvs (kernel module);
- "Hint" LVS and iptables can not be used at the same time;
Ii. type of LVS
- LB (Load Balancing): Load Balancer Cluster
Features: In order to add capability capability
- HA (High Availability): Highly available cluster
Features: Availability of services available (up to 99.999% online a year)
Calculation method: Online Time/(online time/fault processing time)
- HP ([Hpc]high performance): High-performance cluster
Features: Performance of service delivery
Three, LVS composition structure (load Balancing implementation scheme)
- Method of DNS domain name rotation analysis
- A method based on client scheduling access
- Scheduling method based on application-layer system load
- A scheduling method based on IP address
In the IP-based load scheduling algorithm. IP load Balancing technology is the most efficient
Four, LVS 10 scheduling algorithm
1. Static Dispatch:
①rr (Round Robin): Polling schedule, call scheduling
The principle of the polling scheduling algorithm is that each time a request from a user is assigned to an internal server in turn, starting from 1. Until n (number of internal servers). And then start the cycle again.
The advantage of the algorithm is its simplicity, which does not need to record the state of all current connections, so it is a stateless dispatch.
"Tip: This is not considered the processing power of each server"
②wrr:weight, weighted (the proportion between weights is now scheduled between the hosts)
Because of the configuration of each server, the business application installed, and so on, its processing power will be different. So. We are based on the different processing capabilities of the server. Assign a different weight to each server so that it can accept service requests for the corresponding number of weights.
③sh:source hashing, source address hash
The main implementation of session binding, the previously established session information can be preserved
The source address hash scheduling algorithm is exactly the same as the target address hash scheduling algorithm, which is based on the requested source IP address, as the hash key (hash key) from the static distribution of the hash list to find the appropriate server. If the server is available and is not overloaded, send the request to the server, otherwise the return is empty.
It uses the same hash function as the target address hash scheduling algorithm. Its algorithm flow and the target address hash scheduling algorithm basically similar, in addition to the request of the destination IP address for the requested source IP address, so here is not a narrative.
④dh:destination hashing: Destination Address hash
Send a request for the same IP address to the same server.
The target address hash scheduling algorithm is also a load balancer for the destination IP address, which is a static mapping algorithm that maps a destination IP address to a server through a hash (hash) function.
The target address hash scheduling algorithm is first based on the destination IP address of the request. Locate the appropriate server from a statically allocated hash table as a hash key (hash key), and if the server is available and not overloaded, send the request to the server, otherwise return NULL.
2. Dynamic scheduling
①LC (least-connection): Minimum connection
The least connection scheduling algorithm is to allocate a new connection request to the server with the least number of current connections, and the minimum connection schedule is a dynamic scheduling short algorithm that anticipates server load balancing through the number of connections currently active by the server, which the scheduler needs to record the number of connections that each server has established. When a request is dispatched to a server, its number of connections increases by 1, and when the connection is aborted or timed out, its number of connections is reduced by one. When the system is implemented. We also introduce a value of 0 o'clock when the server is weighted. Indicates that the server is not available and is not scheduled.
Simple algorithm: Active*256+inactive (who's small. Pick who)
②WLC (Weighted least-connection scheduling): Weighted minimum connection
The weighted minimum connection scheduling algorithm is a superset of minimum connection scheduling. Each server uses corresponding weights to represent its processing performance. The default value for server is 1, and the system administrator can dynamically set permissions on the server, and the weighted minimum connection schedule is proportional to the number of established connections and their weights as much as possible when scheduling a new connection.
Simple algorithm: (active*256+inactive)/weight "(Number of active connections +1)/Divided by weight" (who's small, pick who)
③sed (Shortest expected delay): Shortest expected delay
Based on the WLC algorithm
Simple algorithm: (active+1) *256/weight "(Number of active connections +1) *256/divided by weight"
④nq (never queue): Never queue (improved SED)
Without a queue, if there is a realserver number of connections = 0 directly allocated the past, there is no need for SED operations.
⑤LBLC (locality-based Least Connection): Minimal connection based on locality
The least-connection algorithm based on locality is the load-balancing dispatch for the target IP address of the request message, and the non-sign is mainly used for the cache cluster system, because the cloth marked IP address of the customer request message in the cache cluster is changed. Here, if whatever the backend server can handle, whatever the request is. The design objective of the algorithm is to dispatch the request of the same target IP address to the same server in the case of the load balance of the server, so as to improve the access local and main memory cache hit rate of the server, so as to adjust the processing ability of the whole cluster system.
The least-connection scheduling algorithm based on locality finds out the recently used realserver of the target IP address according to the target IP address of the request. If the real server is available and is not overloaded. Send the request to the server, or, if the server does not exist, or if the server is overloaded and has half the workload of the server, select an available server with the principle of "least link". Sends the request to the server.
⑥LBLCR (locality-based Least Connections withreplication): least locality-based link with replication
Local least-Link scheduling algorithm with replication is also for the target IP address load balancing, the algorithm according to the destination IP address of the target IP address to find the corresponding server group, according to the "minimum connection" principle from the server group to select a server, if the server is not overloaded. Sends the request to the server. If the server is overloaded. Select a server from this cluster by the "minimum connection" principle and join the server to the server group. Sends the request to the server. At the same time, the server group has not been altered for some time. Remove the busiest server from the server group. To reduce the amount of replication.
Five, Ipvs to achieve load balancing method
NAT: Address translation (similar to Dnat)
1, cluster point and director must work in the same IP network
2, RIP is generally a private address. For communication between cluster nodes only
3. Director is between client and real server. and is responsible for handling all incoming and outgoing channels.
4. Realserver must run the gateway with dip
5. Director supports port mapping
6, Realserver can use whatever type of operating system (OS)
7, in the larger-scale application scenario, director easily become a system bottleneck
DR: Direct routing (and used as source address)
1, each cluster node and director must be in the same physical network;
2, RIP can use the public network address, to achieve portable remote management and monitoring.
3, the Director is only responsible for processing inbound requests, will act messages are realserver directly to the client
4, Realserver can not point the gateway to dip, but direct point to the front-end gateway;
5. Director does not support port mapping
6. Most operating systems can be used in Realserver
TUN: Tunnel
1. Cluster nodes can cross the Internet
2, RIP must be a public network address
3, the Director is only responsible for processing inbound requests, will act messages are realserver directly to the client
4. Realserver Gateway cannot point to Director
5. Only the OS talent with the tunnel function is used for realserver
6. Port mappings are not supported
Vi. Ipvsadm frequent use of commands
1. Manage Cluster service
加入:-A -t|u|f service-address [-sscheduler] -t:tcp 协议的集群服务 -u:udp 协议的集群 -f:FWM 防火墙标记改动:-E删除:-D -D -t|u|f service-address
Like what:# ipvsadm -A -t 172.16.100.1:80 -s rr
2. Manage the RS in the Cluster service
Join:-a -t|u|f service-address -rserver-address [-g|i|m] *[-w weight]*
-t|u|f service-address: A pre-defined Cluster service
-R Server-address:rs address, in the NAT model, the ability to use port mappings
[-g | i | m] LVS type
-g:dr
-i:tun
-m:nat
[-W weight] defines server weights
3. Changes: -e
4. Delete:-d -t|u|f service-address -r server-address
example: #ipvsadm -a -t 172.16 .100 .1 : 80 -r 192.168 .10 Span class= "Hljs-number" >.8 -m for example: #ipvsadm -a -t 172.16 .100 .1 : 80 -r 192.168 .10 .9 -m
5. View
-L|l[options]-n:数字格式显示主机地址和port号--stats:统计信息--rate:速率--timeout:显示tcp、tcpfin和udp会话的超时时间值--daemon--sort:跟协议、地址、port进行排序,默觉得升序-c:显示当前ipvs连接状况
6. Remove all cluster Services:
-C:清空ipvs规则
7. Save the Rules
-S:(用输出重定向进行保存)格式:`#ipvsadm -s >/path/to/somefile`
8. Load the previous rule:
-R格式:`#ipvsadm -R </path/to/somefile`
View Original
Original works, agreed to reprint, please be sure to use hyperlinks in the form of the original source of the article and the author's information and this statement. Otherwise, the legal liability will be investigated.
Top Picks
LNMP Environment Construction--nginx Chapter
Configuring the local Yum source in RHEL6.5
Installation and use of Zabbix under Ubuntu
MySQL Dual master hot standby problem processing
10 scheduling algorithms and load balancing theory of LVS cluster