Haproxy build a web cluster

Haproxy build a web cluster
Highlights 1:
1 four load balancing:
1) the DNS poll: the same domain name will resolve to achieve load balancing for multiple different ip addresses.
2) Nginx Load balancing: by defining upstream group name {server ip: port weight = weight; ...} backend service, then proxy_pass HTTP: // load balancing group name .
3) LVS load balancing: load balancing call linux kernel (kernel) module ip_vs defined by ipvsadm VIP (cluster IP) and real server (back-end server).
2.haproxy load balancing: by defining listen (listen), is defined using the server back-end web server monitoring, load balancing scheduling algorithm specified in the balance.
3. seven agents:
1) squid proxy: set up squid in the front end of the site for users to access speed, and provides ACL (Access Control List) function.
2) nginx proxy: proxy_pass and other parameters to achieve seven agents.
3) haproxy Agent: users and back-end service mapping agency achieved by listening.
4) apache Agent: apache relatively less agent, mainly because of poor performance.
In short: LVS best performance, but the configuration complexity; nginx cluster node health check function is not strong, the performance is better haproxy.
Highlights 2: HTTP request:
1.http request: Access via URL (Uniform Resource Locator) Web site is http request.
2.http request status code: There will be a digital representation of the results of the requested URL to access the site when, if 2xx or 3xx (eg 200/301) suggests that the site can be a normal visit, if it is 4xx or 5xx (eg 404/500) represents an access site error.
Highlights 3: load balancing and scheduling algorithms commonly used web cluster schedulers:
1. The load balancing algorithm used scheduling: the RR (poll sequentially distribution tasks), the LC (minimum connection, according to the amount of the current processing request cluster node, the distributed task a small amount of processing node request), SH (source access scheduling algorithm, based on the back-end server ip client or a client cookie to determine access and distribute tasks to this back-end server)
2. common web cluster scheduler: DNS round exercise, nginx proxy, LVS load balancing, haproxy agents, hardware devices (such as F5, pike, green League) load balancer.
4 Content Key: + Nginx deployment HAPROX:
1. Installation Nginx
2. Installation and Configuration haproxy haproxy
Highlights 5: Haproxy profile: /etc/haproxy/haproxy.cfg
. 1) global configuration:
setting global # global parameter
log 127.0. 0.1 local2

log语法:log <address_1>[max_level_1]

# 全局的日志配置,使用log关键字,指定使用127.0.0.1上的syslog服务中的local0日志设备,记录日志等级为info的日志
chroot      /var/lib/haproxy      #改变当前工作目录
pidfile     /var/run/haproxy.pid    #当前进程id文件
maxconn     4000           #最大连接数
user        haproxy         #所属用户
group       haproxy         #所属组
daemon                     #以守护进程方式运行haproxy
stats socket /var/lib/haproxy/stats  #基于本地的文件传输

2) proxies (proxy) configuration parameters:
MODE HTTP
# default mode mode {tcp | http | health} , tcp 4 layers, http layer 7, health will only return the OK
log Global
# applications global logging setting
option httplog

Enable logging HTTP request, the default haproxy logging is not recorded HTTP request logs

option dontlognull

Enable this option, the log does not record air connections. The so-called air is connected upstream of the load balancer or monitoring system in order to detect whether the service is available when alive, require periodic connection or a fixed component or acquired page, or to detect whether the port scan monitor or the like is referred to in the opening operation air link; official document annotation, if the service is no other upstream load balancer, it is not recommended to use this parameter, because malicious scanning on the Internet or other actions will not be recorded

http-Server-use Close the Option
# actively closed after each request is finished http channel
the Option forwardfor the except 127.0.0.0/8
# If the application on the server wants to record the IP address of the client initiated the request, you need to configure this option on HAProxy, so HAProxy IP information will be sent to the client server, add the "X-Forwarded-for" field in the HTTP request. Enabled X-Forwarded-For, is inserted into the head end IP customer requests sent to the back-end server, the back-end server to get the real IP client.
redispatch the Option
# When using a cookie, haproxy will be serverID of its back-end server requests inserted into the cookie, in order to ensure SESSION persistent session; but this time, if the back-end server dawdle off, but the client's cookie It will not refresh, if you set this parameter, will be directed to the customer's request to force the other back-end server, to ensure the normal services.
retries 3

Backend server connection failure was defined reconnection times, the number of connection failures will exceed this value will correspond marked as unavailable backend server

timeout http-request 10s #http request time
timeout queue 1m # timeout request in a queue
timeout connect 10s # connection timeout
timeout client 1m # client timeout
timeout server 1m # server timeout
timeout http-keep-alive 10s # setting http-keep-alive timeout
timeout check 10s # detection timeout
maxconn 3000 # per process maximum number of connections available to
frontend main : # 80 listens address 80
acl url_static path_beg -i / static / ImagesRF Royalty Free / JavaScript / stylesheets
acl url_static -i .jpg .gif .png .css path_end .js
use_backend static IF url_static
default_backend my_webserver
# define a front end portion my_webserver named. Here the corresponding request is forwarded to the backend
backend static
# using static and dynamic separation (if url_path match .jpg .gif .png .css .js static file is accessed after the end)
Balance of the RoundRobin
# Load balancing algorithm (#banlance roundrobin polling, balance source to save the session value, support for static-rr, leastconn, first, uri and other parameters)
Server static 127.0.0.1:80 the Check
# static file is deployed in the machine (can also be deployed in other machines or squid caching server)
my_webserver backend
# define a rear end portion my_webserver named. PS: Here my_webserver just a custom name only, but the term default_backend value consistent with the need to configure the frontend inside
balance roundrobin # load balancing algorithm
multiple back-end server web01 172.31.2.33:80 check inter 2000 fall 3 weight 30 # defined
server web02 172.31.2.34:80 check inter 2000 fall 3 weight 30 # define a plurality of rear
multiple backend server web03 172.31.2.35:80 check inter 2000 fall 3 weight 30 # definition
3) server Explanation:
Server <name > <address>: [[Port]] [param
]
each server and its backend host defined options server <name> <address> [ : port] [settings ...] default-server [settings ...]
<name>: internal server name on the haproxy; and a warning message appears in the log
<address>: server address, supports the use of the host name
[: [port]]: port mapping; when is omitted, the port is bound in the same bind
[param ]: parameter
check: to make the current health detection server, used only for detecting four
Note: httpchk, "smtpchk", " mysql-check", "pgsql-check" and "sslhello-chk" defines the application layer detection method
addr: IP address used to detect the
port: for this port to detect
inter <delay>: the time interval between two consecutive detected, the default is 2000ms
Rise <COUNT>: the number of consecutive detection result is "success" only marker server is available; default is 2
Fall <COUNT>: number of consecutive detection result is "failed" was marked server is unavailable; default. 3
cookie <value>: the currently specified value of the cookie server, implement, cookie viscosity
disabled: marked unavailable
redir <prefix>: requesting all the GET HEAD classes and to this redirect server to the specified the URL
weight <weight>: weight default. 1
Maxco nn <maxconn>: the current maximum number of concurrent connections server
backlog <backlog>

server-default [param
] set the default options for each server in the backend

Guess you like

Origin blog.51cto.com/14382976/2406846