1.HAProxy Description
2. HAProxy架設
VIP:10.55.79.25
HAProxy Server1:10.55.79.153(Master)
HAProxy Server2:10.55.79.154(Slave)
Web Server1:10.55.78.178
Web Server2:10.55.78.179
net.ipv4.ip_nonlocal_bind=1
#sysctl –p
經測試:
haproxy-1.4.15.tar.gz & keepalived- 1.2.2 .tar.gz 可運作
haproxy-1.4.24.tar.gz & keepalived-1.2.8.tar.gz 可運作
make install PREFIX=/usr/local/haproxy
option httplog #日志類別http日志格式
option abortonclose #當服務器負載很高的時候,自動結束掉當前隊列處理比較久的連接
#balance leastconn #默認的負載均衡的方式,最小連接
log 127.0.0.1 local3 err #[err warning info debug]
server www1 10.55.78.178:80 check weight 1 inter 2000 rise 2 fall 3
server www2 10.55.78.179:80 check weight 1 inter 2000 rise 2 fall 3
#服務器定義,check inter 2000是檢測心跳頻率rise 3是3次正確認為服務器可用,
#fall 3是3次失敗認为服務器不可用,weight代表權重
#errorfile 403 /etc/haproxy/errorfiles/403.http
#errorfile 500 /etc/haproxy/errorfiles/500.http
#errorfile 502 /etc/haproxy/errorfiles/502.http
listen status_auth 10.55.79.153:81 #管理介面
stats enable
mode http
stats uri /admin-status #管理地址
stats auth admin:123456 #管理帐号:管理密码
stats admin if TRUE
listen status_auth 10.55.79.25:81 #VIP管理介面
mode http
stats uri /admin-status #管理地址
stats auth admin:123456 #管理帐号:管理密码
stats admin if TRUE
3. Syslog Setting
local3.* /var/log/haproxy.log
local0.* /var/log/haproxy.log
SYSLOGD_OPTIONS="-r -m 0"
#/etc/init.d/syslog restart
4. haproxy壓力測試
先進管理畫面,再確認最後狀態
5. Keepalive Setting
real_server 10.55.79.153 80 {
TCP_CHECK {
7. 開機啟動Script
8. Reference
一、
以上的設定在Real Server上看到的ip是帶HAProxy Server的ip,若要在Real Server 上看到實際連進來Client IP,需要Redhat 6.0以上,詳細資訊詳見以下的說明:
1.http://www.pigo.idv.tw/archives/989 -->中文
2.http://blog.loadbalancer.org/configure-haproxy-with-tproxy-kernel-for-full-transparent-proxy/ -->英文
http://rritw.com/a/bianchengyuyan/PHP/20130301/314828.html
一、roundrobin,表示簡單的輪詢;二、static-rr,表示根據權重;三、leastconn,表示最少連接者先處理;四、source,表示根據請求源IP;五、uri,表示根據請求的URI;六、url_param,表示根據請求的URl參數’balance url_param’ requires an URL parameter name七、hdr(name),表示根據HTTP請求頭來鎖定每一次HTTP請求;八、rdp-cookie(name),表示根據據cookie(name)來鎖定並哈希每一次TCP請求。
常用算法:roundrobin、source、lestconn。