Setting Up A High-Availability Load Balancer (With Failover and Session Support) With Perlbal/Heartbeat On Debian Etch - Page 2
5 Setting Up HeartbeatWe've just configured Perlbal to listen on the virtual IP address 192.168.0.99, but someone has to tell lb1 and lb2 that they should listen on that IP address. This is done by heartbeat which we install like this: lb1/lb2: apt-get install heartbeat To allow Perlbal to bind to the shared IP address, we add the following line to /etc/sysctl.conf: vi /etc/sysctl.conf
... and run: sysctl -p Now we have to create three configuration files for heartbeat, /etc/ha.d/authkeys, /etc/ha.d/ha.cf, and /etc/ha.d/haresources. /etc/ha.d/authkeys and /etc/ha.d/haresources must be identical on lb1 and lb2, and /etc/ha.d/ha.cf differs by just one line! lb1/lb2: vi /etc/ha.d/authkeys
somerandomstring is a password which the two heartbeat daemons on lb1 and lb2 use to authenticate against each other. Use your own string here. You have the choice between three authentication mechanisms. I use md5 as it is the most secure one. /etc/ha.d/authkeys should be readable by root only, therefore we do this: lb1/lb2: chmod 600 /etc/ha.d/authkeys lb1: vi /etc/ha.d/ha.cf
Important: As nodenames we must use the output of uname -n on lb1 and lb2. The udpport, bcast, mcast, and ucast options specify how the two heartbeat nodes communicate with each other to find out if the other node is still alive. You can leave the udpport, bcast, and mcast lines as shown above, but in the ucast line it's important that you specify the IP address of the other heartbeat node; in this case it's 192.168.0.101 (lb2.example.com). On lb2 the file looks pretty much the same, except that the ucast line holds the IP address of lb1: lb2: vi /etc/ha.d/ha.cf
lb1/lb2: vi /etc/ha.d/haresources
The first word is the output of uname -n on lb1, no matter if you create the file on lb1 or lb2! It is followed by our virtual IP address (192.168.0.99 in our example). Finally we start heartbeat on both load balancers: lb1/lb2: /etc/init.d/heartbeat start Then run: lb1: ip addr sh eth0 ... and you should find that lb1 is now listening on the shared IP address, too: lb1:~# ip addr sh eth0 You can check this again by running: ifconfig lb1:~# ifconfig As lb2 is the passive load balancer, it should not be listening on the virtual IP address as long as lb1 is up. We can check that with: lb2: ip addr sh eth0 The output should look like this: lb2:~# ip addr sh eth0 The output of ifconfig shouldn't display the virtual IP address either: lb2:~# ifconfig
6 Starting PerlbalNow we can start Perlbal: lb1/lb2: perlbal --daemon Of course, you don't want to start Perlbal manually each time you boot the load balancers. Therefore we open /etc/rc.local... vi /etc/rc.local ... and add the line /usr/local/bin/perlbal --daemon to it (right before the exit 0 line):
This will make Perlbal start automatically whenever you boot the load balancers. (To stop Perlbal, run killall perlbal )
7 TestingOur high-availability load balancer is now up and running. You can now make HTTP requests to the virtual IP address 192.168.0.99 (or to any domain/hostname that is pointing to the virtual IP address), and you should get content from the backend web servers. You can test its high-availability/failover capabilities by switching off one backend web server - the load balancer should then redirect all requests to the remaining backend web server. Afterwards, switch off the active load balancer (lb1) - lb2 should take over immediately. You can check that by running: lb2: ip addr sh eth0 You should now see the virtual IP address in the output on lb2: lb2:~# ip addr sh eth0 The same goes for the output of ifconfig When lb1 comes up again, it will take over the master role again.
8 Virtual Host Support In PerlbalPerlbal suppports virtual hosts. Let's assume we want requests for *.site.com to be served by the hosts with the IP addresses 192.168.0.102 and 192.168.0.103, and requests for *.example.com by the hosts 192.168.0.104 and 192.168.0.105. This is how /etc/perlbal/perlbal.conf would look: vi /etc/perlbal/perlbal.conf
9 Links
|
Join the discussion.
www.seamlessenterprise.com
IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com
Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com
Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com





print: 
Recent comments
2 hours 53 min ago
4 hours 35 min ago
7 hours 1 min ago
7 hours 7 min ago
11 hours 41 min ago
13 hours 42 min ago
17 hours 5 min ago
19 hours 12 min ago
19 hours 23 min ago
21 hours 49 min ago