LVS three kinds of packet forwarding method LVS provides three kinds of packet forwarding: NAT (network address mapping), IP tunneling (IP tunnel), direct Routing (directly routed) different forwarding modes determine the different cluster network structure, the following three ways to forward Starting from: 1, NAT (Network address mapping): NAT mode can support any operating system, as well as private networks, and only one Internet IP address, but the performance of the entire system is limited. Because there is a delay in executing the NAT each time the package needs to be rewritten, in addition, most applications have 80% of the data 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 tunneling): Director assigns a 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-server connection IP tunneling technology greatly improves the director's dispatch processing capability, and greatly increases 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: 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 does not have the overhead of IP encapsulation compared to IP tunneling, but due to the physical layer (modify MAC address) technology, all servers must be in one physical network segment. Eight scheduling algorithms for LVS: * RR round call (Round Robin) Scheduler uses the "round call" scheduling algorithm to distribute external requests sequentially 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 wheel call (Weighted Round Robin) Scheduler dispatches access requests by the "weighted round call" scheduling algorithm 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 The Least-link (Least Connections) scheduler dynamically dispatches network requests to servers 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, 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 load balanced against the target IP address, and is mainly used in the 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 local least-link (locality-based Least Connections with Replication) "Local least-link with replication" Scheduling algorithm is also for the target IP address load balancing, is mainly used for 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) "Destination address hash" Scheduling algorithm according to the requested destination 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 theServer, otherwise the return is empty. * The SH Source address hash (source Hashing) "Origin address hash" scheduling algorithm based on the requested source IP address, as a hash key (hash keys) 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. Configure the IPVSADM service Note: The following steps are configured according to the three package forwarding methods of LVs 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, Vs/nat mode for each server The configuration 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/bashecho 1 >/proc/sys/net/ipv4/ip_forward # (Turn on routing) IPVSADM-C # (Clear previous conversion table) Ipvsadm-at 8.8.8.8:80-s RR # ( Specify 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) Ipvsadm-at 8.8.8.8:80-r 192.168.1.47:80-m#chmod u+x ipvsadm.sh (add executable permission)----------------------------------------------------------------------------------------- -------------------------------------------------------------------------ServerA is configured as follows: Ifconfig eth0 192.168.1.46 netmask 255.255.255.0route Add default GW 192.168.1.49 (Note: This gateway is the IP address of lvsserver eth0) service httpd start (Open Test Web service) echo ' 192.168.1.46 ' >/var/www/html/index.html (HTML page for making tests)------------------------------------------------------ -------------------------------------------------------------------------------------------------------------ServerB are configured as follows: Ifconfig eth0 192.168.1.47 netmask 255.255.255.0route Add default GW 192.168.1.49 (Note: This gateway is Lvsserver's eth0 IP address) service httpd Start (open test Web server echo ' 192.168.1.47 ' >/var/www/html/index.html (HTML page for testing)-------------------------- --------------------------------------------------------------------------------------------------------------- ---------------------------2, Vs/tun mode configuration of each server Lvsserver configuration is as follows: ifconfIG Eht0 192.168.1.49 Netmsk 255.255.255.0 (Note: Only one physical network card is required in Tun mode, the ETH1 network card can be disabled) ifconfig tunl0 192.168.1.40 netmask 255.255.255.255 Up (note: Tunlo interface is configured with a VIP address) route add-host 192.168.1.40 Dev Tunlo vi ipvsadm.sh (Create script file)------------- --------------------------------------------------------------------------------------------------------------- --------------------------------------- #! /BIN/BASHIPVSADM-C # (clears the previous conversion table) Ipvsadm-at 192.168.1.40:80-s RR # (specifies the server with the scheduling algorithm conversion) Ipvsadm-at 192.168.1.40:80-r 19 2.168.1.46:80-i # (add a real server,-M is Nat mode,-G is the direct route (DR) mode,-I is Tun mode) Ipvsadm-at 192.168.1.40:80-r 192.168.1.47:80-i#chmod u +x ipvsadm.sh (add executable permission) #./ Ipvsadm.sh--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------ServerA is configured as follows: Ifconfig eth0 192.168.1.46 netmask 2 55.255.255.0ifconfig tunl0 192.168.1.40 netmask 255.255.255.255 up Route add-host 192.168.1. Max Dev Tunlo vi arp.sh (Create script file) #!/bin/bashecho "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignoreecho "2" >/pro C/sys/net/ipv4/conf/tunl0/arp_announceecho "1" >/proc/sys/net/ipv4/conf/all/arp_ignoreecho "2" >/proc/sys/ Net/ipv4/conf/all/arp_ Announce----------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ServerB configuration is the same as Severa------------------------------------------------- --------------------------------------------------------------------------------------------------------------- -------3, the configuration of each server in VS/DR mode lvsserver configuration is as follows: Ifconfig eht0 192.168.1.49 Netmsk 255.255.255.0 (Note: Only one physical network card is required in Dr Mode, the ETH1 network card can be disabled) Ifconfig eth0:0 192.168.1.40 netmask 255.255.255.255 Up (note: eth0:0 interface is configured with a VIP address) route add-host 192.168.1.40 Dev Eth0:0vi ipvsadm.sh (gen Build script file)------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------#! /bin/bashecho 1 >/proc/sys/net/ipv4/ip_forward # (Turn on routing) IPVSADM-C # (Clear previous conversion table) Ipvsadm-at 192.168.1.40:80-s RR # (Specify server with scheduling algorithm conversion) 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) ipvsadm-at 192.168.1.40:80-r 192.168.1.47:80-g#chmod u+x ipvsadm.sh (increased executable permissions). Ipvsadm.sh--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------ServerA is configured as follows: Ifconfig eth0 192.168.1.46 netmask 255.255.255.0ifconfig 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 (Add route to loopback interface) VI arp.sh (Create script file) #!/bin/bashecho "1" >/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "2" >/proc/sys/ne T/ipv4/conf/lo/arp_announceecho "1" >/proc/sys/net/ipv4/conf/all/arp_ignoreecho "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, display LVS current connection such as: Ipvsadm-l-C ipvsadm-l--stats 2, 46 and 47 of the Web services are enabled. Enter the address of the VIP continuously refresh you will see different pages of the switch ipvsadm service configuration ipvsadm configuration #cat >/etc/sysconfig/ipvsadm input content is as follows: Ipvsadm-a-T 172.16.4.200:80 -S rripvsadm-a-T 172.16.4.200:80-r 172.16.4.188:80-mipvsadm-a-T 172.16.4.200:80-r 172.16.4.198:80-m Note: Service IPV Sadm Start Service will read the contents of the/etc/sysconfig/ipvsadm, and line-by-row execution, the use of VI editing/ETC/SYSCONFIG/IPVSADM will occur when the character encoding problem can not be performed, it is recommended to use cat editing. 172.16.4.200 are virtual IP addresses, 172.16.4.188 and 172.16.4.198 are real IP addresses. Save exit, test: #ipvsadm-restore </etc/sysconfig/ipvsadm#ipvsadm-l parameter description: Arp_announce0 can send out all IP free ARP1 on any interface Try to avoid sending free ARP2 of IP outside the interface onlyThe free ARPARP_IGNORE0 that sends outgoing IP on the interface can respond to all configured IP ARP messages 1 only respond to ARP messages from the incoming interface IP 8 does not respond to any ARP requests
Configuring the Ipvsadm Service