Τετάρτη 31 Ιανουαρίου 2018

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. 

HAProxy Server


  • Server IP : 10.2.1.60
  • OS : Cent OS release 7.3
HTTP-Server-01
  • Server IP : 10..2.1.61
  • OS : Cent OS release 7.3

 HTTP-Server-02

  • Server IP : 10.2.1.62
  • OS : Cent OS release 7.3
Please refer the given image below for more details about the example have been taken.




 1) Install

Install and configure HAProxy on Centos server (10.2.1.60) 

# yum install haproxy
# haproxy -v

After 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.
# cp /etc/haproxy/haproxy.cfg haproxy.cfg.bak
# rm /etc/haproxy/haproxy.cfg
# vi /etc/haproxy/haproxy.cfg 

Add the following and save the file


       global
    log /dev/log local0
    log /dev/log local1 notice
    chroot /var/lib/haproxy
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

  defaults
    log global
    mode http
    option httplog
    option dontlognull
    timeout connect 5000
    timeout client 50000
    timeout server 50000

 frontend http_front
    bind *:80
    stats uri /haproxy?stats
    default_backend http_back

 backend http_back
    balance roundrobin
    server web1 10.2.1.61:80 check
    server web2 10.2.1.62:80 check

  
Then start HAProxy: 
# systemctl start  haproxy.service
# systemctl enable haproxy.service
# chkconfig haproxy on


2) Testing HAProxy
With  the HAProxy configured and running, open your load balancer server’s public IP in a web browser and check that you get connected to your backend correctly. The parameter stats uri in the configuration enables the statistics page at the defined address.
 
URL: http://10.2.1.60/haproxy?stats
 
When you load the statistics page and all of your servers are listed
in green your configuration was successful.