Ubuntu 14.04
Sponsored Link

Configure LVS (Linux Virtual Server)2016/01/11

Configure LVS (Linux Virtual Server) to build a load barancer.
This example is based on the environment below.
        |     |                    |
    eth0|      eth0|       eth0|
 +------+-----+     +-------+------+     +-------+------+
 | LVS Server |     |   Backend#1  |     |   Backend#2  |
 |            |     |  Web Server  |     |  Web Server  |
 +------------+     +--------------+     +--------------+

HTTP packets to on LVS Server are forwarded to Backend01 and Backend02 Servers with DSR(Direct Server Return).
[1] Install ipvsadm.
apt-get -y install ipvsadm
vi /etc/default/ipvsadm
# change

# change

# change to the interface to use

/etc/init.d/ipvsadm start

[2] Configure virtual IP address on LVS Server.
vi /etc/network/interfaces
# add to the end

auto eth0:0
iface eth0:0 inet static
ifup eth0:0

ip addr show eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP< mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:39:8a:e6 brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0
       valid_lft forever preferred_lft forever
    inet brd scope global secondary eth0:0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe39:8ae6/64 scope link
       valid_lft forever preferred_lft forever
[3] For DSR mode, return packets from backends to clients are directly returned, so it's nesessary to configure following settings. Set it on all backend servers.
# specify virtual IP address

iptables -t nat -A PREROUTING -d -j REDIRECT
[4] Configure Load Balancing settings on LVS server.
# clear tables

ipvsadm -C
# add virtual service

# [ ipvsadm -A -t (Service IP:Port) -s (Distribution method) ]

ipvsadm -A -t -s rr

# add backend real servers

# [ ipvsadm -a -t (Service IP:Port) -r (Real Server's IP:Port) -g ]

ipvsadm -a -t -r -g

ipvsadm -a -t -r -g

# confirm tables

ipvsadm -l

IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP rr
  -> node01.srv.world:http     Route   1      0          0
  -> node02.srv.world:http     Route   1      0          0

# save rules

ipvsadm -S >> /etc/ipvsadm.rules
[5] It's OK, Access to the Service IP address and make sure it works normally.
By the way, there are some Distribution method like follows.
Method Description
rr Robin Robin
distributes jobs equally amongst the available real servers.
wrr Weighted Round Robin
assigns jobs to real servers propor-tionally to there real servers' weight. Servers with higher weights receive new jobs first and get more jobs than servers with lower weights. Servers with equal weights get an equal dis-tribution of new jobs.
lc Least-Connection
assigns more jobs to real servers with fewer active jobs.
wlc Weighted Least-Connection
assigns more jobs to servers with fewer jobs and relative to the real servers' weight (Ci/Wi). This is the default.
lblc Locality-Based Least-Connection
assigns jobs destined for the same IP address to the same server if the server is not overloaded and available, otherwise assign jobs to servers with fewer jobs, and keep it for future assignment.
lblcr Locality-Based Least-Connection with Replication
assigns jobs destined for the same IP address to the least-con- nection node in the server set for the IP address. If all the node in the server set are over loaded, it picks up a node with fewer jobs in the cluster and adds it in the sever set for the target. If the server set has not been modified for the speci-fied time, the most loaded node is removed from the server set, in order to avoid high degree of replication.
dh Destination Hashing
assigns jobs to servers through looking up a statically assigned hash table by their destination IP addresses.
sh Source Hashing
assigns jobs to servers through looking up a statically assigned hash table by their source IP addresses.
sed Shortest Expected Delay
assigns an incoming job to the server with the shortest expected delay. The expected delay that the job will experience is (Ci + 1) / Ui if sent to the ith server, in which Ci is the number of jobs on the the ith server and Ui is the fixed service rate (weight) of the ith server.
nq Never Queue
assigns an incoming job to an idle server if there is, instead of waiting for a fast one, if all the servers are busy, it adopts the Shortest Expected Delay policy to assign the job.

Matched Content