haproxy配置文件javascript
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進行歸檔記錄
chroot /var/lib/haproxy #運行的安裝路徑
pidfile /var/run/haproxy.pid #pid文件存放位置
maxconn 4000 #最大鏈接數
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 #詳細記錄http日誌
option dontlognull #不記錄健康檢查的日誌信息
option http-server-close #啓用服務器端主動關閉
option forwardfor except 127.0.0.0/8 #傳遞客戶端IP
option redispatch #serverId對應的服務器掛掉後,強制定向到其餘健康的服務器
retries 3 #請求重試次數
timeout http-request 10s #http請求超時時間
timeout queue 1m #一個請求在隊列裏的超時時間
timeout connect 10s #鏈接服務器超時時間
timeout client 1m #客戶端超時時間
timeout server 1m #客戶端超時時間
timeout http-keep-alive 10s #持久鏈接超時時間
timeout check 10s #心跳檢測超市時間
maxconn 3000 #最大鏈接數
#---------------------------------------------------------------------
# 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 #調用後端服務器並檢查ACL規則是否被匹配
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 #監聽地址
stats enable #啓用狀態監控
stats auth admin:admin #驗證的用戶與密碼
stats uri /admin?status #訪問路徑
stats hide-version #隱藏狀態頁面版本號
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次正確認爲服務器可用
#fall3 3次失敗認爲服務器不可用php