94-HAProxy

一. HAProxy简介
1. LB CLuster:

工作于第四层:
lvs:Linux Virtual Server,内核(netfilter, INPUT);
nginx(stream):
HAProxy:mode tcp
工作于第七层:
http:nginx(http), haproxy(mode http), httpd, ats, …
2. HAproxy:
特性:
(单一进程工作模型,基于事件驱动,支持弹性二叉树数据结构)
HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high
availability environments. Indeed, it can:
: – route HTTP requests depending on statically assigned cookies
#支持基于cookie绑定的HTTP协议路由
: – spread load among several servers while assuring server persistence
through the use of HTTP cookies
#支持服务在持续使用http cook情况下的负载均衡
: – switch to backup servers in the event a main server fails
#支持主备模式,主服务器宕机时,服务切换到备用服务器
: – accept connections to special ports dedicated to service monitoring
#支持特定端口连接的监听服务
: – stop accepting connections without breaking existing ones
#支持不破坏现有连接的情况下终止接受连接请求
: – add, modify, and delete HTTP headers in both directions
#支持在每个调度器中添加,修改和删除HTTP 协议首部
: – block requests matching particular patterns
#支持使用特定表达式匹配块请求
: – report detailed status to authenticated users from a URI intercepted by
the application
#支持通过WEB GUI将调取的详细实时状态信息展示给指定认证用户
==========================================================
二.程序环境
1. Version:1.4, 1.5, 1.6, 1.7-dev
2 .程序环境:
配置文件:/etc/haproxy/haproxy.cfg
Unit File: haproxy.service
主程序:/usr/sbin/haproxy
内建错误页面: /usr/share/haproxy
400.http 403.http .. ……
3. 配置文件:
global:全局配置段
进程及安全配置相关的参数
性能调整相关的参数
Debug相关的参数
proxies:代理配置段
defaults:为frontend, backend以及listen提供默认配置;
frontend:前端,相当于Nginx中的server{ … };
backend:后端,相当于nginx中的upstream { … };
listen:前后端的直接组合;
简要示例:
frontend main *:80
default_backend websrvs
backend websrvs
balance roundrobin
server web1 10.1.0.68:80 check
server web2 10.1.0.69:80 check
4.官方文档: cbonte.github.io/haproxy-dconv/
==========================================================
三.global配置参数:
1. 进程及安全配置相关的参数
user/uid, group/gid, nbproc, ulimit-n, ca-base, …
1). log <address> [len <length>] <facility> [max level [min level]]:
#定义日志系统相关属性
#此处定义的是全局日志信息,在每个server中也可以单独配置日志记录方式
<address>:日志服务器地址;
<facility> : 信道
[len <length>]:每行日志记录的最大长度;
[max level [min level]]: 定义收集最大与最小级别间的日志信息
默认为: log 127.0.0.1 local2
注意: 当使用localN 此类记录方法时,需要在日志服务器rsyslog.conf中,添加
localN的存放位置
eg:
local2.* /var/log/haproxy.log
#注意: 需要启动rsyslog服务,才能够记录日志:
4-HAProxy"
日志示例:
4-HAProxy"
2). ca-base <dir>: #使用https时,用于指定CA证书目录
Assigns a default directory to fetch SSL CA certificates and CRLs from
when a relative path is used with “ca-file” or “crl-file” directives.
3). crt-base <dir>:
Assigns a default directory to fetch SSL certificates from when a relative
path is used with “crtfile” directives.
#ssl时接受证书的默认存放位置
4). nbproc <number> :
#定义工作于守护进程模型时,启动的进程数量,默认为1,且1个进程,为推荐配置,因
此无需修改
2. 性能调整相关的参数:
1) 性能相关参数:
maxconn <number>:设定单haproxy进程的最大并发连接数;
maxconnrate <number>:设定单haproxy进程每秒接受的连接数;
maxsslconn <number>:设定单haproxy进程的ssl连接最大并发连接数;
maxsslrate <number>:单haproxy进程的ssl连接的创建速率上限;
spread-checks <0..50, in percent>
#用于将后端服务器健康监测分散,避免同时监测,堵塞带宽
tune.rcvbuf.client <number>
#请求接收缓冲池中的最大客户端数目
tune.rcvbuf.server <number>
#接收后端服务器的缓冲池中服务器数量
tune.sndbuf.client <number>
#客户端响应缓冲池中的客户端数量
tune.sndbuf.server <number>
#后端服务器请求缓冲池中的客户端数量
tune.ssl.cachesize <number>
#https 缓存空间大小
tune.ssl.lifetime <timeout>
#https缓存有效时长
2) Debugging: #调试相关
debug #调试模式,可以尽可能详细地输出信息
quiet #尽量不输出信息
3) Userlists:定义用户、组及用户列表;(可以用于授权)
userlist <listname>
group <groupname> [users <user>,<user>,(…)]
user <username> [password|insecure-password <password>]
[groups <group>,<group>,(…)]
示例:
4-HAProxy"
4) Peers:定义haproxy同步集群,实现在前端再加lvs
peer
peers
4-HAProxy"
=========================================================
三.代理配置段:
1. 代理配置段概述
Proxy configuration can be located in a set of sections :
– defaults <name> #定义默认响应服务器
– frontend <name> #定义前端监听IP,端口等信息
– backend <name> #定义后端服务器
– listen <name> #前后端直连模式
A “defaults” section sets default parameters for all other sections following
its declaration. Those default parameters are reset by the next “defaults”
section. See below for the list of parameters which can be set in a “defaults”
section. The name is optional but its use is encouraged for better readability.
A “frontend” section describes a set of listening sockets accepting client
connections.
A “backend” section describes a set of servers to which the proxy will connect
to forward incoming connections.
A “listen” section defines a complete proxy with its frontend and backend
parts combined in one section. It is generally useful for TCP-only traffic.
All proxy names must be formed from upper and lower case letters, digits,
‘-‘ (dash), ‘_’ (underscore) , ‘.’ (dot) and ‘:’ (colon).
————————————————————————————-
2. 配置参数:
1) bind:Define one or several listening addresses and/or ports in a frontend.
bind [<address>]:<port_range> [, …]
#用于定义监听地址与端口,并且可以多次出现,监听不同地址以及端口
因此,不应该使用默认配置,以免端口冲突
4-HAProxy"
2) mode { tcp|http|health } #用于定义工作于应用层还是传输层
定义haproxy的工作模型:
tcp:基于layer4实现代理,可代理大多数基于tcp的应用层协议,例如
ssh/mysql/pgsql等;
http:客户端的http请求会被深度解析;
health:工作为健康状态检查响应模式,当请求到达时仅回应“OK”即断
开连接;
———————————————————————————
3) balance:Define the load balancing algorithm to be used in a backend.
#负载均衡调度算法
balance <algorithm调度算法> [ <arguments> ]
balance url_param <param> [check_post]
(1)hash-type:
map-based:取模法,hash数据结构是静态数组;
consistent:一致性哈希,哈希的数据结构是“树”;
#balance 的多个调度算法的动态或者静态性,由hash-type所决定
即在做哈希运算的时候,使用map-based 则为静态调度,反之使用
consistent方法做哈希,则为动态调度
(2)<algorithm>: #调度算法
roundrobin:Each server is used in turns, according to their weights.
#加权轮询,支持慢启动(会动态调整权重)
#最多支持4095个后端活动服务器
#server后面使用weight来定义权重;
动态算法:支持权重的运行时调整,支持慢启动;仅支持最大4095个
后端活动主机;
static-rr:Each server is used in turns, according to their weights.
, #静态的不支持动态调整权重的加权轮询
静态算法:不支持权重的运行时调整及慢启动;但后端主机数量无限
制;
leastconn:The server with the lowest number of connections
receives the connection.
#最少连接算法
#属于动态算法;
first:The first server with available connection slots receives the
connection. The servers are chosen from the lowest numeric
identifier to the highest , which defaults to the server’s
position in the farm.
#服务器名称标示符ID短的,优先调度, 可以用于线性提升负载能力
#即当前一个服务器负载满了以后,再继续负载下一个
#会忽略服务器权重, 且只有长连接时候有效
source:The source IP address is hashed and divided by the total
weight of the running servers to designate which server
will receive the request.
#源地址哈希算法
#属于动态算法或静态算法取决于hash-type;
uri:This algorithm hashes either the left part of the URI (before the
question mark) or the whole URI (if the “whole” parameter is
present) and divides the hash value by the total weight of
the running servers.
#scheme://user:password@host:port/uri;params?query#frag
#即对uri或者uri;params 做哈希运算,当再次请求相同uri时候,将始终发往
同一台主机
#当后端为缓存服务器时候常使用此方式,且为建议的配置
#动态算法或静态算法取决于hash-type;
#可以用于实现动静分离
补充: URL:
scheme://user:password@host:port/uri;params?query#frag
eg:
http://www.magedu.com/goods.php;username=jerry?
#当设置为balence uri 后, 第一次请求goods.php以后,再次请求
goods.php都将发往同一台服务器,
url_param:The URL parameter specified in argument will be looked
up in the query string of each HTTP GET request.
# 对用户请求的url中的<param>部分中的指定的参数的值作hash计
算,并由服务器总权重相除以后派发至某挑出的服务器;
#通常来说,对于使用游客身份访问一站点时候,服务器会自动为请求者赋
予一个临时的id,作为哈希对象,以识别来访者
eg:
http://www.magedu.com/goods.php;username=jerry?
将username作为键, 值jerry作为哈希对象,此后每次以jerry身份登
录时,均发送同一台服务器
hdr(<name>):The HTTP header <name> will be looked up in each
HTTP request.
#指定的http首部将会被取出做hash计算,并由服务器总权重相除以后
派发至某挑出的服务器;没有有效值的会被轮询调度;
#此方式使用并不多,了解即可
eg:
balance hdr(User-Agent)
rdp-cookie
rdp-cookie(<name>)
#windows远程桌面协议相关, 了解即可,详情查看官方文档
———————————————————————————
4) maxconn <conns>:
Fix the maximum number of concurrent connections on a frontend. By
default, this value is set to 2000.
#通常情况下,1G的内存,可以提供2W-2.5W的并发连接
#默认为2000并发量
示例:
4-HAProxy"
—————————————————————————–
3. web GUI 的配置参数:
1) stats enable:启用内建的统计页,在缺少其它必要的参数时,会使用默认配置;
– stats uri : /haproxy?stats
– stats realm : “HAProxy Statistics”
– stats auth : no authentication
– stats scope : no restriction
示例:
4-HAProxy"
stats enable
#开启WEB GUI 内建统计页面功能
stats uri <prefix>:自定义stats页面的uri;
#默认为ip/haproxy?stats
4-HAProxy"
stats realm <realm>:
Enable statistics and set authentication realm.
#认证提示语
stats auth <user>:<passwd>
Enable statistics with authentication and grant access to an account.
#定义认证使用的账号和密码;
4-HAProxy"
stats hide-version:
Enable statistics and hide HAProxy version reporting
#在web gui 页面中隐藏haproxy的版本信息
stats refresh <delay>
#自动刷新相关页面的时间间隔;
stats admin { if | unless } <cond>
Enable statistics admin level if/unless a condition is matched.
#条件满足时启用stats内建的管理功能接口;
# 一般是前面已经加stats auth 认证,
eg:
stats auth admin:admin
stats admin if TRUE
仅允许本地主机登录的示例:
#此时使用的是内建的ACL列表,非用户自定义的
4-HAProxy"
配置示例:
frontend main
bind *:80,*:8080
stats enable
stats uri /admin?stats
stats realm Stats\ Page\ Area
stats auth admin:admin
stats refresh 5s
stats hide-version
stats admin if TRUE
maxconn 10000
4. server:用于在backend中定义一个主机;
1) server <name> <address>[:[port]] [param*]
<name> is the internal name assigned to this server. This name will
appear in logs and alerts.
<address> is the IPv4 or IPv6 address of the server.
<param*>:参数
weight <weight>:当前server的权重;
check:对当前server进行健康状态检测;
inter <delay>:时间间隔;
rise <count>:判定为“健康”状态需要检测的次数,默认2;
fall <count>:判定为“不健康”状态需要检测的次数,默认3;
addr <ipv4|ipv6>:健康状态检测时使用的地址;
port <port>:健康状态检测时使用的端口;
注意:默认为传输层检测,即探测端口是否能响应;需要执行应用层
检测,则需要httpchk, smtpchk, mysql-check, pgsql-
check, ssl-hello-chk;
cookie <value>:为当前server指定其cookie值,此值会在收到请求报文
时进行检测,其功能在于实现基于cookie会话保持;
disabled:将主机标记为不可用;
maxconn <maxconn>:当前server的最大并发连接数;
maxqueue <maxqueue>:当前server的等待队列的最大长度;
redir <prefix>:将发往当前server的所有请求GET和HEAD类的请求均重定
向至指定的URL;
2)server 健康状态检测:
option httpchk
option httpchk <uri>
option httpchk <method> <uri>
option httpchk <method> <uri> <version>
#基于http协议作7层健康状态检测机制;
<method> <uri> <version>:请求报文的超始行;
#<method>默认使用此option 方法,也可以使用其他方法,但option 为推荐方式
eg:
4-HAProxy"
——————————————————————————-
(1)http-check expect [!] <match> <pattern>:
Make HTTP health checks consider response contents
or specific status codes
#基于响应码做状态检测
<match>:status或string;
<pattern>:匹配期望的响应结果的模式;
eg:
http-check expect status 200
官方示例:
4-HAProxy"
— ————————————————————————-
3) cookie:启用基于cookie的会话黏性,要结合server指定的cookie参数一起实现;
cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ] [ postonly ] [
preserve ] [ httponly ] [ secure ] [ domain <domain> ]* [ maxidle
<idle> ] [ maxlife <life> ]
#也可以自定义一个cookie,在请求报文中插入cookie,根据此cookie ,可以发往指定
服务器
eg:
cookie SRV insert nocache indirect
#此方法较为常用
示例:
backend websrvs
balance roundrobin
cookie WEBSRV insert nocache indirect
server web1 10.1.0.68:80 check weight 2 maxconn 5000 cookie web1
server web2 10.1.0.69:80 check weight 1 maxconn 3000 cookie web2
#WEBSRV为cookie键名称,值即为web1,web2
#nocache 表示不允许缓存,避免haproxy前面还存在缓存服务器,到时报文无法
到达指定的后端源服务器
4-HAProxy"
4-HAProxy"
4-HAProxy"
官方示例:
4-HAProxy"
——————————————————————————————
5.局部日志配置
1). log:为frontend或backend定义日志记录机制;
log global #指使用全局定义的日志功能
log <address> [len <length>] <facility> [<level> [<minlevel>]]
#自定义指定的日志记录机制
no log #不记录日志
#注意:每个frontend或者backend,一共只可以定义两次,
即可以一次访问的日志信息,可以分别发往两个位置,分别记录,
如果global中已经定义了两个log 定义,则无法再server中再次定义
日志格式:
4-HAProxy"
4-HAProxy"
actconn当前进程的活动连接数 / feconn 的当前连接数 / beconn的当前连接数 / srv_conn当前对应连接到的主机的连接数 / retries重试次数
4-HAProxy"
srv_queue处理改请求时 server端的队列正在处理的连接数  
backend_queue 处理改请求是 backend队列正在处理的连接数
6.报文首部获取
capture request header <name> len <length>
记录请求报文中的指定的首部的值于日志中;len用于指定要记录的信息的长度;
capture response header <name> len <length>
记录响应报文中的指定的首部的值于日志中;len用于指定要记录的信息的长度;
示例:
capture request header Referer len 30
7.错误页面自定义
#当后端服务器,无返回结果的时候,则需要由haproxy来回应客户端,回应错误信息
#注意,不包含404, 因为404仅能由后端服务器判断资源是否存在,haproxy无法获悉资源情况
errorfile <code> <file>
Return a file contents instead of errors generated by HAProxy.
<code> is the HTTP status code. Currently, HAProxy is capable of
generating codes 200, 400, 403, 408, 500, 502, 503, and 504.
<file> designates a file containing the full HTTP response.
示例:errorfile 503 /etc/haproxy/errorfiles/503sorry.http
errorloc <code> <url>
#使用URL来返回指定错误代码的对应页面文件
errorloc302 <code> <url> #和errorloc类似
#基于返回302响应码的重定向错误页面
Return an HTTP redirection to a URL instead of errors generated by
HAProxy.
示例:
errorloc 503 http://10.1.0.67:8090/errorpagetest.html
8. 修改请求或响应报文首部相关
option forwardfor [ except <network> ] [ header <name> ] [ if-none ]
#Enable insertion of the X-Forwarded-For header to requests sent to
#servers.
#HAProxy把请求报文发往后端主机之前在请求报文添加“X-Forwared-For”首部;
#一般默认已经配置了option forwardfor except 127.0.0.0/8
报文首部添加:
reqadd <string> [{if | unless} <cond>]
Add a header at the end of the HTTP request
#在请求报文尾部添加指定的首部内容
rspadd <string> [{if | unless} <cond>]
Add a header at the end of the HTTP response
#在响应报文尾部添加指定的首部内容
示例:
rspadd X-Via:\ HAProxy/1.5
#”\”用于转移空格字符
报文首部删除:
reqdel <search> [{if | unless} <cond>]
reqidel <search> [{if | unless} <cond>] (ignore case)
Delete all headers matching a regular expression in an HTTP request
rspdel <search> [{if | unless} <cond>]
rspidel <search> [{if | unless} <cond>] (ignore case)
Delete all headers matching a regular expression in an HTTP response
示例:
rspidel Server.*
—————————————————————————————–
9.超时时长设置:
timeout client <timeout>:
Set the maximum inactivity time on the client side. 默认单位是ms;
#客户端非活动的连接最大时长
timeout server <timeout>
Set the maximum inactivity time on the server side. 默认单位是ms;
#后端服务器非活动的连接最大时长
timeout connect <timeout>
Set the maximum time to wait for a connection attempt to a server to
succeed.
#想后端服务器发起请求连接的超时时长
timeout http-keep-alive <timeout>
Set the maximum allowed time to wait for a new HTTP request to appear.
默认单位为ms;
#面向客户端一侧启用保持连接时的超时时长
timeout client-fin <timeout>
Set the inactivity timeout on the client side for half-closed connections.
#客户端半连接超时时长
timeout server-fin <timeout>
Set the inactivity timeout on the server side for half-closed connections.
#服务器端半连接超时时长
10. default_backend <backend>:
Specify the backend to use when no “use_backend” rule has been matched.
#用于为前端定义默认的后端服务器
#前端可以使用use_backend指定后端服务器,若无匹配的后端服务器时,
则使用此定义的默认后端服务器
4-HAProxy"
#此示例中,为动静资源分离,当不属于动态资源也不属于
规定的静态资源时,则发往默认的后端服务器
=========================================================
四.ACL:
The use of Access Control Lists (ACL) provides a flexible solution to perform content switching and generally to take decisions based on content extracted from the request, the response or any environmental status.
1. 语法格式:
acl <acl_name> <criterion> [flags] [operator] [<value>] …
acl名称 规则 标志位 操作 值
内建ACL : 均以大写字母形式的ACL规则, 可直接调用 ( 详情查询官方文档)
2. <aclname>:ACL names must be formed from upper and lower case letters,
digits, ‘-‘ (dash), ‘_’ (underscore) , ‘.’ (dot) and ‘:’ (colon). ACL
names are case-sensitive.
#需要区分大小写
3. <value>的类型:
– boolean
– integer or integer range
– IP address / network
– string (exact, substring, suffix, prefix, subdir, domain)
– regular expression
– hex block
4. [flags]
The following ACL flags are currently supported :
-i : ignore case during matching of all subsequent patterns.
#模式匹配时,忽略大小写
-f : load patterns from a file.
#使用文件装载正则表达式
-m : use a specific pattern matching method
#
-n : forbid the DNS resolutions
#禁止地址反解
-M : load the file pointed by -f like a map file.
#
-u : force the unique id of the ACL
#
— : force end of flags. Useful when a string looks like one of the flags.
#强制转移,防止字符中有类似 [flags] 的字符串
5. [operator]
数值匹配:
eq : true if the tested value equals at least one value
ge : true if the tested value is greater than or equal to at least
one value
gt : true if the tested value is greater than at least one value
le : true if the tested value is less than or equal to at least one
value
lt : true if the tested value is less than at least one value
字符串匹配:
– exact match (-m str) : the extracted string must exactly
match the patterns ;
#精确匹配
– substring match (-m sub) : the patterns are looked up inside
the extracted string, and the ACL matches if any of them
is found inside ;
#匹配指定字符串中的一部分
– prefix match (-m beg) : the patterns are compared with the
beginning of the extracted string, and the ACL matches
if any of them matches.
#匹配字符串的前部分
– suffix match (-m end) : the patterns are compared with the
end of the extracted string, and the ACL matches if any
of them matches.
#后缀匹配(结束部分)
– subdir match (-m dir) : the patterns are looked up inside the
extracted string, delimited with slashes (“/”), and the
ACL matches if any of them matches.
#目录匹配(路径匹配,子目录匹配)
– domain match (-m dom) : the patterns are looked up inside
the extracted string, delimited with dots (“.”), and the
ACL matches if any of them matches
#域名匹配.
条件的逻辑连接
– AND (implicit)
– OR (explicit with the “or” keyword or the “||” operator)
– Negation with the exclamation mark (“!”)
6. <creterion>:
4层检查机制:
Fetching samples at Layer 4:
dst : ip #匹配请求报文的目标地址
dst_port : integer #匹配请求报文的目标端口
src : ip #匹配请求报文的源地址
src_port : integer ##匹配请求报文的源端口
示例:
acl myhost src 10.1.0.200
acl myport dst_port 8080
block if !myhost myport
7层检查机制:
path : string
This extracts the request’s URL path, which starts at the first
slash and ends before the question mark (without the host part).
ACL derivatives :
path : exact string match
path_beg : prefix match
path_dir : subdir match
path_dom : domain match
path_end : suffix match
path_len : length match
path_reg : regex match
path_sub : substring match
示例:
acl text_file path_end -i .txt
block if text_file
#访问.txt的资源时候就拒绝
req.hdr([<name>[,<occ>]]) : string
This extracts the last occurrence of header <name> in an
HTTP request.
#基于请求报文首部信息的匹配机制
hdr([<name>[,<occ>]]) : exact string match
hdr_beg([<name>[,<occ>]]) : prefix match
hdr_dir([<name>[,<occ>]]) : subdir match
hdr_dom([<name>[,<occ>]]) : domain match
hdr_end([<name>[,<occ>]]) : suffix match
hdr_len([<name>[,<occ>]]) : length match
hdr_reg([<name>[,<occ>]]) : regex match
hdr_sub([<name>[,<occ>]]) : substring match
示例:
acl firefox hdr_reg(User-Agent) -i .*firefox.*
block if firefox
res.hdr([<name>[,<occ>]]) : string
This extracts the last occurrence of header <name> in an
HTTP response, or of the last header if no <name> is specified.
#基于响应报文首部的匹配
#阻断指定服务器的响应
shdr([<name>[,<occ>]]) : exact string match
shdr_beg([<name>[,<occ>]]) : prefix match
shdr_dir([<name>[,<occ>]]) : subdir match
shdr_dom([<name>[,<occ>]]) : domain match
shdr_end([<name>[,<occ>]]) : suffix match
shdr_len([<name>[,<occ>]]) : length match
shdr_reg([<name>[,<occ>]]) : regex match
shdr_sub([<name>[,<occ>]]) : substring match
url : string
This extracts the request’s URL as presented in the request.
url : exact string match
url_beg : prefix match
url_dir : subdir match
url_dom : domain match
url_end : suffix match
url_len : length match
url_reg : regex match
url_sub : substring match
7. method : integer + string
#检查 请求报文中的请求方法
acl valid_method method GET HEAD
http-request deny if ! valid_method
注意:HAProxy有众多内建的ACLs,这些ACLs可直接调用,例如
LOCALHOST,TRUE,HTTP;
8. 访问控制相关的参数:
block { if | unless } <condition>
Block a layer 7 request if/unless a condition is matched
阻止符合指定acl的访问请求;
http-request { allow | deny} [ { if | unless } <condition> ]
ccess control for Layer 7 requests
示例:
acl myhost src 10.1.0.67
http-request deny if url_admin !myhost
4-HAProxy"
tcp-request connection <action> [{if | unless} <condition>]
Perform an action on an incoming connection depending on a layer 4
condition
#用于haproxy工作于tcp模式时候的匹配
# 匹配tcp请求报文中指定信息
tcp-request content <action> [{if | unless} <condition>]
Perform an action on a new session depending on a layer 4-7 condition
<action> defines the action to perform if the condition applies. Valid
actions include : “accept”, “reject”, “track-sc0”, “track-sc1”,
“track-sc2”, and “expect-proxy”.
<condition> is a standard layer4-only ACL-based condition.
4-HAProxy"
4-HAProxy"
9. 后端主机调用:
use_backend <backend> [{if | unless} <condition>]
Switch to a specific backend if/unless an ACL-based condition is matched.
eg:
acl text_file path_end -i .txt
block if text_file
acl myhost src 10.1.0.200
acl myport dst_port 8080
block if !myhost myport
实践作业:
(1) 动静分离discuzx,动静都要基于负载均衡实现;
(2) 进一步测试在haproxy和后端主机之间添加varnish缓存;
(3) 给出拓扑设计;
(4) haproxy的设定要求:
(a) 启动stats;
(b) 自定义403、502和503的错误页;
(c) 各组后端主机选择合适的调度方法;
(d) 记录好日志;
(e) 使用keepalived高可用haproxy;
写成文档;
HAProxy 5 文档地址
http://cbonte.github.io/haproxy-dconv/configuration-1.5.html

