Saturday, 23 February 2019

Chapter 1 - High Availability Proxy Servers


High Availability Proxy Servers

For premium DevOps and AWS Courses: https://imojo.in/2cox7em
  1. AWS with the project 
  2. DevOps Real-Time 
  3. DevOps with the project 
  4. AWS Real-Time
  5. Linux Admin






Definition
HAProxy stands for High Availability proxy. HAProxy or High Availability Proxy is TCP and HTTP load balancer and proxy server software. It is a Free and open-source application written in C programming Language. HAProxy application is used as TCP/HTTP Load Balancer and for proxy Solutions. The most common use of the HAProxy application is to distribute the workload across multiple servers e.g., web server, database server, etc thus improving the overall performance and reliability of server environment.



Load Balancer:
HA Proxy: can do health checks, uses load balancing algorithms, sticky session,

Nginx:  Brainless (just forward request)

Architecture



HAProxy Environment Setup
HAProxy Server:
                                 IP Address:  192.168.56.201

                                 Hostname:  HAserver

HAProxy Client:

                                IP Address:  192.168.56.202 , 192.168.56.206
                              
                                Hostname:  HAclient1, HAclient2

Installing Apache on Client Machines


#yum install httpd

verify anyone of the server whether Apache is running by accessing it via IP address in browser.

http://192.168.56.212

Installing HAProxy Server


To install HAProxy on RHEL/CentOS/Fedora run the following command.

#yum install haproxy


Enabling Logging feature and Configure HAProxy


Enable logging feature in HAProxy for future debugging. Open the main HAProxy configuration file ‘/etc/haproxy/haproxy.cfg‘

# mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.org
#vi /etc/haproxy/haproxy.cfg

# create new
 global
      # for logging section
    log         127.0.0.1 local2 info
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
      # max per-process number of connections
    maxconn     256
      # process' user and group
    user        haproxy
    group       haproxy
      # makes the process fork into background
    daemon

defaults
      # running mode
    mode               http
      # use global settings
    log                global
      # get HTTP request log
    option             httplog
      # timeout if backends do not reply
    timeout connect    10s
      # timeout on client side
    timeout client     30s
      # timeout on server side
    timeout server     30s

# define frontend ( set any name for "http-in" section )
frontend http-in
      # listen 80
    bind *:80
      # set default backend
    default_backend    backend_servers
      # send X-Forwarded-For header
    option             forwardfor

# define backend
backend backend_servers
      # balance with roundrobin
    balance            roundrobin
      # define backend servers
    server             client2 192.168.56.202:80 check
    server             client4 192.168.56.206:80 check



Configure HAProxy Logs



Configure Rsyslog to get logs for HAProxy
#vi /etc/rsyslog.conf


# line 15,16: uncomment, lne 17: add

$ModLoad imudp
$UDPServerRun 514
$AllowedSender UDP, 127.0.0.1
# line 54: change like follows

*.info;mail.none;authpriv.none;cron.none
,local2.none
   /var/log/messages
local2.*                                                /var/log/haproxy.log


Next, we need to create a separate file ‘haproxy.conf‘ under ‘/etc/rsyslog.d/‘ directory to configure separate log files.


# vi /etc/rsyslog.d/haproxy.conf
Append following line to the newly create file.

local2.*            /var/log/haproxy.log

restart the rsyslog service to update the new changes.

# systemctl restart rsyslog
#systemctl restart haproxy