I. Introduction of LVS Cluster
LVS cluster uses IP load balancing technology and content-based request distribution technology, because all operations are done in the Linux operating system core space, its scheduling overhead is very small , so The Scheduler has a good throughput rate, transfers the request evenly to the different server execution, and the scheduler automatically shields off the server's failure, thereby forming a set of servers into a high-performance, highly available virtual server. The structure of the entire server cluster is transparent to the customer, and there is no need to modify the client and server-side programs, the implementation pattern is mainly : Vs/nat mode, Vs/tun mode (IP tunneling mode), VS/DR mode (direct routing mode).
Two, LVS load balance mode
1, Lvs-nat
The Lvs-nat mode applies the NAT feature, maps an internal set of servers to a virtual IP, and then serves as a virtual service node. Because both client requests and responses must pass through the Director Server, the director is easily a bottleneck for the cluster, which also makes the Lvs-nat mode support fewer clusters.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/56/wKioL1b87yCjL1CwAACR93bZR_U429.png "title=" _d ( Y78ZYHSO0M40) 9 '%4c{3.png "alt=" Wkiol1b87ycjl1cwaacr93bzr_u429.png "/>
Lvs-nat topology diagram
Configure the network environment and install the Web service on the real server, and do the following on the directory server:
]# echo "1" >/proc/sys/net/ipv4/ip_forward #打开路由转发功能
]# ipvsadm-a-T 192.168.1.106:80-s RR
]# ipvsadm-a-T 192.168.1.106:80-r 192.168.10.3:80-m
]# ipvsadm-a-T 192.168.1.106:80-r 192.168.10.2:80-m
2, LVS-DR
Working principle:director According to different scheduling algorithm, select a real server, do not modify or encapsulate the IP message, but instead of the MAC address of the data frame to select the MAC address of the server, and then the modified data frame in the server group with the local area network sent. Because the MAC address of the data frame is the selected server, the server is sure to receive the data frame from which the IP message can be obtained. When the server discovers that the destination address of the message is on the local network device, the server processes the message and then returns the response message directly to the client based on the routing table.
In LVS-DR mode, real server and director must be on the same physical network.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7E/63/wKioL1b-F9DA1gzrAACmVtYoBXc997.png "title=" D{o7 " L8vvt92zs ' Vauu ' 9oo.png "alt=" Wkiol1b-f9da1gzraacmvtyobxc997.png "/>
Lvs-dr mode topology diagram
Configured on Director server:
~]# ifconfig eth2:0 192.168.145.200 netmask 255.255.255.255
~]# Route add-host 192.168.145.200 Dev eth2:0
~]# ipvsadm-at 192.168.145.200:80-s RR
~]# ipvsadm-at 192.168.145.200:80-r 192.168.145.203:80-g
~]# ipvsadm-at 192.168.145.200:80-r 192.168.145.205:80-g
Because the VIP is set on Real server, the ARP broadcast function needs to be turned off and configured into the following:
~]# ifconfig lo:0 192.168.145.200 netmask 255.255.255.255
~]# Route add-host 192.168.145.200 Dev lo:0
~]# 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
3, Lvs-tun
When using NAT technology, because the request and response packets must be rewritten by the dispatcher address, the processing power of the scheduler becomes a bottleneck when the customer requests are more and more. To solve this problem, the dispatcher forwards the request message through the IP tunnel to the real server, and the real server returns the response directly to the client, so the scheduler only processes the request message, unlike the LVS-DR, which is Lvs-tun IP tunneling technology, so real Server and director can be in different physical networks.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/70/wKiom1b_bEyQC88vAACwYy8dyPw155.png "title=" _3) Ybvgob57}]9[%3occha6.png "alt=" Wkiom1b_beyqc88vaacwyy8dypw155.png "/>
Lvs-tun topology diagram
Configured on Director server:
~]# ifconfig tunl0 192.168.145.200 netmask 255.255.255.255 up
~]# Route add-host 192.168.145.200 Dev tunl0
~]# ipvsadm-at 192.168.145.200:80-s RR
~]# Ipvsadm-at 192.168.145.200:80-r 192.168.145.203:80-i
~]# Ipvsadm-at 192.168.145.200:80-r 192.168.145.205:80-i
Because the VIP is set on Real server, the ARP broadcast function needs to be turned off and configured into the following:
~]# ifconfig tunl0 192.168.145.200 netmask 255.255.255.255 up
~]# Route add-host 192.168.145.200 Dev tunl0
~]# 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
Third, three modes of merit and disadvantage
NAT Mode:
Advantages:
1. Support Port mappings.
2.Real server can use any OS.
3. Only one public network IP is required
Disadvantages:
1. The request and response messages are forwarded through the Director, and the director is prone to becoming a system bottleneck.
2.director and real server must be on the same network segment.
Dr Mode:
Advantages:
1. The request message is dispatched through the director, but the response message must not be passed through the director.
A 2.Real server address can use a private address, but you can also use a public network address.
Disadvantages:
1.Real Server and director must be in the same physical network.
2. Port mappings are not supported.
Tun Mode:
Advantages:
1.Real Server and director can be in different physical networks.
2. the request message is dispatched through the director, but the response message must not be passed through the director.
Disadvantages:
1. The load scheduler, the real server must support the network card of the Tunneling protocol.
2. Multiple public IP addresses are required.
3. Creating an IP tunnel requires additional overhead.
4. Port mappings are not supported.
This article is from the "JC" blog, be sure to keep this source http://jackeychen.blog.51cto.com/7354471/1759561
Introduction to LVS Load Balancing technology