What is a HAProxy ?
HAProxy is free, open source software that provides a high availability load balancer and proxy server for TCP and HTTP-based applications that spreads requests across multiple servers.
Two type of load Balancing.
1.Transport layer (layer 4) load balancing.
2.Application layer (layer 7) load balancing.
1.Transport layer load balancing:-
i) This is also called Layer 4 (tcp protocol) load balancing.
ii) Used to load balance network traffic between multiple servers.
iii) Based on IP range and port number.
2.Application layer load balancing:-
i) This is also called layer 7 (http protocol) load balancing.
ii) Used to load balance network traffic between multiple servers.
iii) Based on contents of user request.
3.haproxy terminology :-
a) ACL : access control list
Used to verify condition and perform action.
Eg:- acl url_login path_beg/login
b) Frontend
i)This define how request should be forward to backend.
- set of IP address and Port
- ACL’s
- Backend rule which is already defined in backend.
Eg:- frontend webapp
Bind *:80 (Transport Layer)
default_backend appserver
Eg:- frontend webapp
bind *:80 (Application Layer)
acl url_blog path_beg/blog
default_backend appserver
c) Backend
i)This is set of servers which receives forwarded requests from frontend.
ii)Two parameters contained by backend.
· List of servers and ports.
· Load balancing algorithm to use.
Eg. Backend appserver
balance roundrobin
server app1 app1.domain.com:80 check
server app1 app1.domain.com:80 check
Eg. Backend appserver
balance roundrobin
mode http
server app1 app1.domain.com:80 check
server app1 app1.domain.com:80 check
4. load balancing algorithms :-
RoundRobin – one by one
Leastconn – depend on load
source – depend on user/source IP
sticky sessions – continues connection
health check – to check server availability
Install HAProxy :-
Configure HAProxy :-
# this config needs haproxy-1.1.28 or haproxy-1.2.1
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
# log loghost local0 info
maxconn 4096
# chroot /usr/share/haproxy
uid 99
gid 99
daemon
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
# redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
frontend http-in
bind *:80
default_backend servers
backend servers
option httpchk OPTIONS /
option forwardfor
stats enable
stats refresh 10s
stats hide-version
stats scope .
stats uri /admin?stats
stats realm Haproxy\ Statistics
stats auth admin:pass
cookie JSESSIONID prefix
server tomcat-1 127.0.0.1:8080 cookie JSESSIONID_SERVER_1 check inter 5000
server tomcat-1 127.0.0.1:8090 cookie JSESSIONID_SERVER_1 check inter 5000
Check URL :-
http://127.0.0.1/admin?stats
OR
http://127.0.0.1:80/admin?stats
username :- admin
password :- pass
No comments:
Post a Comment