Simple implementation of LVS load balancing

Source: Internet
Author: User

1. Theoretical part

650) this.width=650; "src=" Http:// "title=" Lvs.png "alt=" Wkiol1ycwesr1un2aaesqihvnla995.jpg "/>

1.1, the structure of LVS

Dispatch Layer (Director):

Cluster layer (Real Server)

Shared layer

1.2, LVS Three kinds of work mode

1) Dr Mode

-MAC Layer Implementation

-Director changes the requested packet target Mac to the MAC address of the real server

-Data is returned directly to the client

2) Nat mode

-IP Layer Implementation

-Director changes the requested destination IP to the IP of the real server

-Data returned at Director to restore source IP

3) Tun Mode

-Similar to VPN implementations

-Director establishes encrypted IP tunnel forwarding to real Server

-Data is returned directly to the client

1.3, the LVS IP classification

1) VIP (Virtual IP)

-VIP Each machine needs to be configured

-IP for intranet communication and external service

2) DIP (Driector IP)

-Dip set on Driector server

-Sub-network IP, intranet IP for internal communication, external network IP for NAT mode extranet

3) RIP (Real IP)

-RIP is set on real server

-Only intranet Ip,ip only for intranet communication

1.4, the LVS scheduling algorithm:

1) Round call scheduling (Round Robin, abbreviated RR)

2) weighted round call (Weighted Round Robin, abbreviated WRR)

3) Minimum link (Least Connection, abbreviation LC)

4) Weighted least link (Weighted Least conncetions, referred to as WLC)

2. Experimental part

2.1, the experimental premise

1) host information


Director ipaddress=

VIP ipaddress=



Real ipaddress=

Vip-lo ipaddress=



Real ipaddress=

Vip-lo ipaddress=


2) Yum Source

In Real Server

Yum Install-y httpd

In Director

Yum Install-y Ipvsad

2.1. NAT Mode Configuration

650) this.width=650; "src=" Http:// "title=" Lvs-nat.png "alt=" Wkiom1ycavyxax8laaglesfs6yy431.jpg "/>

Vim adds/usr/local/sbin/

#! /bin/bash# director  server to turn on the route forwarding feature:  echo 1  > /proc/sys/net/ipv4/ip_forward #  disable redirection of ICMP echo 0 > /proc/sys/net/ Ipv4/conf/all/send_redirectsecho 0 > /proc/sys/net/ipv4/conf/default/send_redirectsecho  0 > /proc/sys/net/ipv4/conf/eth0/send_redirectsecho 0 > /proc/sys/net/ ipv4/conf/eth1/send_redirects# director  setting up NAT firewall iptables -t nat -fiptables -t  nat -xiptables -t nat -a postrouting -s  -j  masquerade# director set ipvsadmipvsadm= '/sbin/ipvsadm ' $IPVSADM  -C$IPVSADM -A -t -s lc -p 300$ipvsadm -a -t -r -m -w 1$ipvsadm -a -t -r  -m -w 1 

To run the script:


2.2. Dr Mode configuration

In Director

Vim adds/usr/local/sbin/

#! /bin/bashecho 1 >/proc/sys/net/ipv4/ip_forwardipv=/sbin/ipvsadmvip= eth0:0 $VIP broadcast $vip netmask uproute add-host $vip Dev eth0:0$ipv-c$ipv-a-t $VIP: 80-s RR $IPV-t $vip: 80-r $rs 1:80-g-W 1$ipv-a-t $vip: 80-r $rs 2:80-g-W 1

In Real Server

Vim adds/usr/local/sbin/

#! /bin/bashvip= lo:0 $VIP broadcast $VIP netmask up Route add-host $vip Lo:0echo "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

To run the script:

In Director


In Real Server


Reference documents:

How the LVS-DR works


LVS Scheduling Algorithm Classification:


Arp_ignore&arp_announce parameter (dr Mode):


This article is from the "Old Tan Linux Blog" blog, please be sure to keep this source

Simple implementation of LVS load balancing

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: 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.