In our previous post we have set up a HAProxy loadbalancer to balance the load of our web application between three webservers, here’s the diagram of the situation we have ended up with:
As we already concluded in the last post, there’s still a single point of failure in this setup. If the loadbalancer dies for some reason the whole site will be offline. In this post we will add a second loadbalancer and setup a virtual IP address shared between the loadbalancers. The setup will look like this:
So our setup now is: - Three webservers, WebServer1 (192.168.0.1), WebServer2 (192.168.0.2 ), and WebServer3 (192.168.0.3) each serving the application - The first load balancer (loadb01, ip: (192.168.0.100 )) - The second load balancer (loadb02, ip: (192.168.0.101 )), configure this in the same way as we configured the first one.
To setup the virtual IP address we will use keepalived
|1||**`loadb01$ ``sudo` `apt-get ``install` `keepalived`**|
Good, keepalived is now installed. Before we proceed with configuring keepalived itself, edit the following file:
|1||`loadb01$ ``sudo` `vi` `/etc/sysctl``.conf`|
And add this line to the end of the file:
This option is needed for applications (haproxy in this case) to be able to bind to non-local addresses (ip adresses which do not belong to an interface on the machine). To apply the setting, run the following command:
|1||`loadb01$ ``sudo` `sysctl -p`|
Now let’s add the configuration for keepalived, open the file:
|1||`loadb01$ ``sudo` `vi` `/etc/keepalived/keepalived``.conf`|
And add the following contents
|1||`loadb01$ ``/etc/init``.d``/keepalived` `start`|
Now the next step is to install and configure keepalived on our second loadbalancer aswell, redo the steps starting from apt-get install keepalived. In the configuration step for keepalived, be sure change these two settings:
|1 2||`state MASTER ``# set this to BACKUP on the other machine` `priority 101 ``# set this to 100 on the other machine`|
|1 2||`state BACKUP ` `priority 100 `|
That’s it! We have now configured a virtual IP shared between our two loadbalancers, you can try loading the haproxy statistic page on the virtual IP adddress and should get the statistics for loadb01, then switch off loadb01 and refresh, the virtual IP address will now be assigned to the second loadbalancer and you should see the statistics page for that.
If there’s anything else you’d like us to cover, or if you have any questions please leave a comment!