LVS Load Balancer Usage Explained

Source: Internet
Author: User

I. Introduction to the Basic overview

Ii. types and principles of LVS

Three, LVS scheduling algorithm

Iv. using DR and Nat to achieve web load balancing


I. Introduction to the Basic overview

LVS is a load balancing software that works at the transport level and consists of two components of the IPVSADM and kernel space of the user space Ipvs. The Ipvsadm is a command-line tool for user space, primarily for managing the Cluster service and RS on the Cluster service. Ipvs is a program on the input chain that works with the netfilter on the kernel and can be forwarded based on the user's pre-defined cluster implementation.


Ii. types and principles of LVS

The types of LVS can be divided into: NAT, DR, TUN, Fullnat four types


Lvs-nat Model : Need to point RS gateway to the dip address of LVS

Principle: By modifying the target address and the target port in the request message to a selected RS rip and port, to enable forwarding

Process: The ① client sends the request to the front-end load balancer, the source address of the request message is CIP, the destination address is the VIP

After the ② load balancer receives the message, the normal message is entered into the user space, but the discovery request is the address that exists in the rule, then

The destination address of the message is changed to the rip address of the back-end RS Server, the original CIP is unchanged, and the message is sent away.

After the ③ message is sent to the RS server, because the destination address of the message is itself, all will respond to the client's request and return the pack documentation to the Scheduler,

At this point the original address is RIP and the destination address is CIP

After the ④ dispatcher receives the message, the source address of the message is changed to VIP, and then the message is returned to the client.



LVS-DR Model:

Principle: The source and destination IP and port are not sent changes, by re-encapsulation of the request packet a Mac header for forwarding, the source Mac is the Dip interface

Mac, Target Mac is the Mac of the Rip interface of the RS server

Process: ① client sends request message to LVS Scheduler, request message Source address is CIP, destination address is VIP, source Mac is CMAC, Target Mac

is the VIP interface of the LVs mac

after the ②LVS receives the message, it discovers that the request is in the definition rule, then it wraps the source MAC address of the client's request message back to its own d I

P, Target Mac to select the MAC address of the VIP interface for the RS.

③rs received the message, found in the message that the purpose of the MAC is its own VIP interface of the MAC, will receive the message comes out, will respond directly to the client



Lsv-tun Model:

Principle: Do not modify the IP header in the request packet (the source IP is CIP, the target IP is the VIP), but the original IP header and then encapsulate an IP header (the source IP is

DIP, the target IP is the selected RS rip), then sends the message to the selected target RS


Lsv-fullnat Model:

principle: Forwarding by simultaneously modifying the source IP address and destination IP address in the request message


Three, LVS scheduling algorithm

Depending on whether the current load of the backend host is considered when scheduling, it can be divided into static and dynamic methods:

Static algorithm: The scheduler is simply based on the algorithm itself to schedule, regardless of the RS after the actual connection and load situation, pay attention to the beginning of fairness

RR: Polling Schedule

WRR: Weighted Polling

SH: Source address hash, the request from the same IP address is always sent to the first pick in the RS, you can implement session binding

DH: Destination Address hash: A request destined for the same destination address, always forwarded to the first pick of the RS



Dynamic algorithm:

LC: Minimum Connection

WLC: Weighted Minimum connection

SED: Shortest expected delay

NQ: Never-queued connections

LBLC: Dynamic DH algorithm based on local minimum connection

LBLCR: LBLC with copy function


Iv. using DR and Nat to achieve web load balancing

NAT model-based Web load:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/85/6D/wKiom1ei9szgvfG3AACijp5GnzY629.png "title=" 122. PNG "width=" "height=" 364 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:750px;height:364px; "alt=" Wkiom1ei9szgvfg3aacijp5gnzy629.png "/>

Configure Real Server

RS1:

# # #配置IP地址和网关, the gateway points to Dip:[[email protected] ~]# route add default GW 192.168.100.100## #配置一个httpd测试网页: [[email protected] ~]# Yum-y install Httpd[[email protected] ~]# echo "Rserver 1" >/var/www/html/index.html [[email protected] ~]# Systemctl Start Httpd.service

RS2

# # #配置IP地址和网关, the gateway points to Dip:[[email protected] ~]# route add default GW 192.168.100.100## #配置一个httpd测试网页: [[email protected] ~]# Yum-y install Httpd[[email protected] ~]# echo "Rserver 2" >/var/www/html/index.html [[email protected] ~]# Systemctl Start Httpd.service


Configure Director

# #配置IP地址省略: # #配置路由转发功能: [[email protected] ~]# echo 1 >/proc/sys/net/ipv4/ip_forward## #测试下我们环境是否正常: [Email Protected] ~]# Curl http://192.168.1.10Rserver 1[[email protected] ~]# Curl Http://192.168.1.20Rserver 2

To add a rule :

[[email protected] ~]# ipvsadm-a-t 172.16.100.1:80-s rr[[email protected] ~]# ipvsadm-a-t 172.16.100.1:80-r 192.168. 1.10:80-m-W 1[[email protected] ~]# ipvsadm-a-T 172.16.100.1:80-r 192.168.1.20:80-m-W 1

To view rule information:

[Email protected] ~]# ipvsadm-lip Virtual Server version 1.2.1 (size=4096) Prot localaddress:port Scheduler Flags--             Remoteaddress:port Forward Weight activeconn inactconntcp 172.16.100.1:http rr--192.168.1.10:http MASQ 1 0 0-192.168.1.20:http masq 1 0 0



Web load based on the LVS-DR model

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/70/wKiom1ejL6DAI916AACfB5vf0t0495.png "title=" bar. png " alt= "Wkiom1ejl6dai916aacfb5vf0t0495.png"/> configuration director

[Email protected] ~]# ifconfig eno16777736:1 192.168.1.100/32 broadcast 192.168.1.100 up [[email protected] ~]# route add -host 192.168.1.100 Dev eno16777736:1[[email protected] ~]# ipvsadm-a-t 192.168.1.100:80-s RR [[email protected] ~]# I Pvsadm-a-T 192.168.1.100:80-r 192.168.1.105:80-g-W 1 [[email protected] ~]# ipvsadm-a-t 192.168.1.100:80-r 192.168 .1.106:80-g-W 2

Configure RealServer1

[[Email protected] ~] #echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore[[email protected] ~] #echo 1 >/proc/sys/net/ Ipv4/conf/lo/arp_ignore[[email protected] ~] #echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce[[email protected] ~ ] #echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce[[email protected] ~]# ifconfig lo:0 192.168.1.100/32 broadcast 192.168.1.100 up [[email protected] ~]# route add-host 192.168.1.100 Dev lo:0

Configure RealServer2

[[Email protected] ~] #echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore[[email protected] ~] #echo 1 >/proc/sys/net/ Ipv4/conf/lo/arp_ignore[[email protected] ~] #echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce[[email protected] ~ ] #echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce[[email protected] ~]# ifconfig lo:0 192.168.1.100/32 broadcast 192.168.1.100 up [[email protected] ~]# route add-host 192.168.1.100 Dev lo:0

LVS Load Balancer Usage Explained

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.