Installing HAProxy On FreeBSD

haproxy

HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing.

Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the Net.

Installing HAProxy

cd  /usr/ports/net/haproxy/
make install clean

HAproxy is now installed. now we need to setup conf file.

Edit file /usr/local/etc/haproxy.cfg

global
maxconn 4096 # Total Max Connections. This is dependent on ulimit
daemon
nbproc 4 # Number of processing cores. Dual Dual-core Opteron is 4 cores for example.

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

listen webfarm 63.123.123.100:80
    mode http
    balance roundrobin
    cookie SERVERID insert nocache indirect
    option forwardfor
    option httpchk HEAD /check.txt HTTP/1.0
    stats enable
    stats auth admin:password

    server TechNode1 63.123.123.101:80 cookie Server1 weight 20 check
    server TechNode2 63.123.123.102:80 cookie Server2 weight 10 check

In the above configuration we are using two web servers (TechNode1, TechNode2). On first Node we are setting weight (20) because Node1 is also mysql server so we dont want to receive more requests on that node.

The other node will receive more requests. The HAProxy will also handle user’s session so whenever any one goes down then HAProxy automatically shifts sessions on other node.

Make sure check.txt file must exist on both nodes.

Finally lets start it, and add it to start up.

echo 'haproxy_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/haproxy start

That’s all

Leave a Reply

Your email address will not be published. Required fields are marked *

*