Monthly Archives: December 2011
Piranha Load Balancing
Red Hat adapted the Piranha load balancing software to allow for transparent load balancing and failover between servers. The application being balanced does not require special configuration to be balanced, instead a Red Hat Enterprise Linux server with the load balancer configured, intercepts and routes traffic based on metrics/rules set on the load balancer.
lba1.virtual.net 10.10.50.11/24
lba2.virtual.net 10.10.50.12/24
web1.virtual.net 10.10.50.21/24
web2.virtual.net 10.10.50.22/24
virtual ip 10.10.50.100/24
Load Balancers
We install piranha and ipvsadm packages on both load balancers.
# yum install piranha ipvsadm -y
Now we create file ipvsadm and we allow ipv4 forwarding.
#touch /etc/sysconfig/ipvsadm #sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/' /etc/sysctl.conf
Make ipv4 forwarding active
#sysctl -p net.ipv4.ip_forward = 1 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
We craete configuration file lvs.cf for both load balancers, lba1 will be primary and
lba2 will be secondary.In case of lba1 failure lba2 will take virtual ip.
lba1
[lba1]#cat /etc/sysconfig/ha/lvs.cf serial_no = 34 primary = 10.10.50.11 service = lvs rsh_command = rsh backup_active = 1 backup = 10.10.50.12 heartbeat = 1 heartbeat_port = 539 keepalive = 3 deadtime = 25 network = direct reservation_conflict_action = preempt debug_level = NONE virtual HTTP { active = 1 address = 10.10.50.100 eth0:1 vip_nmask = 255.255.255.0 port = 80 send = "GET / HTTP/1.1\r\n\r\n" expect = "HTTP" use_regex = 0 scheduler = rr protocol = tcp timeout = 4 reentry = 4 quiesce_server = 1 server web1 { address = 10.10.50.21 active = 1 weight = 1 } server web2 { address = 10.10.50.22 active = 1 weight = 1 } }
lba2
[lba2]#cat /etc/sysconfig/ha/lvs.cf serial_no = 34 primary = 10.10.50.11 service = lvs rsh_command = rsh backup_active = 1 backup = 10.10.50.12 heartbeat = 1 heartbeat_port = 539 keepalive = 3 deadtime = 25 network = direct reservation_conflict_action = preempt debug_level = NONE virtual HTTP { active = 1 address = 10.10.50.100 eth0:1 vip_nmask = 255.255.255.0 port = 80 send = "GET / HTTP/1.1\r\n\r\n" expect = "HTTP" use_regex = 0 scheduler = rr protocol = tcp timeout = 4 reentry = 4 quiesce_server = 1 server web1 { address = 10.10.50.21 active = 1 weight = 1 } server web2 { address = 10.10.50.22 active = 1 weight = 1 } }
Web servery
Now we install httpd on web servers and ensure to start httpd service at boot time.
#yum install httpd #chkconfig httpd on
We want to web servers were clustered with direct routing, we have to stop reverse ARP.
We can use iptables or arptables_jf.I recommande to use arptables.
#yum install arptables_jf -y #chkconfig arptables_jf on
We create arptables rules.
web1
[web1]#arptables -I IN -d 10.10.50.100 -j DROP [web1]#arptables -A OUT -d 10.10.50.100 -j mangle --mangle-ip-s 10.10.50.21 [web1]#service arptables save [web1]#service arptables start
web2
[web2]# arptables -I IN -d 10.10.50.100 -j DROP [web2]#arptables -A OUT -d 10.10.50.100 -j mangle --mangle-ip-s 10.10.50.22 [web2]#service arptables save [web2]#service arptables start
Finally we create second loopback interface and we create alias of virtual ip address where
web server will send queries.Same at both web servers.
# vi /etc/sysconfig/network-scripts/ifcfg-lo:0 DEVICE=lo:0 IPADDR=10.10.50.100 NETMASK=255.255.255.255 NETWORK=10.10.50.0 BROADCAST=10.10.50.255 ONBOOT=yes
Let’s start pusle service and check functinality.
#service pulse start #chkconfig pulse on
We chceck virtual ip on primary balancer.
[lba1]#ip adress show eth0 2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:0c:29:db:1c:a5 brd ff:ff:ff:ff:ff:ff inet 10.10.50.11/24 brd 10.0.2.255 scope global eth0 inet 10.10.50.100/24 brd 10.0.2.255 scope global secondary eth0:1 inet6 fe80::20c:29ff:fedb:1ca5/64 scope link valid_lft forever preferred_lft forever
For troubleshooting we can use command.
# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.2.100:80 rr -> 10.0.2.22:80 Route 1 0 0 -> 10.0.2.21:80 Route 1 0 0