HAproxy load balancer

HAproxy load balancer;

Use it because of simply doing HTTP protocol load; at the same time can protect server-side service is not exposed to the IP network.

yum install haproxy -y

HAproxy configuration example;

haproxy arranged into five levels: 
Global : Global 
Listen: Frontend and Backend combination of 
defaults: configure the default parameters 
frontend: in response to a front end configuration 
backend: backend server cluster configuration

Configuration file example:

vi /etc/haproxy/haproxy.cfg
#
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/the syslog 
# 
# local2. * / var / log / haproxy.log 
# 
log 127.0 . 0.1 local2 
CHROOT / var / lib / HAProxy 
PidFile / var / RUN / haproxy.pid 
nbproc . 4         # number of threads 
The maxconn 5000         # maximum number of connections 
User HAProxy 
Group haproxy # user group 
daemon # be run as a daemon 
# Turn ON UNIX socket stats 
stats socket / var / lib / HAProxy / stats # 
Defaults


http module default mode http # 
log global         # log using global configuration module defined in 
option httplog # log category 
option dontlognull # HAProxy not ensure the recording state for detecting the upper load balancing over the transmission of heartbeat data packet without 
Option http -server- Close # when the high server load time, automatically off the end of the current queue processing relatively long link 
option forwardfor the except 127.0 . 0.0 / 8     # set the back-end address 
option after redispatch # serverId corresponding server hang, forcing directed to other healthy server 
retries 3     # retries 
timeout HTTP - request 10s # HTTP request timeout 
timeout queue 1m # default queue timeout 
timeout connect 10s # successfully connected to a server maximum wait time 
timeout http 
timeout client 1m # connection client maximum wait time
timeout server 1m # server response to client maximum wait time-keep- Alive # 10s long connection timeout 
timeout check 10s # heartbeat timeout 
maxconn 3000     # maximum number of connections
 
# set a static page to monitor 
the listen stats 
the MODE HTTP 
the bind 0.0 . 0.0 : 2019     # monitor 
stats enable # 
stats hide - Version # hidden version 
stats uri ?? / haproxyadmin stats # HAProxy state management page, by / HAProxy stats to access 
stats realm Haproxy \ statistics # statistics state 
stats auth admin: admin # set the monitoring page of the user and password 
stats ADMIN IF TRUE # load configuration 
frontend http 
the bind

 *: 
the MODE HTTP2020
log Global 
Option httpclose 
Option logasap 
Option dontlognull 
Capture Request header len the Host 20 is 
Capture the Referer len Request header 60 
default_backend Servers http_back # define a server group # backend configuration 
backend Servers 
Balance of the RoundRobin # Polling 
Server server1

 172.16.2.40:80 The maxconn 2000 Check 
Server server2 172.16.2.41:80 the check maxconn 2000 

back-end service marks of distinction ip: port 
maximum number of connections maxconn 
the check key 
inter health check interval 
2000 milliseconds 
rise detected as a normal number of 
fall detection for the number of failed 
weight weights    

 HAProxy load balancing algorithms:

roundrobin # Polling
 static - RR # WRR 
leastconn # minimum number of connections 
source # corresponds to nginx ip_hash 
HDR (name) # lock up every HTTP request HTTP request 
uri # requested according to the URI 
url_param # according to the request URl parameters ' Balance url_param ' The requires the URL of the parameter name AN 
RDP -cookie (name) # represents the (name) lock according to data hash cookie and every TCP request

 Detection page visit http: // ip: 2019; front password admin: admin

 

Guess you like

Origin www.cnblogs.com/sharesdk/p/12368630.html