Configure HTTP Server load balancing with HAProxy in CentOS

In here I’m going to show you how to configure HTTP server load balancing with the HAProxy server.
HAProxy is an open source high availability and high responsive solution with server load balancing mechanism and proxy server. This would be helpful to maximise server availability and prevent single point of failure of the any kind of running applications on servers.
This tutorial is guiding you through the steps to be followed for http server load balancing using HAProxy. Let’s take an example for configuring HAProxy load balancing with some http server instances.
HAProxy Server
  • Server IP : 10.101.5.3
  • OS : Cent OS release 6.5
 
HTTP-Server-01
  • Server IP : 10.101.5.4
  • OS : Cent OS release 6.5
 
HTTP-Server-02
  • Server IP : 10.101.5.4
  • OS : Cent OS release 6.5
 
HTTP-Server-03

  • Server IP : 10.101.5.4
  • OS : Cent OS release 6.5
 
Please refer the given image below for more details about the example have been taken.
HAProxy
Install and configure HAProxy server on HAProxy server (10.101.5.3) using apt-get install option. Use updated and relevant HAProxy repository for Cent OS.
# yum install haproxy
Afere installing HAProxy you can configure it to use HTTP server load balancing. In order to achieve that you have to add some more configuration for the .cfg file on HAProxy server.
# vim /etc/haproxy/haproxy.cfg
In this configuration file you need to add the all http servers available, and their IP address and specific names for them.
global
     user haproxy
     group haproxy
     nbproc 1
defaults
     mode http
     timeout connect 5s
     timeout client 25s
     timeout server 25s
frontend ft_web
     bind 10.101.5.3:8080 name http
     default_backend bk_web
backend bk_web
     stats enable
     stats uri /haproxy?stats
     stats realm Haproxy\ Statistics
     stats auth haproxy:stats
     balance roundrobin
     server web-server-01 10.101.5.4:8080
     server web-server-02 10.101.5.5:8080
     server web-server-03 10.101.5.6:8080
There are four main sections of the configuration file, those are global, defaults, fronted, & backend. A global section for setting the main haproxy settings, like user, user group. Default section to set the mode of server type, set timeouts for connection, client, server. The front-end section is to bind the IP of haproxy server. balance round robin is the method that is used for load balancing.
In HAProxy, there is a special dashboard to testing the load-balancing is working as expected. The dashboard configurations are available under the backend section. According to the above configuration, dashboard configuration is given below.
     stats enable
     stats uri /haproxy?stats
     stats realm Haproxy\ Statistics
     stats auth haproxy:stats
Screen Shot 2015-02-11 at 6.21.37 PM
T
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s