Load Balancer with LVS + heartbeat + ldirectord + IIS in CentOS 5

Posted: February 5, 2013 in Linux
Tags: , ,

Update: ldirectord has been removed from CentOS 6 default repository, and replaced it with Piranha.

First we need install heartbeat, heartbeat-ldirectord and ipvsadm to the load balancer nodes: active and standby.

$yum install heartbeat heartbeat-ldirectord ipvsadm

Next set ip4 package forwarding in /etc/sysctl.conf

set net.ipv4.ip_forward=1

To enable ip forwarding for ipv6: $echo 1 >/proc/sys/net/ipv6/ip_forward

Execute $sysctl -p to load the new change.

We need create virtual IP for each web server cluster. To create the virtual IP, assuming you active network card is eth0

$ cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
$ vi cp /etc/sysconfig/network-scripts/ifcfg-eth0:0

change device to eth0:0, remove the gateway, set ip address to the virtual ip

$ service network restart

Next, we need config heartbeat and ldirectord

1. Config authkeys

$ cp /usr/share/doc/heartbeat-<the heartbeat version>/authkeys /etc/ha.d/
 $ vi /etc/ha.d/authkeys
 uncomment auth line, set the auth value and uncomment the corresponding encrypt method line

2. Config ha.cf

$ cp /usr/share/doc/heartbeat-<the heartbeat version>/ha.cf /etc/ha.d/
$ vi /etc/ha.d/ha.cf
find bcast line, uncomment it; find the node line, add the loadbalancer hostname. The hostname must be the same as the return value when you run $ uname -n in the load balancer.

3. Config haresources

$ cp /usr/share/doc/heartbeat-<the heartbeat version>/haresources /etc/ha.d/
$ vi /etc/ha.d/haresources
append this line: <loadbalancer hostname> IPaddr::192.168.20.124/24/eth0/192.168.20.255 ldirectord::www

4. Config ldirectord

$ cp /usr/share/doc/heartbeat-ldirectord-2.1.3/ldirectord.cf /etc/ha.d/
$ vi /etc/ha.d/ldirectord.cf

this is config file for core load balancing. add/remove real server, set persistent, timeout and check page.

More information can be found in http://manpages.ubuntu.com/manpages/karmic/man8/ldirectord.8.html

Next config IIS server.

1. Install "Microsoft Loopback Adapter" by using "Add Hardware" icon in Control Panel.
2. Set IP to virtual ip
3. Set Subnet Mask to 255.255.255.0
4. Don't Set Gateway or DNS

The above steps are enough for windows server 2003, but for 2000 and 2008, we need a few more steps.

2008, run the following commands in command line

netsh interface ipv4 set interface "net adapter name" weakhostreceive=enabled
netsh interface ipv4 set interface "loopback adapter name" weakhostreceive=enabled
netsh interface ipv4 set interface "loopback adapter name" weakhostsend=enabled

2000, we need change the interface metric to 254. run the following commands in command line

route print: this will return all network interfaces and active route, find the loopback one
route delete 192.168.20.0 mask 255.255.255.0 192.168.20.133: this will delete the one
route add 192.168.20.0 mask 255.255.255.0 192.168.20.133 metric 254 if 0x2000004: 0x2000004 is the interface id for loopback adapter

To view the loadbalancer status: $ ipvsadm -Ln

To add/remove real web server to be balanced: vi ldirectord.cf

Remember to allow 80(http) or 443(https) port in iptables.

Credit: http://www.howtoforge.com/set-up-a-loadbalanced-ha-apache-cluster-ubuntu8.04-p4

Advertisements
Comments
  1. […] Background: We have a load balancer powered by LVS + ldirectord. You can find the guide on how to set it up by your own Here. […]

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