Load Balancing with HAproxy
Regardless of the option you choose, using some sort of load balancing solution in your infrastructure is highly recommended. However, if you need a solution that is cost-effective up front, you can setup an open source load balancing solution such as HAproxy.
HAProxy is an open source load balancer that functions as a fast proxy server and provides high availability for TCP and HTTP-based applications. HAproxy is easy to install on a SmartMachine and includes support for SMF. Although not installed on a SmartMachine by default, HAproxy is available as a package in pkgsrc on any SmartMachine you provision. Once installed, you will need to configure HAproxy in various ways to fit your environment.
In this topic:
To install HAproxy, run this command:
Installation of HAproxy includes an SMF manifest that supports the enabling, disabling, and restarting of the HAproxy persistent daemon process. You can enable that process by running:
|You can learn more about using SMF in the Joyent Public Cloud here.|
The default location for HAproxy is:
The default location for the HAproxy configuration file is:
There are two specific components of an HAproxy configuration that you will need to address: configuration properties and the load balancing algorithms your configuration will use.
HAproxy is installed with a configuration file that is populated with default values for various parameters. Before you start using HAproxy, you will need to set these parameters to values that support your environment. HAproxy configuration parameters are broken down into three primary components:
- The arguments from the command-line, which always take precedence
- The global section, which sets process-wide parameters
- The proxies sections, which you can set as defaults, listen,
frontend and backend.
Below are some notable parameters.
|mode||tcp, http, or health|| This parameters sets the mode for the proxy instance. Use one of the three following values with this parameter.
|maxconn||number||Fix the maximum number of concurrent connections on a frontend. Consumes about 17 kB of RAM per established connection. That means that a medium system equipped with 1GB of RAM can withstand around 40000-50000 concurrent connections if properly tuned.|
|retries||number||Set the number of retries to perform on a server after a connection failure.|
|option||forwardfor, httplog, tcplog, logasap, dontlognull|| These are options you can set in your configuration. You can set any number of these options in your configuration by including the option parameter multiple times.
Proxy sections are defined in the following way:
|defaults <name>|| Sets default parameters for all sections following its declaration.
| frontend <name>
|| Describes a set of listening sockets accepting client connections.
| backend <name>
|| Describes a set of servers to which the proxy will connect to forwarded incoming connections.
| listen <name>
|| Defines a complete proxy with its frontend and backend parts combined in one section.