High-Availability Implementation & mdash; LVS (LinuxVirtualServer) LinuxVirtualServer several terms: ctor: also known as the scheduler, LVS front-end device; realserver: also known as the real internal server, is actually providing services; VIP: The published IP address, that is, the customer... high availability-Linux Virtual Server (LVS) Linux Virtual Server terms: ctor: also known as a scheduler, LVS front-end device; realserver: also known as a real internal Server, is actually providing services; VIP: The published IP address, that is, the IP address requested by the customer; DIP: The address for communication between the scheduler and the realserver; LVS working mode introduction LVS server cluster load balancing has three ways, NAT, DR and TUN, the following briefly talk about the differences between these three methods: LVS-NAT: the idea of this method is to implement data spoofing at the network layer (IP layer ). The destination address of the IP package sent from the client to redirector is replaced. 1. in the network environment, one ctor + N realservers. director and realserver are in the same private network segment. director is the default gateway of realserver. Only director has public IP addresses and can be exposed on the wide area network. 2. the client requests a public IP (director) first. the IP address of the IP packet in the request packet is replaced with the IP address of a realserver selected by director according to the load balancing policy. 3. after the realserver responds to the request, it generates a returned data packet. the source address of the returned data packet is the IP address of the realserver, and the destination address is the IP address of the client server. Because the default gateway of realserver is redirector, although the destination address of the returned IP packet is the IP address of the client, the returned data packet is first sent back to redirector. Redire implements spoofing again and changes the source address of the returned IP packet to its own IP address. Then, it is forwarded to the vSwitch and returned to the client. The redirector task is to implement two IP layer spoofing modifications, one is to modify the target address of the request data packet, the purpose of this modification is to achieve load balancing distribution of data. The other is to modify the source address of the response packet to hide the realserver, so that the user does not feel the existence of the realserver. 3. restrictions: the throughput of the entire cluster is limited by the bandwidth of redirector (mainly the egress bandwidth ). LVS-DR: the idea of this method is to implement data spoofing on the data link layer and modify the Mac address of network frame data. 1. in the network environment, one ctor + N realservers, director and realserver both have public IP addresses and are exposed on the wide area network. In addition, realserver also has an ip alias that is the same as the director IP address. In other words, the realserver has two ip addresses, a real IP address, and an IP alias (that is, a public IP address) that is the same as the direcotr address. a public ip address is the IP address opened to the client. Realserver also needs to make a configuration so that they ignore all ARP broadcasts targeting public IP addresses. when the system arp broadcast asks which mac address has a public IP address, only the scheduling server will respond, data sent from outside will not be sent to the actual server. 2. the client requests a public IP address (director) first. because the network environment has been configured that only director has responded to ARP broadcast, the mac address of the request packet will be changed to the mac address of the realserver. That is to say, redireimplements link layer spoofing to replace the target mac address of the frame data with the mac address of a realserver determined based on the load balancing policy. 3. the realserver responds to the request that the realserver receives the mac frame and then assembles the mac frame into an ip package. it finds that the destination address in the ip package is the same as its own ip address alias and there is no problem. proceed with the process, (This is why the ip alias must be the same. if the ip alias is different, the operating system may directly ignore it.) generate a response data and send it back. At this time, because redirector is not the default gateway, the data will be directly sent to the wide area network, and the wan will send the data to the client. 4. advantage: the returned data packet does not need to pass through redirector, and there is no redirector bandwidth bottleneck. In principle, the bandwidth of the cluster is the sum of the bandwidth of all servers. of course, they cannot exceed the bandwidth of the connected Wan switch. 5. restrictions: you need to purchase multiple public IP addresses. director and realserver must be in the same wan cidr block, that is, on the same vSwitch. Why must I be in the same CIDR block? If the realserver is in another CIDR block, redirechanges the entire packet and mac frame before sending it to the switch. The Switch finds that the mac address cannot be found in its wan and cannot forward it. LVS-TUN: This method is to break through the limitations of the LVS-DR within the same network segment. It does not cheat, but is a bright and bright communication, and is encapsulated twice at the network layer. 1. in the network environment, one ctor + N realservers, director and realserver both have public IP addresses and are exposed on the wide area network. Public ip addresses are different from each other, and there is no alias restriction or need not be in the same network segment. 2. the client requests the client to send data to redirector, and redireputs the IP package as a valid load into a new IP package, determine the ip address of a specific realserver as the destination address of the new ip package based on the scheduling policy. These new IP packets are completely compliant with network protocols, and there is no deception. Therefore, these IP packets must pass through the wan CIDR block to reach the specified realserver. 3. after the realserver responds to the data obtained by The realserver, it needs to do something, extract the payload of the IP packet, and then use these loads as the IP packet to form TCP, then form the final request data up. Based on the request data, after the realserver generates the returned data, it returns the result to the client. 4. Advantage: like LVS-DR, there is no redirector outbound bandwidth bottleneck. 5. Disadvantages: additional packaging and package settlement are required. LVS configuration LVS-NAT configuration 1, realserver configuration requirements: configure the internal private network address, the default gateway pointing to the scheduling server 2, Directer configuration requirements basic configuration: the scheduling server requires two NICs (one for external network and one for internal network. One module can also be used to configure sub-interfaces. the external VIP and DIP are both configured on the same Nic, but this will further reduce the performance of the scheduler. we recommend that you use a dual NIC) disable selinux and iptablessetenforce 0 service iptables stop (to avoid unnecessary troubles, disable these two services on each server) enable the packet forwarding function echo "1">/proc/sys/net/ipv4/ip_forward1_sadm-A-t $ VIP: $ Port-s rr explanation: -A indicates adding A cluster service (multiple services can be added, for example, adding A web 80 and an https 443);-t indicates tcp; -s indicates that the scheduling algorithm is round robin (a total of 10 scheduling algorithms can be selected as needed) ipvsadm-a-t $ VIP: $ Port-r $ DIP: $ Port-m explanation:-a indicates adding a realserver, followed by the address Port of the previously defined cluster service.-r indicates adding a specific real The address of the server,-m indicates that the mode is NAT mode LVS-DR configuration 1, Realserver configuration requirements basic configuration first configure the limit arp, otherwise after the address is configured, the address conflict occurs, you can modify the kernel parameters. In linux, by default, arp broadcasts of IP addresses on all interfaces are advertised on the interface, and arp requests of IP addresses on all interfaces are responded to. arp_announce: advertise arp broadcasts of IP addresses on all interfaces on the interface. 1. restrict broadcast notification responses to arp requests from other devices as much as possible on the interface (not strict enough). 2: only the arp broadcast arp_ignore of the IP address on this interface is advertised. The maximum arp response level is 0. for arp requests from other devices, the arp response level of the IP address on all other interfaces is 1: for arp requests from other devices, only reply to the arp response echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "2">/proc/sys/net/ipv4 /conf // lo/arp_announceecho "1">/proc/sys/net/ipv4/conf/all/arp_ignoreecho "2">/proc/sys/net/ipv4/conf/ all/arp_announce configures VIP on the lo Port of realserver, this configuration limits that the VIP will not generate a MAC address table on the physical switch, so as to avoid IP conflict ifconfig lo: 1 $ VIP broadcast $ VIP netmask broadcast bandwidth 255.255ifconfig eth0 $ DIP up note that the broadcast address of this VIP interface is still VIP, which limits its broadcast. the subnet mask is 32 bits, in the following configurations on the scheduler, pay attention to this configuration for special routes, so that the lo Port with the source address as VIP of the destination VIP package goes out route add-host $ VIP dev lo: 1Directer configuration requires VIP and DIP configuration. VIP is configured on the sub-interface of the physical network card ifconfig eth0 $ DIP broadcast $ VIP netmask 255.255.0 upifconfig eth0: 1 $ VIP broadcast $ VIP netmask route 255.255.255 up configure a special route. The goal is to route the VIP package from the physical sub-interface configured with the VIP to route add-host $ VIP dev eth0: 1 cluster configuration ipvsadm-A-t $ VIP: $ Port-s rr explanation:-A indicates adding A cluster service (the configuration is the same as that in NAT) ipvsadm-a-t $ VIP: $ Port-r $ DIP: $ Port-g explanation: The other is similar to NAT. in the final mode, change to-g, that is, DR mode.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.