一. 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服務,才能夠記錄日志:
日志示例:
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) Peers:定義haproxy同步集群,實現在前端再加lvs
peer
peers
=========================================================
三.代理配置段:
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> [, …]
#用于定義監聽地址與端口,并且可以多次出現,監聽不同地址以及端口
因此,不應該使用默認配置,以免端口沖突
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并發量
示例:
—————————————————————————–
3. web GUI 的配置參數:
1) stats enable:啟用內建的統計頁,在缺少其它必要的參數時,會使用默認配置;
– stats uri : /haproxy?stats
– stats realm : “HAProxy Statistics”
– stats auth : no authentication
– stats scope : no restriction
示例:
stats enable
#開啟WEB GUI 內建統計頁面功能
stats uri <prefix>:自定義stats頁面的uri;
#默認為ip/haproxy?stats
stats realm <realm>:
Enable statistics and set authentication realm.
#認證提示語
stats auth <user>:<passwd>
Enable statistics with authentication and grant access to an account.
#定義認證使用的賬號和密碼;
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列表,非用戶自定義的
配置示例:
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:
——————————————————————————-
(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
官方示例:
— ————————————————————————-
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前面還存在緩存服務器,到時報文無法
到達指定的后端源服務器
官方示例:
——————————————————————————————
5.局部日志配置
1). log:為frontend或backend定義日志記錄機制;
log global #指使用全局定義的日志功能
log <address> [len <length>] <facility> [<level> [<minlevel>]]
#自定義指定的日志記錄機制
no log #不記錄日志
#注意:每個frontend或者backend,一共只可以定義兩次,
即可以一次訪問的日志信息,可以分別發往兩個位置,分別記錄,
如果global中已經定義了兩個log 定義,則無法再server中再次定義
日志格式:
actconn當前進程的活動連接數 / feconn 的當前連接數 / beconn的當前連接數 / srv_conn當前對應連接到的主機的連接數 / retries重試次數
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指定后端服務器,若無匹配的后端服務器時,
則使用此定義的默認后端服務器
#此示例中,為動靜資源分離,當不屬于動態資源也不屬于
規定的靜態資源時,則發往默認的后端服務器
=========================================================
四.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
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.
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.www58058.com/59680