Posted by: kezhong | March 24, 2010

Setup a Linux loadbalancer with LVS and ldirectord

I had built a basic LVS as my last post Implementing Load Balance on CentOS 5.4, but it was not practical. Because once a real server goes down, the director will not be able to find and half users will get an error page. The ldirectord program attach the heartbeat package can solve this problem. It monitors the health of the real servers. When a real server is down, the ldirectord program will remove this real server from the IPVS routing table.

Install the ldirectord program on Linux Director
# yum install heartbeat*

Configure
# mkdir -p /etc/ha.d/conf
# cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf /etc/ha.d/conf

Modify the /etc/ha.d/conf/ldirectord.cf file with vi, the content of this file should be as below.
# Global Directives
checktimeout=3
checkinterval=1
autoreload=yes
logfile=”/var/log/ldirectord.log”
logfile=”local0″
quiescent=yes
# Sample for an http virtual service
virtual=192.168.26.200:80
real=192.168.26.211:80 gate
real=192.168.26.212:80 gate
service=http
scheduler=rr
protocol=tcp
checktype=negotiate
checkport=80
request=”index.html”

Delete the follow lines from the /etc/rc.local file.
ipvsadm -A -t 192.168.26.200:80 -s rr
ipvsadm -a -t 192.168.26.200:80 -r 192.168.26.211 -g
ipvsadm -a -t 192.168.26.200:80 -r 192.168.26.212 -g

Append “/usr/sbin/ldirectord start” to the end of the  /etc/rc.local file.

Start the ldirectord daemon
# ldirectord start
# ldirectord status
ldirectord for /etc/ha.d/conf/ldirectord.cf is running with pid: 3102

Test
Launch the web site http://192.168.26.200 through the web browser at another machine. Refresh the browser again and again, the different pages appeared. It worked well. Check the IPVS routing table on the Linux Director, the result is as below.
# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.26.200:http rr
-> 192.168.26.211:http Route 1 0 5
-> 192.168.26.212:http Route 1 0 5

Stop the web service on a real server(192.168.26.211).
# service httpd stop
Refresh the browser again and again, it only displayed the page of the second real server. Check the IPVS table.
# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.26.200:http rr
-> 192.168.26.211:http Route 0 0 0
-> 192.168.26.212:http Route 1 0 6


Responses

  1. […] a Linux loadbalancer with LVS and ldirectord in tunnelling way In my last post “Setup a Linux loadbalancer with LVS and ldirectord“, I used direct routing way. In this post, I’ll use the tunneling way. The main […]

  2. I have configured as explained above. but when i access the virtual IP, it hits the director and not the real servers. (in your case….when i access 192.168.26.200 it hits 192.168.26.201 and not 192.168.26.211 or 192.168.26.212) what seems to be the problem in my configuration?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: