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 :)

        log   local0
        log   local1 notice
        maxconn 4096
        chroot /var/lib/haproxy
        user haproxy
        group haproxy

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

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

listen smtp :25
        mode tcp
        option tcplog
        balance roundrobin

        server smtp check
        server smtp1 check
        server smtp2 check
        server smtp3 check

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


Nick Bettison ©