Configure LVS (Linux Virtual Server)2015/06/10 |
Configure LVS (Linux Virtual Server) to build a load barancer.
This example is based on the environment below. | | eth0|192.168.0.30 +----------+ --------------------| LVS |---------------------- +-----+----+ eth1|10.0.0.30 | +------------+ | +------------+ | Backend01 |10.0.0.51 | 10.0.0.52| Backend02 | | Web Server +------------+-------------+ Web Server | | |eth0 eth0| | +------------+ +------------+ |
HTTP packets to the eth0 on LVS Server are forwarded to Backend01 and Backend02 Servers with NAT.
Change the default gateway to internal IP address of LVS on both Backend Web Servers first. (it's 10.0.0.30 on the example)
|
|
[1] | Install ipvsadm. |
[root@dlp ~]#
yum -y install ipvsadm # enable IP forward [root@dlp ~]# echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf [root@dlp ~]# sysctl -p
touch /etc/sysconfig/ipvsadm [root@dlp ~]# systemctl start ipvsadm [root@dlp ~]# systemctl enable ipvsadm |
[2] | Configure Load Balancing. |
# clear tables [root@dlp ~]# ipvsadm -C
# add virtual service # [ ipvsadm -A -t (Service IP:Port) -s (Distribution method) ] [root@dlp ~]# ipvsadm -A -t 192.168.0.30:80 -s wlc # add backend real servers # [ ipvsadm -a -t (Service IP:Port) -r (Real Server's IP:Port) -m ] ("m" means masquerading (NAT)) [root@dlp ~]# ipvsadm -a -t 192.168.0.30:80 -r 10.0.0.51:80 -m [root@dlp ~]# ipvsadm -a -t 192.168.0.30:80 -r 10.0.0.52:80 -m # 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 dlp.srv.world:http wlc -> 10.0.0.51:http Masq 1 0 0 -> 10.0.0.52:http Masq 1 0 0 |
[3] | 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 |
|