Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Managing Web Traffic Load With HaProxy  (Read 1388 times)

0 Members and 1 Guest are viewing this topic.

joseletk

  • Guest
Managing Web Traffic Load With HaProxy
« on: July 14, 2018, 12:58:09 pm »
HaProxy is used to decrease the web application server load. It also used to decrease the database server load. It can handle a lot of traffic. Similar to nginx, but nginx can’t handle the ip/tcp traffic it is used only for web traffic. It use low memory to handle large number of concurrent request.

Installation

We will install latest version of HaProxy ( 1.5.1 ) on our ubuntu server,  for HaProxy latest version installation we will use pp:vbernat/haproxy-1.5 repository .

Code: [Select]
#add-get-repository –y pp:vbernat/haproxy-1.5

#apt-get update

#apt-get install  haproxy –y

If add-get-repository not found than install software-properties-common package.

HaProxy Configuration

Before going to configure we will need to know about some options.

Fronted :- HaProxy listen all connection here

Backend: -HaProxy forward all incoming request

Stats :- Show status of all connected load balancer nodes .

Algorithms Of Load Balancing

HaProxy use round-robin algorithm by default.

Roundrobin:-  All coming request will distribute amongst all connected nodes  one buy one. For session based application you will need configure sticky session. Using sticky session HaProxy will send client request on same server . So you will need to define cookie COOKIES –NAME prefix into back-end directive.

Static-rr :- Work same as round-robin but we can’t adjust server  weights. It is used for long running connection .

Leastconn :- HaProxy will send the connection on node which have lowest connection.

Other one is uri but it is not used more.

Configuration Example

Code: [Select]
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 2
timeout http-request 10
timeout queue 75400
timeout connect 75400
timeout client 75400
timeout server 75400
timeout http-keep-alive 25
timeout check 15
maxconn 40000
 
# frontend LB
bind 192.168.0.5:80
reqadd X-Forwarded-Proto:\ http
default_backend LB
#
backend LB 192.168.0.5:80
mode http
stats enable
stats hide-version
stats uri /stats
stats realm Haproxy\ Statistics
stats auth haproxy:redhat # User and Password for HaProxy status page. balance
roundrobin # Blancing algorithm.
option httpchk
option httpclose
option forwardfor
cookie SESSION insert
server app1-srv 192.168.0.6:80 cookie app1-srv check # backend server.
server app2-srv 192.168.0.7:80 cookie app2-srv check # backend server.
server app3-srv 192.168.0.8:80 check backup # backup server if app1 and app2 down.

Save and exit.

Now restart HaProxy service.

Code: [Select]
# service haproxy restart

# chkconfig haproxy on

HaProxy server is ready to handle all incoming traffic.We can check the HaProxy nodes status with it’s status page.

Type http://ipa-ddress/stats in your browser and type the credential.User : ha proxy , Password : admin@123.

Make sure port 80 should be open in firewall.
======================================================================