This article will tells you how to set up an LVS cluster of load balanced virtual servers with Heartbeat and LVS cluster and Ldirectord On CentOS The load balancer sits between the user and two (or more) backend Apache web servers that have the same content.
Apache load balancing virtual servers with Heartbeat and LVS cluster/Ldirectord On CentOS.
Primary Note
In this article we will use the following 3 hosts/servers:
Virtual IP address (end users connect to this) : 10.10.1.42
Load Balancer: load1linuxpcfix.com, IP address: 10.10.1.41
Web Server 1: apache1.linuxpcfix.com, IP address: 10.10.1.44
Web Server 2: apache2.linuxpcfix.com, IP address: 10.10.1.45
Load Balancer Configuration
Install heartbeat,heartbeat-ldirector and ipvsadm RPM packages on your Load Balancer system (load1.linuxpcfix.com).
#chkconfig ldirectord off
#chkconfig heartbeat on
Enables packet forwarding
1 Enable IPVS On The Load Balancers
First we need to implement IPVS on our load balancers. IPVS (IP Virtual Server) implements transport-layer load balancing contained by the Linux kernel, so works as Layer-4 switching.
loadb1/loadb2:
#echo ip_vs_ftp >> /etc/modules
#echo ip_vs >> /etc/modules
#echo ip_vs_lblc >> /etc/modules
#echo ip_vs_lblcr >> /etc/modules
#echo ip_vs_lc >> /etc/modules
#echo ip_vs_nq >> /etc/modules
#echo ip_vs_rr >> /etc/modules
#echo ip_vs_sed >> /etc/modules
#echo ip_vs_sh >> /etc/modules
#echo ip_vs_wlc >> /etc/modules
#echo ip_vs_wrr >> /etc/modules
Then we do this:
loadb1/loadb2:
#modprobe ip_vs_ftp
#modprobe ip_vs
#modprobe ip_vs_lblc
#modprobe ip_vs_lblcr
#modprobe ip_vs_lc
#modprobe ip_vs_nq
#modprobe ip_vs_rr
#modprobe ip_vs_sed
#modprobe ip_vs_sh
#modprobe ip_vs_wlc
#modprobe ip_vs_wrr
Load Balancer Secondary Ethernet Configuration
BOOTPROTO=none
ONBOOT=yes
HWADDR=d8:d3:85:e3:9e:ca
NETMASK=255.255.254.0
IPADDR=10.10.1.42
TYPE=Ethernet
Configure LOAD balancer
Configure heartbeat on your Load Balancer system.
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 10
bcast eth0
mcast eth0 225.0.0.1 694 1 0
auto_failback on
respawn hacluster /usr/lib/heartbeat/ipfail
node load1.linuxpcfix.com
Configuring ldirectord
Configure ldirectord on your Load Balancer system
checkinterval=2
autoreload=yes
logfile=”/var/log/ldirectord.log”
quiescent=yes
virtual=10.10.1.42:80
real=10.10.1.44:80 gate
real=10.10.1.45:80 gate
fallback=127.0.0.1:80 gate
service=http
request=”/check.txt”
httpmethod=GET
receive=” Cluster Working Fine ”
persistent=100
scheduler=rr
protocol=tcp
checktype=negotiate
Load1.linuxpcfix.com ldirectord::ldirectord.cf LVSSyncDaemonSwap::master IPaddr2:: 10.10.1.42/23/eth0/10.10.1.255
Note it should be single line
3 md5 Ultramonkey!
Now check if load balancer work as expected:
The load balancer should list the virtual IP address (10.10.1.42):
link/ether d8:d3:85:e3:9e:ca brd ff:ff:ff:ff:ff:ff
inet 10.10.1.41/23 brd 103.10.235.255 scope global eth0
inet 10.10.1.42/23 brd 103.10.235.255 scope global secondary eth0:0
inet6 fe80::dad3:85ff:fee3:9eca/64 scope link
valid_lft forever preferred_lft forever
Cluster Nodes Configurations (Apache Real Web Servers Configuration)
On both web servers apache1 and apache2, apache should be running a common service file (for purpose of get checked by ldirectord).
#echo “Cluster Working Fine” > /var/www/html/check.txt
#service httpd start
#chkconfig httpd on
#yum install iproute
Now, Create a loopback interface on each web server, so it doesn’t communicate with your network gateway/router directly.
It should look similar to this:
IPADDR=10.10.1.42
NETMASK=255.255.255.255
NAME=loopback
BOOTPROTO=none
TYPE=Ethernet
ONPARENT=yes
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
#ifup lo:0
Final Test
Use “ipvsadm” to list down current statistics of ldirectord. Make sure that both real servers IPs
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.10.1.42:80 rr persistent 100
-> 10.10.1.45:80 Route 1 0 0
-> 10.10.1.44:80 Route 0 0 0
Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes
-> RemoteAddress:Port
TCP 10.10.1.42:80 23 139 0 13185 0
-> 10.10.1.45:80 18 107 0 9920 0
-> 10.10.1.44:80 5 32 0 3265 0
Prot LocalAddress:Port CPS InPPS OutPPS InBPS OutBPS
-> RemoteAddress:Port
TCP 10.10.1.42:80 0 0 0 0 0
-> 10.10.1.45:80 0 0 0 0 0
-> 10.10.1.44:80 0 0 0 0 0
Great! You have successfully implement Apache load balancer.
About IPVS
IPVS (IP Virtual Server) implements transport-layer load balancing inside the Linux kernel, so called Layer-4 switching. IPVS running on a host acts as a load balancer at the front of a cluster of real servers, it can direct requests for TCP/UDP based services to the real servers, and makes services of the real servers to appear as a virtual service on a single IP address.