Configure LVS (Linux Virtual Server)2013/08/20 |
Configure LVS to build a load barancer.
This example shows to configure it on the environment below. | | eth0|192.168.0.100 +----------+ --------------------| LVS |---------------------- +----------+ eth1|10.0.0.100 | +----------+ | +----------+ | |10.0.0.30 | 10.0.0.31| | | Backend1 |------------------------------| Backend2 | | Web | eth0 eth0| Web | +----------+ +----------+ |
Packets to the eth0 on LVS Server are forwarded to Backend1 and Backend2 Servers with NAT.
Please change the default gateway to internal IP address of LVS on both Backend Web Servers first.
(it's 10.0.0.100 on this example)
|
|
[1] | Install ipvsadm |
[root@gw ~]#
yum -y install ipvsadm
[root@gw ~]#
vi /etc/sysctl.conf # line 7: change net.ipv4.ip_forward = 1
sysctl -p # reload [root@gw ~]# /etc/rc.d/init.d/ipvsadm start ipvsadm: Clearing the current IPVS table: IPVS: Registered protocols (TCP, UDP, SCTP, AH, ESP) IPVS: Connection hash table configured (size=4096, memory=64Kbytes) IPVS: ipvs loaded. [ OK ] ipvsadm: Applying IPVS configuration: IPVS: [wlc] scheduler registered. [ OK ] [root@gw ~]# chkconfig ipvsadm on |
[2] | Set ipvsadm |
# clear tables first [root@gw ~]# ipvsadm -C
# add virtual service # [ipvsadm -A -t (Service IP:Port) -s (Distribution method)] [root@gw ~]# ipvsadm -A -t 192.168.0.100:80 -s wlc # add real servers # [ipvsadm -a -t (Service IP:Port) -r (Real Server's IP:Port) -m] ("m" means masquerading (NAT)) [root@gw ~]# ipvsadm -a -t 192.168.0.100:80 -r 10.0.0.30:80 -m [root@gw ~]# ipvsadm -a -t 192.168.0.100:80 -r 10.0.0.31:80 -m # confirm tables [root@gw ~]# ipvsadm -l IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 192.168.0.100:http wlc -> 10.0.0.30:http Masq 1 0 0 -> 10.0.0.31:http Masq 1 0 0 # save the config [root@gw ~]# /etc/rc.d/init.d/ipvsadm save ipvsadm: Saving IPVS table to /etc/sysconfig/ipvsadm: [ OK ] |
[3] |
It's OK all. Access to the Service IP address and make sure it works normally.
By the way, there are some Distribution method like follows.
|
Sponsored Link |