原创文章,作者:ldt195175108,如若转载,请注明出处:http://www.178linux.com/59680

(0)
上一篇 2016-11-18 19:25
下一篇 2016-11-18 20:04

相关推荐

  • parted使用说明

    一.为什么使用parted命令     传统的MBR(Master Boot Record)分区方式,有一个局限:无法支持超过2TB的硬盘分区(单个分区超过2TB)。     GPT(GUID Partition Table)的分区表很好的解决了这个问题,但在Linux系统中,传…

    Linux干货 2015-04-13
  • Linux用户及权限管理

    Linux用户及权限管理 当我们用ls -al查看一个文件的详细信息的时候会显示出一个有七个字段的文件详细信息,现在我们来了解下这七个字段各自代表的意义 drwxr-xr-x 18 root root 4096 12月 16 15:25 .config 我们先来说明这七段分别表示什么每个字段我们用 | 隔开 drwxr-xr-x | 18 | root | …

    Linux干货 2016-12-19
  • Linux终端类型

    前言 终端是一个很重要的外设,用过终端设备的人都知道如果设备类型不对就会有乱字符,也可用仿真终端软件如netterm试验一下,Linux的终端信息放在 /usr/share/terminfo下,在这个目录的子目录v下就有许多的如vt100,vt102,vt200等,看一下就知道了。 终端类型的区别与概念 1、 pty(虚拟终端): 但是如果我们远程telne…

    Linux干货 2016-10-14
  • 进程和计划任务

    一、知识整理 1、网络客户端工具:lftp,ftp,lftget,wget 子命令:get,mget,ls,help等 wget [opt] …[url] -q 静默模式 -c 断点续传 -O 保存位置 –limit-rates=  指定传输速率 登录ftp之后:lcd 在本机切换目录;get下载单个文件 !ls 查看本机文…

    Linux干货 2016-09-13
  • 马哥教育网络班21期-第五周课程练习

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@localhost ~]# grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符…

    Linux干货 2016-08-08
  • History的作用及调用历史命令的快捷方式

    History的作用及调用历史命令的快捷方式 M21-陆东贵 CentOS 7.2 命令历史:shell进程会在其回话中保存此前用户提交执行过的命令; history命令:命令历史; 命令语法:history [-c] [-d 偏移量] [n] 或           …

    Linux干货 2016-10-19