LVS - Load Balancing Detaied Tutorial - Step 2: LVS Configuration
In this step, we will config web server and load balancer server.
####################################################################################################
Step 2: LVS Setup configuration on LB1 and LB2
a. On Load Balacer Server
Install on Lvs1 and lvs2:
# yum install -y piranha
On Lvs1:
# vim /etc/sysconfig/ha/lvs.cf
serial_no = 14
primary = 192.168.44.101
service = lvs
rsh_command = ssh
backup_active = 1
backup = 192.168.44.102
heartbeat = 1
heartbeat_port = 1050
keepalive = 2
deadtime = 10
network = direct
debug_level = NONE
monitor_links = 1
virtual server1 {
active = 1
address = 192.168.44.130 eth0:1
port = 80
send = "GET / HTTP/1.1\r\n\r\n"
expect = "HTTP"
load_monitor = uptime
scheduler = rr
protocol = tcp
timeout = 10
reentry = 180
quiesce_server = 0
server www1 {
address = 192.168.44.131
active = 1
weight = 1
}
server www2 {
address = 192.168.44.132
active = 1
weight = 1
}
}
#scp /etc/sysconfig/ha/lvs.cf lvs2:/etc/sysconfig/ha/
#vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
#scp /etc/sysctl.conf lvs2:/etc/
sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
Start Service
# /etc/init.d/pulse restart
Shutting down pulse: [ OK ]
Starting pulse: [ OK ]
# tail -f /var/log/messages
Dec 15 21:28:35 lvs1 pulse[2718]: Terminating due to signal 15
Dec 15 21:28:54 lvs1 pulse[2734]: STARTING PULSE AS MASTER
Dec 15 21:28:55 lvs1 pulse[2734]: backup inactive: activating lvs
Dec 15 21:28:55 lvs1 lvs[2736]: starting virtual service server1 active: 80
Dec 15 21:28:55 lvs1 kernel: send_arp uses obsolete (PF_INET,SOCK_PACKET)
Dec 15 21:28:55 lvs1 kernel: IPVS: [rr] scheduler registered.
Dec 15 21:28:55 lvs1 nanny[2749]: starting LVS client monitor for 192.168.44.130:80 -> 192.168.44.131:80
Dec 15 21:28:55 lvs1 lvs[2736]: create_monitor for server1/www1 running as pid 2749
Dec 15 21:28:55 lvs1 nanny[2750]: starting LVS client monitor for 192.168.44.130:80 -> 192.168.44.132:80
Dec 15 21:28:55 lvs1 lvs[2736]: create_monitor for server1/www2 running as pid 2750
Dec 15 21:28:55 lvs1 nanny[2750]: [ active ] making 192.168.44.132:80 available
Dec 15 21:28:55 lvs1 nanny[2749]: [ active ] making 192.168.44.131:80 available
Dec 15 21:29:00 lvs1 pulse[2742]: gratuitous lvs arps finished
Note: Only apear on Lvs server which you start service pulse after that server
b. On Web Server:
Install on 2 web servers:
# yum install -y httpd php php-mysql php-gd
# yum install -y arptables_jf
Web server 1:
#echo "www1.hbn.local" > /var/www/html/index.html
Web server 2:
#echo "www2.hbn.local" > /var/www/html/index.html
On both servers:
Start service
#service httpd start
#chkconfig --level 35 httpd on
Configure the Loopback interface :
# vim /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.44.130
NETMASK=255.255.255.255
NETWORK=192.168.44.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=192.168.44.255
ONBOOT=yes
NAME=loopback
#ifup lo:0
#arptables -A IN -d 192.168.44.130 -j DROP
#arptables -A OUT -d 192.168.44.130 -j mangle --mangle-ip-s 192.168.44.101
#arptables -A OUT -d 192.168.44.130 -j mangle --mangle-ip-s 192.168.44.122
# /etc/init.d/arptables_jf save
Saving current rules to /etc/sysconfig/arptables: [ OK ]
Start loopback interface on startup
# echo "ifup lo:0" > /etc/rc.local
c. Test Connection
To show connections:
# ipvsadm -L ( only on one server which start pulse after)
#watch ipvsadm -Lcn
Demo - Video: Watch with HD
Or: http://www.mediafire.com/?tog1lgvss0pqap1
------------------------------------------------------------
Thanks for reading
--------------------------------------------------------------------------
All my Lab:
Linux Lab -- window and Cisco Lab
to be continued - I will update more.
Nam Habach