haproxy - Basic TCP Proxy

haproxy is a high performance TCP/HTTP load balancer. I’ve been using it for years now and have never experienced any problems with it. There are loads more configurable options but this simple config below will get you started.

The below configuration is for haproxy 1.5. I have not tested it with anything newer. Version 1.5 is what comes with Debian 8 (jessie).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
global
user haproxy
group haproxy
daemon
maxconn 4096
defaults
mode tcp
balance leastconn
timeout client 30000ms
timeout server 30000ms
timeout connect 3000ms
retries 3
frontend fr_server1
bind 0.0.0.0:<port>
default_backend bk_server1
backend bk_server1
server srv1 <ip>:<port> maxconn 2048

To use this configuration, execute the following command:

haproxy -f <config path>

This will run haproxy in the background as a daemon.