Load Balancing with HAProxy
Configuring HAproxy as a SwiftStack Load Balancer
To illustrate how a SwiftStack cluster can be configured with an external load balancer, such as HAProxy, let’s walk through a step-by-step example of how to configure a SwiftStack cluster in two tiers: one proxy tier and one storage tier. The chart below shows how it could be set up.Sample Network Topology
In a SwiftStack cluster, you can run everything on one flat network, but it is generally better to separate external and internal traffic in the cluster. The following is an example of a network topology:
● The ‘Outward-facing’ network is the network which handles incoming traffic.
Load Balancing with HAProxy
Network Schema
Description Subnet Netmask
Outward-facing 192.168.50.0 /24
Cluster-facing 192.168.51.0 /24
IP Address Assignments
For this example we will be using two (2) proxy nodes and three (3) storage nodes. Node Name Outward IP Address Cluster IP Address
proxy1 192.168.50.11 192.168.51.11 proxy2 192.168.50.12 192.168.51.12 storage1 192.168.51.101 192.168.51.101 storage2 192.168.51.102 192.168.51.102 storage3 192.168.51.103 192.168.51.103
Load Balancing
SwiftStack includes a load balancer that can be used with very little configuration. The SwiftStack load balancer is based on the LVS open source project. The SwiftStack load balancer binds to a single node and routes requests to each of the other SwiftStack proxy nodes.
With an external load balancer any load balancing method may be used, such as simple round robin DNS or a layer 4 or layer 7 load balancer. The type of load balancing you chose depends on your use-case and what your cluster workload will look like. Selecting and setting up the load balancing solution is therefore up to you. SwiftStack has worked with customers who have used everything from round robin DNS using BIND, HAProxy and other open source solutions, as well as commercial equipment from companies like f5 and A10.
HAProxy
Load Balancing with HAProxy
HAProxy implements an event-driven, single-process model which enables support for very high number of simultaneous connections at very high speeds.
Installing HAProxy
The installation examples below are for Ubuntu 12.04 LTS Server, but should be similar on other Linux distributions. (For CentOS and Red Hat, you might need to enable the EPEL repositories.)
To install HAProxy, do the following: $ sudo aptitude install haproxy
That’s it. Once installed you need to configure HAProxy to start on boot. You can do that by updating the /etc/default/haproxy file by modifying “enabled” from 0 to 1, as follows:
# Set ENABLED to 1 if you want the init script to start haproxy. ENABLED=1
Configuring HAProxy for a SwiftStack Cluster
If you are setting up a cluster with an external load balancer, such as HAProxy, you will need to set up your load balancer to divide the load between your proxy nodes.
Using the network topology example provided above, if you have selected 192.168.50.0/24 as your ‘Outward-facing’ network, you need to set up your load balancer to include the IP
addresses of the proxy nodes in its load balancing pool. You will also need to assign the load balancer a virtual IP (VIP) on which it will respond. Here we will use 192.168.50.10 for the VIP and assuming we are using standard HTTP on port 80. So, for this example, the IP addresses used would be:
● 192.168.50.10 (load balancer IP)
● 192.168.50.11 (proxy1, included in pool) ● 192.168.50.12 (proxy2, included in pool)
To configure the external load balancer to pull failing nodes out of the load balancing pool, configure the load balancer to use the proxy node’s health check URL. The Swift health check URL is simply: /healthcheck
Load Balancing with HAProxy
$ sudo mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.orig Create the new, Swift-specific HAProxy configuration file:
$ sudo vi /etc/haproxy/haproxy.cfg … and make it look as follows:
global maxconn 4096 user haproxy group haproxy daemon defaults log global mode http option httplog option dontlognull retries 3 option redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 listen webcluster 192.168.50.10:80 mode http stats enable
stats auth username:password balance roundrobin
option httpchk HEAD /healthcheck HTTP/1.0 option forwardfor
option httpclose
server proxy1 192.168.50.11:80 weight 5 check inter 2000 server proxy2 192.168.50.12:80 weight 5 check inter 2000 Lastly, you need to restart HAProxy to make it use the new configuration: $ sudo service haproxy restart
In your HAProxy configuration file, you have two “stats” statements, one with “enable” and one with “auth username:password.” This statement enables the HAProxy stats web page.
Load Balancing with HAProxy
http://192.168.50.10/haproxy?stats
Your credentials to log in to the HAProxy stats page will be: ● Username: username
● Password: password
You can of course change any of the settings in the configuration file as you see fit, including the credentials to the stats page.
Configuring SwiftStack to Use An External Load Balancer
Now that you’ve got HAProxy installed and running, you also need to make sure that your SwiftStack cluster is configured to use an external load balancer. To do so, go to the “Configure Cluster” page on https://platform.swiftstack.com.
Ensure you have the following settings:
Use SwiftStack Load Balancer: unchecked
Cluster API IP Address: 192.168.50.10 (your HAProxy IP address)
Cluster API Hostname: <blank or the FQDN of your cluster>
If you need to make changes to your cluster configuration (as above), to activate your changes, you need to: