Setup HAProxy Load Balancer on Ubuntu

01. installing haproxy on ubuntu machine
sudo apt-get install haproxy

02. Edit configurations file
sudo vi /etc/haproxy/haproxy.cfg

Add following text to file and save it

maxconn 4096
user haproxy
group haproxy
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
listen webcluster *:80
mode http
stats enable
stats auth us3r:passw0rd
balance roundrobin
option httpchk HEAD / HTTP/1.0
option forwardfor
cookie LSW_WEB insert
option httpclose
server web01 cookie LSW_WEB01 check
server web02 cookie LSW_WEB02 check
03. Setting startup parameter for HAProxy set enabled as 1 to start HAproxy
sudo vi /etc/default/haproxy

# Set ENABLED to 1 if you want the init script to start haproxy.

04. Start HAProxy form command line
sudo /etc/init.d/haproxy start

05. Restart HAProxy after any configuration change form command line
sudo /etc/init.d/haproxy restart

06. Start 2 ESB servers (Set HTTP port as 8280 and 8281) and with default configurations

07. Access Web user interface from browser
Type following url in browser and provide stat credentials you provided in configurations file(haproxy.cfg)

You will see following User interface.

08. Access ESB from browser or send requests to following url

Following Diagram shows you how this laod balancer works.

Big thanks to this blog author

Web Analytics