close x

How to create a High Availability load balancer on SmartCloud Enterprise (1/2)

Hello guys,

The purpose of this post is create a high availability load balancer for http traffic (on Red Hat)), it should be the same proccess with a few changes for other types of traffic. The following image is the structure of the



We should follow all the steps in both servers. The only difference between them is in conf file of Keepalived where we must set backup or master.

1.- Install HAproxy and Keepalive.

rpm -ivh
yum -y install haproxy keepalived
2.- Configure Keepalived

mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
nano /etc/keepalived/keepalived.conf
vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script “killall -0 haproxy” # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
} vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 100 # 101 on master, 100 on backup
virtual_ipaddress {
ip_virtual #change for the virtual IP
track_script {
3.-Now we need to configure the system to allow HAProxy to access shared virtual IP addresses. First make a backup of the sysctl.conf file:

nano /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
4.- Let’s check we are doing well:

service keepalived start
ip addr sh eth0
eth0: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff inet xx.xx.xx.xx/xx brd xx.xx.xx.xx scope global eth0 inet xx.xx.xx.xx/xx scope global eth0 inet6 xxxx::xxx:xxxx:xxx:xxxx/xx scope link valid_lft forever preferred_lft forever
5.- Configure HAproxy.

mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
nano /etc/haproxy/haproxy.cfg

log local0
log local1 notice
chroot /var/lib/haproxy

pidfile /var/run/

maxconn 4096

user haproxy

group haproxy


stats socket /var/lib/haproxy/stats


mode http

log global

option httplog

option dontlognull

option http-server-close

option forwardfor except

option redispatch

retries 3

timeout http-request 10s

timeout queue 1m

timeout connect 10s

timeout client 1m

timeout server 1m

timeout http-keep-alive 10s

timeout check 10s

maxconn 3000

listen xx.xx.xx.xx:80

mode http

stats enable

stats auth user:password #We should set an user and password in order to see the stats

balance roundrobin

cookie JSESSIONID prefix

option httpclose

option forwardfor

option httpchk HEAD /check.txt HTTP/1.0 #We should create this field in the Rootdirectory of the web server in each web server.

server webA xx.xx.xx.xx:80 cookie A check

server webB xx.xx.xx.xx:80 cookie B check
6.- Set up the start-up

chkconfig haproxy on
chkconfig keepalived on
service haproxy start
7.- Modify webservers conf. Comment the LogFormat line in httpd.conf and add the new one.

nano /usr/local/apache2/conf/httpd.conf
#LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined LogFormat “%{X-Forwarded-For}i %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
Comment all the CustomLog lines and the following lines, in the virtual host definition:

SetEnvIf Request_URI “^/check\.txt$” dontlog CustomLog /var/log/apache2/access.log combined env=!dontlog
Create in the rootdirectory the file check.txt

touch /usr/local/apache2/htdocs/check.txt
service httpd restart

I hope it will be usefull for you.






Cloud Computing0 comments

Leave a Reply