Blog |Follow Nick on Twitter| About
 

Recently I wanted to load balance a TCP service i.e. not http, in the past I've used ultramonkey but there doesn't seem to be any maintained Redhat/Centos packages.

After some googling I found that haproxy can balance non-http services but examples of non-http configurations are few and far between, this blog post lead me to my solution, so after the jump I have a haproxy.cfg which will load balance smtp round-robin style across 4 servers, you also get a webstats interface listening on http://IP:8080/haproxy?stats (username = me, password = password).

By changing the port numbers from 25 (SMTP) you can effectively load balance any TCP app :)

global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        maxconn 4096
        chroot /var/lib/haproxy
        user haproxy
        group haproxy
        daemon
        #debug
        #quiet

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        option redispatch
        retries 3
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen stats :8080
        balance
        mode http
        stats enable
        stats auth me:password


listen smtp :25
        mode tcp
        option tcplog
        balance roundrobin

        server smtp 192.168.0.1:25 check
        server smtp1 192.168.0.2:25 check
        server smtp2 192.168.0.3:25 check
        server smtp3 192.168.0.4:25 check

Redhat/Centos rpm packages of haproxy are avilable from Fedora's EPEL Project

rgds,

Nick

 
Nick Bettison ©