haproxy配置文件
haproxy配置文件
?vim haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application.? See the
# full configuration options online.
#
#?? http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
?
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
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/syslog
??? #
??? #??? local2.*?????????????????????? /var/log/haproxy.log
??? #
??? log???????? 127.0.0.1 local2? #日志通過rsyslog進(jìn)行歸檔記錄
?
??? chroot????? /var/lib/haproxy? #運行的安裝路徑
??? pidfile???? /var/run/haproxy.pid?? #pid文件存放位置
??? maxconn???? 4000?????????? #最大連接數(shù)
??? user??????? haproxy???????? #運行程序使用haproxy用戶
??? group?????? haproxy????????? #運行程序使用haproxy組
??? daemon????????????? #以后臺模式運行haproxy
?
??? # turn on stats unix socket
??? stats socket /var/lib/haproxy/stats
?
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
??? mode??????????????????? http????????? #工作模式(7層 http;4層tcp )
??? log???????????????????? global??????? #記錄日志
??? option????????????????? httplog?????? #詳細(xì)記錄http日志
??? option????????????????? dontlognull?? #不記錄健康檢查的日志信息
??? option http-server-close????????????? #啟用服務(wù)器端主動關(guān)閉
??? option forwardfor?????? except 127.0.0.0/8 #傳遞客戶端IP
??? option????????????????? redispatch? #serverId對應(yīng)的服務(wù)器掛掉后,強(qiáng)制定向到其他健康的服務(wù)器
??? retries???????????????? 3????????? #請求重試次數(shù)
??? timeout http-request??? 10s??????????? #http請求超時時間
??? timeout queue?????????? 1m????????? #一個請求在隊列里的超時時間
??? timeout connect???????? 10s?????????? #連接服務(wù)器超時時間
??? timeout client????????? 1m?????????? #客戶端超時時間
??? timeout server????????? 1m?????????? #客戶端超時時間
??? timeout http-keep-alive 10s?????????? #持久連接超時時間
??? timeout check?????????? 10s???????? #心跳檢測超市時間
??? maxconn???????????????? 3000?????? #最大連接數(shù)
?
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend? proxy *:80
??? #定義ACL
??? acl url_static?????? path_beg?????? -i /static /p_w_picpaths /javascript /stylesheets
??? acl url_static?????? path_end?????? -i .jpg .gif .png .css .js
??? acl url_dynamic???? path_end? -i .php .jsp
??? use_backend dynamic????????? if url_dynamic #調(diào)用后端服務(wù)器并檢查ACL規(guī)則是否被匹配
??? default_backend???????????? static
?
#---------------------------------------------------------------------
# static backend for serving up p_w_picpaths, stylesheets and such
#---------------------------------------------------------------------
backend static??????????????? #后端算法
??? balance???? source
??? server????? static 192.168.5.13:80 inter 1500 rise 2 fall 3 check
#---------------------------------------------------------------------
listen statistics
??? mode http?????????????????????????? #http 7 層模式
??? bind *:8080???????????????????????? #監(jiān)聽地址
??? stats enable??????????????????????? #啟用狀態(tài)監(jiān)控
??? stats auth admin:admin????????????? #驗證的用戶與密碼
??? stats uri /admin?status???????????? #訪問路徑
??? stats hide-version????????????????? #隱藏狀態(tài)頁面版本號
??? stats admin if TRUE???????????????? #如果驗證通過了就允許登錄
??? stats refresh 3s??????????????????? #每3秒刷新一次
??? acl allow src 192.168.5.0/24?????? #允許的訪問的IP地址
??? tcp-request content accept if allow #允許的地址段就允許訪問
??? tcp-request content reject????????? #拒絕非法連接
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend synamic
??? balance???? source
??? server??? synamic 192.168.5.14:80 check inter 1500 rise 2 fall 3
#check inter 1500是檢測心跳頻率
#rise2?? 2次正確認(rèn)為服務(wù)器可用
#fall3?? 3次失敗認(rèn)為服務(wù)器不可用
轉(zhuǎn)載于:https://blog.51cto.com/zuoshou/1742475
總結(jié)
以上是生活随笔為你收集整理的haproxy配置文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 翻译: TypeScript 1.8 B
- 下一篇: 张鸿洋 博客