<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>LINICKX.com</title><link>https://www.linickx.com/</link><description></description><lastBuildDate>Fri, 07 Nov 2008 19:38:00 +0000</lastBuildDate><item><title>Load balance anything with HAProxy</title><link>https://www.linickx.com/load-balance-anything-with-haproxy</link><description>&lt;p&gt;Recently I wanted to load balance a TCP service i.e. &lt;strong&gt;&lt;u&gt;not&lt;/u&gt;&lt;/strong&gt;
http, in the past I've used &lt;a href="http://www.ultramonkey.org"&gt;ultramonkey&lt;/a&gt;
but there doesn't seem to be any maintained Redhat/Centos packages.&lt;/p&gt;
&lt;p&gt;After some googling I found that &lt;a href="http://haproxy.1wt.eu/"&gt;haproxy&lt;/a&gt; can
balance non-http services but examples of non-http configurations are
few and far between, &lt;a href="http://strugglers.net/~andy/blog/2007/04/29/haproxy-bafflement/"&gt;this blog
post&lt;/a&gt;
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
(&lt;em&gt;username = me, password = password&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;By changing the port numbers from 25 (&lt;em&gt;SMTP&lt;/em&gt;) you can effectively load
balance any TCP app :)&lt;/p&gt;
&lt;!--more--&gt;

&lt;pre&gt;&lt;code&gt;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
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Redhat/Centos rpm packages of haproxy are avilable from &lt;a href="http://fedoraproject.org/wiki/EPEL"&gt;Fedora's EPEL
Project&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Fri, 07 Nov 2008 19:38:00 +0000</pubDate><guid isPermaLink="false">tag:www.linickx.com,2008-11-07:load-balance-anything-with-haproxy</guid><category>haproxy</category><category>Linux</category><category>loadbalance</category></item></channel></rss>