• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to install and configure HAProxy 1.4.24 in CentOS 6

October 28, 2013 by Sharad Chhetri 2 Comments

In this topic we will learn how to install and configure HAProxy 1.4.24 in CentOS 6.
HAproxy is widely used Open Source tcp/http based loadbalancer.And many renowned company also using the HAProxy.Here in this tutorial we will install the latest stable HAProxy version 1.4.24 in CentOS 6.4.

We recommend to install latest stable version 1.4.24, read the below given release note.
haproxy 1.4.24

Follow the given below steps for HAProxy 1.4.24 installation in CentOS 6.4

Details:

LoadBalancer Server Name = HAProxy
No. of Webserver = 2 (webserver1 and webserver2)
HAProxy IP address = 192.241.190.251
webserver1 IP address = 192.168.122.101
webserver2 IP address = 192.168.122.102
server Health Check File name = healthcheck.txt

Step 1: Login as root and download the HAProxy tarball in Server

yum install wget gcc gcc-c++ autoconf automake make
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz

Step 2: Extract the tarball

tar -xvzf haproxy-1.4.24.tar.gz

Step 2: Now compile the HAProxy

cd haproxy-1.4.24

make TARGET=linux26

make install

Step 3: Create haproxy directory in /etc and its config file

mkdir -p /etc/haproxy

Now create a file called haproxy.cfg in /etc/haproxy

Note: In configuration file we have added two webserver named with webserver1 and webserver2.You can add two or more than two webserver in list. Replace the Servername and IP address as per your information.

vi /etc/haproxy/haproxy.cfg

global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        maxconn 5000
        chroot /var/lib/haproxy
        user haproxy
        group haproxy
        daemon

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        option redispatch
        retries 3
        maxconn 4000
        contimeout      8000
        clitimeout      80000
        srvtimeout      80000

listen LOADBAL  192.241.190.251:80
      mode http
      cookie LOADBAL  insert
      balance roundrobin
      option httpclose
      option forwardfor
      option httpchk HEAD /healthcheck.txt HTTP/1.0
      server webserver1 192.168.122.101:80 cookie webserver1 check
      server webserver2 192.168.122.102:80 cookie webserver2 check
      capture response header Location len 40

listen stats :4997
    mode http
    stats enable
    stats hide-version
    stats realm Haproxy Statistics
    stats uri /
    stats auth scloaduser:your_password
 

Step 3: Now login into both server[webserver1 and webserver2] and create a blank file in its webspace called healthcheck.txt (See the line having “option httpcheck” in configuration)

Here in this example we have two server webserver1 and webserver2.

(a) Login into both server as a root
(b) Our web application path is at /var/www/html/application_name
Hence we are creating a blank file in same path in both server respectively.

touch /var/www/html/application_name/healthcheck.txt

Step 4: Now start the haproxy service in Loadbalancer server a.k.a HAproxy server

haproxy -f /etc/haproxy/haproxy.conf

To stop the haproxy service,first get the pid of haproxy and kill it

ps -ef|grep haproxy

kill -9 pidof_haproxy

Step 5: To get the haproxy dashboard in configuration file below given lines were already added


listen stats 192.241.190.251:4997
    mode http
    stats enable
    stats hide-version
    stats realm Haproxy Statistics
    stats uri /
    stats auth scloaduser:your_password

As per above configuration.

listen stats 192.241.190.251:4997 means in ip address 192.241.190.251 port no. 4997 you can get the haproxy dashboard.
stats auth scloaduser:your_password here you have to mention your haproxy’s dashboard username and password.

To access the HAproxy dahsboard, open the webbrowser and in URL type

http://loadbalancer-ip-address:4997

In our eg. it is

http://192.241.190.251:4997

To enable haproxy logging. Read this post https://sharadchhetri.com/2013/10/16/how-to-enable-logging-of-haproxy-in-rsyslog/

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to enable logging of haproxy in rsyslog
  2. How to install and configure samba server in CentOS 6.3
  3. How to install and configure nagios nrpe in CentOS and Red Hat
  4. Install and configure Varnish Cache server on CentOS/RHEL 6.x
  5. Install and configure rsyslog Centralized logging server in CentOS 6.5
  6. Install and configure transparent squid proxy server : RHEL/CentOS 6.x
  7. How to configure FTP server in CentOS 6.3 – vsftpd server
  8. How to configure ethernet in CentOS 6 after installing in Virtual Box
  9. How to configure vsftpd server with virtual user mysql authentication in CentOS 6
  10. How to install and configure Secure FTP server in Ubuntu 12.04 LTS

Filed Under: Linux, Loadbalancer Tagged With: haproxy, loadbalancer

Reader Interactions

Comments

  1. Manoj says

    November 1, 2013 at 10:47 am

    Thanks dude!!

    Reply
    • sharad chhetri says

      November 2, 2013 at 2:03 am

      Welcome Manoj

      Reply

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

Run the script using nohup without hitting enter key two times

curl command to check the http status

linux release renew dhcp assigned ip address

How to hide php version information in header

How to configure ethernet in CentOS 6 after installing in Virtual Box

How to find when Operating system was installed in linux CentOS and Red Hat

Install libjpegtran by using yum command in CentOS 6.x

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy