1.haproxy使用最須要注意的點:
1.1鏈接數:
前端maxconn默認值爲2000,很是有必要將其增長几倍。
1.2超時時間
timeout connect 60s # haproxy和服務端創建鏈接的最大時長,設置爲1秒就足夠了。局域網內創建鏈接通常都是瞬間的
參考:http://www.cnblogs.com/f-ck-need-u/p/8540805.html
frontend webserver
bind 0.0.0.0:80 #在本機的全部接口監聽訪問 80 端口的請求javascript
MySQL集羣在HAproxy以後運行,HAproxy對進來請求進行負載均衡,對外只暴露一個IP地址。css
haproxy反向代理設置:html
global
daemon
maxconn 25600
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:800
default_backend servers
backend servers
balance roundrobin #負載均衡模式輪詢
server server1 192.168.1.102:80 cookie A check
server server2 192.168.1.104:80 cookie B check前端
根據用戶訪問內容實現動靜分離:java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
frontend http-
in
bind *:80
mode http
log global
option httpclose
acl url_static path_beg -i /
static
/images /javascript /stylesheets
acl url_static path_end -i .jpg .jpeg .gif .png .css .js
use_backend static_servers
if
url_static
default_backend dynamic_servers
backend static_servers
balance roundrobin
server imgsrv1 172.18.64.7:80 check maxconn 6000
server imgsrv2 172.18.64.107:80 check maxconn 6000
backend dynamic_servers
balance source
server websrv1 172.18.64.17:80 check maxconn 1000
server websrv2 172.18.64.106:80 check maxconn 1000
|
http://www.cnblogs.com/heiye123/articles/7928292.htmlweb
################################################服務器
2.haproxy服務器自己只提供代理,沒有ssl證書 (通常咱們經常使用的就是這種方式)cookie
這種方式,haproxy不須要從新編譯支持ssl,簡單方便,只須要後面的web服務器配置好ssl便可。負載均衡
配置參數(修改haproxy.cfg文件)frontend
frontend https_frontend bind *:443 mode tcp default_backend web_server backend web_server mode tcp balance roundrobin stick-table type ip size 200k expire 30m stick on src server s1 192.168.1.150:443 server s2 192.168.1.151:443 --------------------------------------------------------- 注意,這種模式下mode 必須是tcp 模式 ---------------------------------------------------------
cp自http://www.mamicode.com/info-detail-1539510.html 和 http://www.javashuo.com/article/p-mnxvjzrf-kw.html