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. | --------+-------------------------------------------------------------------- | +-------------------+--------------------+ |10.0.0.40(VIP) | | eth0|10.0.0.30 eth0|10.0.0.51 eth0|10.0.0.52 +------+-----+ +-------+------+ +-------+------+ | LVS Server | | Backend#1 | | Backend#2 | | | | Web Server | | Web Server | +------------+ +--------------+ +--------------+ |
HTTP packets to 10.0.0.40(VIP) on LVS Server are forwarded to Backend01 and Backend02 Servers with DSR(Direct Server Return).
|
|
[1] | Install ipvsadm. |
root@dlp:~#
apt-get -y install ipvsadm
root@dlp:~#
vi /etc/default/ipvsadm # change AUTO=" true "
# change DAEMON=" master "
# change to the interface to use IFACE=" eth0 "
/etc/init.d/ipvsadm start |
[2] | Configure virtual IP address on LVS Server. |
root@dlp:~#
vi /etc/network/interfaces # add to the end auto eth0:0 iface eth0:0 inet static address 10.0.0.40 network 10.0.0.0 netmask 255.255.255.0 ifup eth0:0 root@dlp:~# 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 10.0.0.30/24 brd 10.0.0.255 scope global eth0 valid_lft forever preferred_lft forever inet 10.0.0.40/24 brd 10.0.0.255 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 root@node01:~# iptables -t nat -A PREROUTING -d 10.0.0.40 -j REDIRECT
|
[4] | Configure Load Balancing settings on LVS server. |
# clear tables root@dlp:~# ipvsadm -C
# add virtual service # [ ipvsadm -A -t (Service IP:Port) -s (Distribution method) ] root@dlp:~# ipvsadm -A -t 10.0.0.40:80 -s rr # add backend real servers # [ ipvsadm -a -t (Service IP:Port) -r (Real Server's IP:Port) -g ] root@dlp:~# ipvsadm -a -t 10.0.0.40:80 -r 10.0.0.51:80 -g root@dlp:~# ipvsadm -a -t 10.0.0.40:80 -r 10.0.0.52:80 -g # confirm tables root@dlp:~# ipvsadm -l IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.40:http rr -> node01.srv.world:http Route 1 0 0 -> node02.srv.world:http Route 1 0 0 # save rules root@dlp:~# 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.
|
Sponsored Link |
|