One, LVS three kinds of packet forwarding method
LVS provides three packet forwarding methods: NAT (Network address mapping), IP tunneling (IP tunneling), direct Routing (straight route)
Different forwarding mode determines the network structure of different cluster, and the following three kinds of forwarding methods are respectively started:
1. NAT (Network address mapping):
The NAT mode can support any operating system, as well as private networks, and requires only one Internet IP address, but the performance of the entire system is limited. Because you need to rewrite the package every time you execute NAT
There is a certain delay; In addition, most applications have 80% of the data flow from the server to the client, that is, the user's request is very short, and the server response is very large, the load Balancer to form a great pressure, become a new bottleneck.
2, IP tunneling (IP tunnel):
The Director assigns the request to a different real server. Real server responds directly to the user after processing the request so that the director Load Balancer handles only half of the client's connection to the server
IP tunneling technology greatly improves the director's scheduling ability, but also greatly improves the maximum number of nodes the system can hold, can be more than 100 nodes
Real server can run on any LAN or WAN, which means allowing geographic distribution, which is important in disaster recovery. The server must have an official IP address to communicate directly with the client
And all servers must support the IP tunneling protocol.
3. Direct Routing (directly routed):
Similar to IP tunneling, the load balancer handles only half of the connections, avoids new performance bottlenecks, and increases the scalability of the system. Direct routing compared to IP tunneling
There is no overhead for IP encapsulation, but due to the physical layer (modify MAC address) technology, all servers must be in one physical network segment.
II. Eight scheduling algorithms for LVS:
* RR round call (Round Robin)
The scheduler uses the "round-robin" scheduling algorithm to sequentially allocate external requests to real servers in the cluster, and treats each server equally, regardless of the actual number of connections and system load on the server.
* WRR weighted round call (Weighted Round Robin)
The scheduler uses the "Weighted round call" scheduling algorithm to schedule access requests based on the different processing capabilities of the real server. This ensures that the processing capacity of the server handles more access traffic. The scheduler can automatically inquire about the load of the real server and adjust its weights dynamically.
* LC Minimum Link (Least Connections)
The scheduler dynamically dispatches network requests to the server with the fewest number of links established through the "least connection" scheduling algorithm. If the real server of the cluster system has similar system performance, the "Minimum connection" scheduling algorithm can be used to balance the load well.
* WLC Weighted least link (Weighted Least Connections)
In the case of the server performance difference in the cluster system, the scheduler uses the "Weighted least link" scheduling algorithm to optimize the load balancing performance, and the server with higher weights will bear a large proportion of active connection load. The scheduler can automatically inquire about the load of the real server and adjust its weights dynamically.
* LBLC minimum link based on locality (locality-based Least Connections)
The "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 with replication based least locality link (locality-based Least Connections with Replication)
The "least local link with replication" Scheduling algorithm is also a load balancer for the target IP address, which 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, 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.
* DH Target Address hash (Destination Hashing)
The "Target address hash" scheduling algorithm finds the corresponding server from a statically allocated hash list, based on the requested destination IP address, as a hash key (hash key), if the server is available and not overloaded, sends the request to the server, otherwise returns NULL.
* SH Source address hash (source Hashing)
The "Source address hash" scheduling algorithm, based on the requested source IP address, as the 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 return empty.
Note: If you would like to know more about the technical details of the above, LVS homepage query. The LVS homepage is:
http://www.LinuxVirtualServer.org/
http://www.linux-vs.org/
Third, the installation of IPVSADM services
1, the official website to download the installation package: http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
IPVSADM Installation:
# tar zxvf ipvsadm-1.24.tar.gz-c/usr/src/
# cd/usr/src/ipvsadm-1.24
# make All
# make Install
# Ipvsadm--version
2. Yum installation (simple and convenient)
#yum-y Install Ipvsadm
Iv. Configuration of Ipvsadm Services
Note: The following steps are configured according to three kinds of package forwarding method of LVS
The experimental environment is as follows:
Lvsserver 192.168.1.49 (eht0) vip:192.168.1.40 8.8.8.8 (NAT mode)
ServerA 192.168.1.46 (eth0)
ServerB 192.168.1.47 (eth0)
1. Configuration of each server in Vs/nat mode
The Lvsserver configuration is as follows:
Ifconfig eht0 192.168.1.49 Netmsk 255.255.255.0
Ifconfig eht1 8.8.8.8 netmask 255.255.255.0
(Note: Because NAT mode requires two real network card, so add a network card, the IP address of this network card is also the address of the VIP)
VI ipvsadm.sh (Create script file)
--------------------------------------------------------------------------------------------------------------- ----------------------------------------------
#! /bin/bash
echo 1 >/porc/sys/net/ipv4/ip_forward (Turn on routing)
Ipvsadm-c (clears the previous conversion table)
Ipvsadm-at 8.8.8.8:80-s RR (Specifies the server with the scheduling algorithm transformation)
Ipvsadm-at 8.8.8.8:80-r 192.168.1.46:80-m (add a real server,-M is Nat mode,-G is the direct route (DR) mode,-I is Tun mode)
Ipvaadm-at 8.8.8.8:80-r 192.168.1.47:80-m
#chmod u+x ipvsadm.sh (add executable permission)
--------------------------------------------------------------------------------------------------------------- ---------------------------------------------------
The ServerA configuration is as follows:
Ifconfig eth0 192.168.1.46 netmask 255.255.255.0
Route add default GW 192.168.1.49
(Note: This gateway is the IP address of the lvsserver eth0)
Service httpd Start (Open Test Web Service)
echo ' 192.168.1.46 ' >/var/www/html/index.html (HTML page for test making)
--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------
The ServerB configuration is as follows:
Ifconfig eth0 192.168.1.47 netmask 255.255.255.0
Route add default GW 192.168.1.49
(Note: This gateway is the IP address of the lvsserver eth0)
Service httpd Start (open a test Web server
echo ' 192.168.1.47 ' >/var/www/html/index.html (HTML page for test making)
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------
2. Configuration of each server in Vs/tun mode
The Lvsserver configuration is as follows:
Ifconfig eht0 192.168.1.49 Netmsk 255.255.255.0
(Note: Only one physical NIC is required in Tun mode to disable the eth1 NIC)
Ifconfig tunl0 192.168.1.40 netmask 255.255.255.255 up
(Note: The address of the Tunlo interface configuration is the VIP address)
Route add-host 192.168.1.40 Dev Tunlo
VI ipvsadm.sh (Create script file)
--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------
#! /bin/bash
Ipvsadm-c (clears the previous conversion table)
Ipvsadm-at 192.168.1.40:80-s RR (Specifies the server with the scheduling algorithm transformation)
Ipvsadm-at 192.168.1.40:80-r 192.168.1.46:80-i (add a real server,-M is Nat mode,-G is the direct route (DR) mode,-I is Tun mode)
Ipvaadm-at 192.168.1.40:80-r 192.168.1.47:80-i
#chmod u+x ipvsadm.sh (add executable permission)
#./ipvsadm.sh
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------
The ServerA configuration is as follows:
Ifconfig eth0 192.168.1.46 netmask 255.255.255.0
Ifconfig tunl0 192.168.1.40 netmask 255.255.255.255 up
Route add-host 192.168.1.40 Dev Tunlo
VI arp.sh (Create script file)
#!/bin/bash
echo "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------
ServerB Configuration Same as Severa
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------
3. Configuration of each server in VS/DR mode
The Lvsserver configuration is as follows:
Ifconfig eht0 192.168.1.49 Netmsk 255.255.255.0
(Note: Only one physical NIC is required in DR Mode to disable the eth1 NIC)
Ifconfig eth0:0 192.168.1.40 netmask 255.255.255.255 up
(Note: The address of the Eth0:0 interface configuration is the VIP address)
Route add-host 192.168.1.40 Dev eth0:0
VI ipvsadm.sh (Create script file)
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------
#! /bin/bash
echo 1 >/porc/sys/net/ipv4/ip_forward (Turn on routing)
Ipvsadm-c (clears the previous conversion table)
Ipvsadm-at 192.168.1.40:80-s RR (Specifies the server with the scheduling algorithm transformation)
Ipvsadm-at 192.168.1.40:80-r 192.168.1.46:80-g (add a real server,-M is Nat mode,-G is the direct route (DR) mode,-I is Tun mode)
Ipvaadm-at 192.168.1.40:80-r 192.168.1.47:80-g
#chmod u+x ipvsadm.sh (add executable permission)
./ipvsadm.sh
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------
The ServerA configuration is as follows:
Ifconfig eth0 192.168.1.46 netmask 255.255.255.0
Ifconfig lo:0 192.168.1.40 netmask 255.255.255.255 up (add VIP address on Lo Interface)
Route add-host 192.168.1.40 Dev lo:0 (Increase the route to the loopback interface)
VI arp.sh (Create script file)
#!/bin/bash
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
#chmod u+x arp.sh (add executable permission)
#./arp.sh
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------
ServerB configuration is the same as ServerA
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------
Test: 1, show LVs Current connection
such as: Ipvsadm-l-C ipvsadm-l--stats
2. Enable 46 and 47 Web services. Directly enter the address of the VIP constantly refresh you will see different pages of the switch
Linux Load balancer (LVS installation and configuration) "Go"