Ubutun 安裝
#ubuntu 14.04LTS
add-apt-repository ppa:vbernat/haproxy-1.7
apt-get update
apt-get dist-upgrade
apt-get install haproxy
mac 安裝
brew install haproxy
#運(yùn)行 `haproxy -f /usr/local/Cellar/haproxy/1.6.6/haproxy.cfg -d`
配置文件
global
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
timeout connect 5000
timeout client 10000
frontend localnodes
bind *:4000
mode tcp
default_backend nodes
timeout client 1m
backend nodes
mode tcp
balance leastconn
server web01 127.0.0.1:4001 check
server web02 127.0.0.1:4002 check
timeout connect 10s
timeout server 1m
- check 表示 haproxy 會(huì)對(duì)后臺(tái)的 server 做健康檢查,一旦發(fā)現(xiàn)離線就不往這個(gè)節(jié)點(diǎn)發(fā)信息了
- balance leastconn 表示負(fù)載策略是 最小連接數(shù)
- 參考 How To Use HAProxy to Set Up HTTP Load Balancing on an Ubuntu VPS
- maxconn 的默認(rèn)值是2000
timeout client 10000 指的是如果 10000ms 以?xún)?nèi)沒(méi)有進(jìn)行通訊,tcp 連接將重置