Using LVS for load Balancing in Linux

Source: Internet
Author: User

What is LVS

LVS is a shorthand for Linux virtual server, that is, a virtualized server cluster system. LVS is also known as the four-tier routing, which works on the transport layer.

Introduction to LVS Technology

The LVS cluster uses IP load balancing technology and content-based request distribution technology. 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 eliminates the need to modify client and server-side programs. To do this, you need to consider system transparency, scalability, high availability, and manageability at design time.

Components of LVS

Lvs=ipvs+ipvsadm Ipvs: is a kernel framework, working on the input chain, equivalent to the NetFilter framework of iptables, the framework according to the rules defined on the input chain to carry out packet forwarding, try not to enter the user space Ipvsadm: equivalent to the Iptabels command, which defines rules for Ipvs 123123

The noun explanation of LVS

CIP: Client ipvip: Virtual IP, can be transferred, configure Load Balancer server, communicate with CIP. Real server: A server DS:LVS server dip that is actually responding: an IP that interacts with a real server server, communicates with RIP, and is on a load-balanced machine. IP of the rip:real server.

650) this.width=650; "Src=" http://img.blog.csdn.net/20170724161901526?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2fpcnvpmtiz/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" here to write a picture describing "title=" "/>

Working model of LVS

The  1. nat mode:     is equivalent to the dnat:     feature:     a. The RIP for RS is a private IP, and the gateway only wants to dip    b.rs the RIP and dip required to     c within a network segment. Both the request and the response are in the LVS server      d. Port mapping can be done   2. DR mode:     requests go over the LVS server, and the response is not only over the LVS server, The direct response from RS to the client side.      process: The client sends DIP.VIP packets to Ds,ds to convert the original destination MAC address into a Mac of a   host in the RS server, and then broadcasts it through the VIP network card to reach RS, The RS processing is sent out via another router to respond to the data   packet to the client. The      rs configuration requires:     to configure RIP and VIP, and the VIP is configured on Io. RS and DS to be in the same network segment      feature:                 rs Gateway cannot point to dip, port mapping is not supported  3. run mode:     use IP tunneling technology, Once again IP encapsulation      mechanism:         on the original message The CIP.VIP message sent by the client arrives at Ds,ds and turns the message into Cip.vip dip by two packages. RIP message,   into the DS to forward from the dip interface to send the value of the Internet, RS received the message after the analysis, sent to the target IP pseudo-rip,   to receive, and then sent to aLayer IP message, once again, found that the target IP for the VIP,RS configuration VIP, so accept into the    line response, sent to the Internet Vip.cip message      features:             1,RIP,DIP,VIP all the public address              2,rs Gateway does not point to dip             3, port mapping not supported              The 4,rs OS must support tunnel functionality

650) this.width=650; "Src=" http://img.blog.csdn.net/20170724171401852?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2fpcnvpmtiz/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" here to write a picture describing "title=" "/>

650) this.width=650; "Src=" http://img.blog.csdn.net/20170724173220359?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2fpcnvpmtiz/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" here to write a picture describing "title=" "/>

LVS Scheduling algorithm

1. Static method: RR: Polling scheduling algorithm WRR: Weighted polling scheduling algorithm SH: The original address hash, to achieve the same IP directed to the same server DH: Destination address hash 2. Dynamic method: LC: Minimum link, rs load = active link number *256+ inactive links WRC: weighted least link, RS load/weight sed: Minimum expected delay, improved WRC, calculation method payload = (active link +1) *256/wight NQ: The never-queued scheduling algorithm, at the beginning, is based on the search to divide the request from the big to the small.

Ipvsadm Command Writing Rules

 1.  Add a service cluster:     ipvsadm -a| E -t|u|f vip [-s scheduler] [-p [timeout]] [-m netmask] [--pe  persistence_engine]        -a: Add a service cluster                      -t:TCP                      -u:UDP                     -f: Firewall Tag                      -s: Scheduling Algorithm               -E: Modify the server cluster   2.  add rs    ipvsadm -a|e -t|u| in the service cluster F vip -r dip [options]    &nbsP;   -a: Add a rs                     -t:tcp                     -u:udp                     -f: Firewall                      -r rip             [option]: Commonly used              -G:DR mode (default)                      -m:nat Mode             -E: Modify   3.  Delete      ipvsadm -d  -t|u|f vip           //Delete a service cluster      ipvsadm  -d -t|u|f VIP -r RIP 4.  Clear All Rules      ipvsadm - c 5.  Save     ipvsadm -S [-n] 6.  Reload      ipvsadm -r 7.  View     ipvsadm -L|l [option]     OPTION:        -N: Digital format display IP address                  -c: Displays information about the number of connections                  --stats: Show Statistics                  --rate: Average rate per second   8.  counter clear 0      IPVSADM -Z [-T|U|F VIP]
 1.  structure     dr:clone1  192.168.80.150 (VIP), 192.168.100.1 (DIP)     rs:clone2  192.168.100.2    rs:clone3   192.168.100.3 2.  Step:     ds:         ifconfig eth1 DIP_GW up         Ifconfig eth0:0 vip        ipvsadm -a -t vip  -s rr        ipvsadm -a -t vip -r  rip -m    rs:        ifconfig eth0  Rip up        route add default gw dip 

650) this.width=650; "Src=" http://img.blog.csdn.net/20170724183422936?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2fpcnvpmtiz/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" here to write a picture describing "title=" "/>

650) this.width=650; "Src=" http://img.blog.csdn.net/20170724202059585?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2fpcnvpmtiz/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" here to write a picture describing "title=" "/>

Load balancing for LVS using Dr mode

 1.  structure     ds:    192.168.80.150 (VIP)      rs:        192.168.80.130         192.168.80.131 2.  Step     ds Configuration:     ifconfig  eth0:0 vip up     route add -host vip dev eth0:0      ipvsadm -A -t vip -s rr      Ipvsadm -a -t vip -r rip -g -w wight    rs configuration:      echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore      echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore      echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce     echo  2 > /proc/sys/net/ipv4/conf/eth0/arp_announce     ifconfig eth0 rip       ifconfig lo:0 VIP netmask 255.255.255.255 broadcast VIP  up     route add -host vip dev lo:0

650) this.width=650; "Src=" http://img.blog.csdn.net/20170724203141784?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2fpcnvpmtiz/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" here to write a picture describing "title=" "/>

650) this.width=650; "Src=" http://img.blog.csdn.net/20170724203537875?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqva2fpcnvpmtiz/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Southeast "alt=" here to write a picture describing "title=" "/>

The durability of LVS

 1.  persistent client link (PCC): All requests to the VIP in the future to the same client are directed to the unified RS within the effective time.     :ipvsadm -a -t ip:0 -s rr  -p time  when adding rules  2.  Persistent Port Link (PPC): All requests to a port from a unified client to a VIP are all directed to   the same RS within the effective time. Ipvsadm default is to use the ppc  3.  Persistent firewall tag link (PFMC): Port binding, based on the firewall tag, will be two or two or more than two   port binding as a unified service.      Add a Firewall tag: (multiple ports marked as uniform tag code, use multiple statements)               #iptable  -t mangel -A PREROUTING -d VIP -p tcp  --dport rs_port -j mark --set-mark  Tag Code {0-99}          mangel: Modify the header of the message and mark it. Mark before input.      Add Rule:             #ipvsadm  -A -f  tag Codes  -s -p         #ipvsadm  -a  -f  Tag Code  -r ip -g 


Using LVS for load Balancing in Linux

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.