Setting Up A High-Availability Load Balancer With HAProxy/Keepalived On Debian Lenny - Page 2
5 Setting Up keepalivedWe've just configured HAProxy 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 keepalived which we install like this: lb1/lb2: aptitude install keepalived To allow HAProxy to bind to the shared IP address, we add the following line to /etc/sysctl.conf: vi /etc/sysctl.conf
... and run: sysctl -p Next we must configure keepalived (this is done through the configuration file /etc/keepalived/keepalived.conf). I want lb1 to be the active (or master) load balancer, so we use this configuration on lb1: lb1: vi /etc/keepalived/keepalived.conf
(It is important that you use priority 101 in the above file - this makes lb1 the master!) Then we start keepalived on lb1: lb1: /etc/init.d/keepalived 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 Now we do almost the same on lb2. There's one small, but important difference - we use priority 100 instead of priority 101 in /etc/keepalived/keepalived.conf which makes lb2 the passive (slave or hot-standby) load balancer: lb2: vi /etc/keepalived/keepalived.conf
Then we start keepalived: lb2: /etc/init.d/keepalived start 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
6 Starting HAProxyNow we can start HAProxy: lb1/lb2: /etc/init.d/haproxy start
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 When lb1 comes up again, it will take over the master role again.
8 HAProxy StatisticsYou might have noticed that we have used the options stats enable and stats auth someuser:somepassword in the HAProxy configuration in chapter 4. This allow us to access (password-protected) HAProxy statistics under the URL http://192.168.0.99/haproxy?stats. This is how it looks: If you don't need the statistics, just comment out or remove the stats lines from the HAProxy configuration.
9 Links
|




Recent comments
1 day 8 hours ago
1 day 11 hours ago
1 day 12 hours ago
1 day 14 hours ago
1 day 15 hours ago
1 day 17 hours ago
1 day 18 hours ago
2 days 10 hours ago
2 days 11 hours ago
2 days 15 hours ago