Setup Load Balancing With Fail Over

This guide will explain how to create a web load balancer using HAProxy, HAProxy is an open source product and who supports the purposes of fail over load balancing webserver, largely for the purpose reverse proxy in site a high daily traffic (High availability load balance (support fail over and session) using the Debian base HAProxy).

how do I see if a site (web) using a load balancer or not? easy, type on terminal your linux host -t a and enter
the result will be like this
is an alias for detik.com.
detik.com has address 202.158.66.20
detik.com has address 202.158.66.86
detik.com has address 202.158.66.94
detik.com has address 202.158.66.190
detik.com has address 203.190.241.41
detik.com has address 203.190.241.43
detik.com has the address 203 190 241 166
in this paper we use a simple diagram like this
* Load Balancer 1: lb1.example.com, IP address: 192.168.0.100
* Load Balancer 2: lb2.example.com, IP address: 192.168.0.101
* Web Server 1: http1.example.com, IP address: 192.168.0.102
* Web Server 2: http2.example.com, IP address: 192.168.0.103
* We also need a virtual IP address That floats the between LB1 and lb2: 192.168.0.99

Here's a little diagram That shows our setup:

shared IP = 192.168.0.99
192.168.0.100 192.168.0.101 192.168.0.102 192.168.0.103
-------+------------+--------------+-----------+-- --------
| | | |
+--+--+ +--+--+ +----+----+ +----+----+
| LB1 | | lb2 | | http1 | | http2 |
+-----+ +-----+ +---------+ +---------+
haproxy haproxy 2 web servers (Apache)
keepalived keepalived

before the start of a good idea to make sure you install web applications on the webserver who has supported JSESSIONID
ok we just started

in httpd1 and http2
1. preparation on the web server, I am using apache2, you should use apache as well
in /etc/apache2/apache2.conf gantilah baris ini LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined with
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

then make sure you have to paste this line in your vhost configuration in /etc/apache2/sites-available/default
SetEnvIf REQUEST_URI "^ / check \. Txt $" dontlog
CustomLog /var/log/apache2/access.log combined env =! Dontlog

after that restart or reload your apache
/Etc/init.d/apache2 restart or /etc/init.d/apache2 reload

create a file check.txt
touch /var/www/ check.txt

2. this stage we will install its HAProxy

in lb1/lb2
for your users type in ubuntu live
sudo apt-get install haproxy

3. HAProxy configuration stage
in lb1/lb2
after you check the location of installation configuration file by typing where haproxy haproxy
in ubuntu there is usually at /etc/haproxy/haproxy.cfg, get used to the original red and swollen
cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg_ori
cat /dev/null> /etc/haproxy/haproxy.cfg
vim /etc/haproxy/haproxy.cfg then fill with line like this
global
127.0.0.1 log local0
127.0.0.1 log local1 notice
#Log loghost local0 info
maxconn 4096
#Debug
#Quiet
user haproxy
group haproxy

defaults
global log
http mode
option httplog
option dontlognull
3 retries
redispatch
maxconn 2000
contimeout 5000
clitimeout 50 000
srvtimeout 50 000

listen webfarm 192.168.0.99:80
http mode
enable stats
stats auth someuser: somepassword
balance roundrobin
cookie JSESSIONID prefix
option httpclose
option forwardfor
httpchk option HEAD / HTTP/1.0 check.txt
A cookie 192.168.0.102:80 webA server check
Webb 192.168.0.103:80 server cookie B check

then set enbled = 1 in /etc/default/haproxy like this
# Set ENABLED to 1 if you want the init script to start haproxy.
ENABLED = 1
# Add extra flags here.
# EXTRAOPTS = "-de-m 16"

Next we need a bridge between haproxy and web servers in order to deliver and ask for the webserver to want to monitor your request from haproxy, we need keepalived

in lb1/lb2

sudo apt-get install keepalived
sets also /etc/sysctl.conf to allow sharing an IP address in a way

vim /etc/sysctl.conf

add this line

net.ipv4.ip_nonlocal_bind = 1
then type the sysctl-p command to load the re-
after haproxy completed then the next is keepalived
in LB1

vi /etc/keepalived/keepalived.conf
vrrp_script chk_haproxy {# Requires keepalived-01.01.13
script "killall -0 haproxy" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of Prio if OK
}

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101 #101 on master, 100 on backup
virtual_ipaddress {
192.168.0.99
}
track_script {
chk_haproxy
}
}

intent of the line above the line we want to use the LB1 adal to be active or other languages ​​who as a master

keepalived service run by ordinary means
/Etc/init.d/keepalived start

ip addr sh eth0
in lb2
vim /etc/keepalived/keepalived.conf

vrrp_script chk_haproxy {#Requires keepalived-01.01.13
script "killall -0 haproxy" #cheaper than pidof
interval 2 #check every 2 seconds
weight 2 #add 2 points of Prio if OK
}

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 100 # 101 on master, 100 on backup
virtual_ipaddress {
192.168.0.99
}
track_script {
chk_haproxy
}
}

/Etc/init.d/keepalived start

type
ip addr sh eth0
should appear like this
lb2:~# ip addr sh eth0
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link / ether 00:0 c: 29: e0: 78:92 brd ff: ff: ff: ff: ff: ff
inet 192.168.0.101/24 brd 192.168.0.255 scope global eth0
inet6 fe80:: 20c: 29ff: fee0: 7892/64 scope link
valid_lft preferred_lft forever forever
lb2:~#


The next stage is the
lb1/lb2
/Etc/init.d/haproxy start

The next stage is testing try a request to 192.168.0.99 then you look at loadbalancer2 by typing
ip addr sh eth0
but it's worth turning off your LB1
This at once proves if failovernya already worked together loadblancernya

loadbalancing here is to split the web server load, while for failover using keepalived
Title : Setup Load Balancing With Fail Over
Description : This guide will explain how to create a web load balancer using HAProxy , HAProxy is an open source product and who supports the purposes o...

0 Response to "Setup Load Balancing With Fail Over"

Posting Komentar