數位天堂

Nokia:科技始終來自於人性; 拜耳:如果文明不能使我們更相愛,那科技便失去意義!
歡迎您的加入,讓我們一起討論科技與環保的整合應用...

您尚未登入。

#1 2010-10-26 23:53:05

Aven
天使
來自: 數位天堂
註冊日期: 2007-07-15
文章數: 2266
網站

簡單好用的 Server Load Balancer - HAProxy

最近因客戶需求,需要SLB(Server Load Balancer),所以花了一點時間研究SLB,原來在Optware裡就有一套免費的SLB - HAProxy。雖然免錢,但是該有的功能都沒少,例如可以設定後端 Server 數量,要多久去檢查一次 Server 是否掛點,可設定檢查的方式(路徑? 檔案?),若 Server 已經掛點就可以馬上將此機器從服務中抽離,只要 Server 恢復運作,將會自動回復服務,最重要的是還可提供即時統計報表。

HAProxy基本架構如下,當外部 User 對 Web 主機發出連線需求,HAProxy 可依據設定的權重,將此連線需求重新分配給底下的三台 Web Server,以達到負載平衡的功效。
http://lh6.ggpht.com/_1iLUH2gfDEw/TG0PggZC_MI/AAAAAAAADLY/v03_EAOcv0s/image_thumb%5B3%5D.png?imgmax=800

底下開始安裝流程:

$ ipkg install haproxy Installing haproxy (1.4.8-1) to /opt/... Downloading http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable/haproxy_1.4.8-1_mipsel.ipk Installing pcre (8.10-1) to /opt/... Downloading http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable/pcre_8.10-1_mipsel.ipk Configuring haproxy Configuring pcre Successfully terminated.


安裝完畢馬上執行看看,若出現如下錯誤訊息

$ haproxy haproxy: can't load library 'libuClibc++.so.0'


那就表示有缺少 libuClibc++ 函示庫,須另外安裝。

$ ipkg list | grep uclib libuclibc++ - 0.2.2-9 - C++ standard library designed for use in embedded systems uclibc-opt - 0.9.28-13 - micro C library for embedded Linux systems $ ipkg install libuclibc++ Installing libuclibc++ (0.2.2-9) to /opt/... Downloading http://ipkg.nslu2-linux.org/feeds/optware/oleg/cross/stable/libuclibc++_0.2.2-9_mipsel.ipk Configuring libuclibc++ Successfully terminated.


再執行看看,已經正常了

$ haproxy HA-Proxy version 1.4.8 2010/06/16 Copyright 2000-2010 Willy Tarreau Usage : haproxy [-f ]* [ -vdVD ] [ -n ] [ -N ] [ -p ] [ -m ] -v displays version ; -vv shows known build options. -d enters debug mode ; -db only disables background mode. -V enters verbose mode (disables quiet mode) -D goes daemon -q quiet mode : don't display messages -c check mode : only check config files and exit -n sets the maximum total # of connections (2000) -m limits the usable amount of memory (in MB) -N sets the default, per-proxy maximum # of connections (2000) -p writes pids of all children to this file -dp disables poll() usage even when available -sf/-st [pid ]* finishes/terminates old pids. Must be last arguments.


再來就是編輯 config 檔

$ nano /opt/etc/haproxy/haproxy.cfg


內容請參考官網設定

# # /opt/etc/haproxy/haproxy.conf # global maxconn 32768 user nobody group nobody daemon nbproc 8 listen web-balancer bind 192.168.2.110:80 mode http balance roundrobin maxconn 32768 clitimeout 60000 srvtimeout 60000 contimeout 5000 retries 3 server web1 192.168.1.1 weight 3 check server web2 192.168.1.2 weight 3 check server web3 192.168.1.3 weight 3 check option forwardfor option httpclose option redispatch option dontlognull #Stats page eg http://ip:port/haproxy?stats stats enable stats hide-version stats refresh 30s stats show-node stats show-legends stats auth root:haproxy stats uri /haproxy?stats


寫好 config,先用 debug mode 確認一下是否有錯誤訊息

$ haproxy -d -f /opt/etc/haproxy/haproxy.cfg


若OK的話,可以把 -d 拿掉變成 daemon mode
而底下是即時統計圖,可以看到 HAProxy 流量分派的實際狀況,小小一台 WL-500 竟然可以取代幾十萬的 SLB 機器,爽度100 milk
https://digiland.tw/uploads/2_haproxy_stats.gif

參考資料:
http://haproxy.1wt.eu/
部份圖片取自:
http://hankycheng.blogspot.com/2010/08/ … lance.html





技術問題請於論壇上集眾人之力公開討論,感恩 thankgod

離線

 

#2 2010-10-27 12:22:56

oldhan
精靈
註冊日期: 2007-11-19
文章數: 133
目前積分 :   

Re: 簡單好用的 Server Load Balancer - HAProxy

不錯喔, 開站的人如果有用 freenas 的話, 把一些 http 的服務搶過來減輕 wl500 系列分享器的負擔.
milk



離線

 

#3 2010-10-27 23:26:38

Aven
天使
來自: 數位天堂
註冊日期: 2007-07-15
文章數: 2266
網站

Re: 簡單好用的 Server Load Balancer - HAProxy

oldhan 提到:

不錯喔, 開站的人如果有用 freenas 的話, 把一些 http 的服務搶過來減輕 wl500 系列分享器的負擔.
milk

現在大部分 Web 服務都會牽涉到資料庫,所以本篇只做到前端的流量分流,還須考量後端有資料庫同步的問題,這樣系統才完整,這部份留待日後再立主題討論。



技術問題請於論壇上集眾人之力公開討論,感恩 thankgod

離線

 

相關討論主題

主題 回覆 點閱 最後發表
0 2787 2020-04-08 00:39:39 作者 chengsheng16
3 11869 2016-06-17 11:52:43 作者 join600
[DD-WRT] PPTP VPN server 作者 hippo  [ 1 2 3 ]
28 187823 2016-04-27 16:52:53 作者 kevin1412
7 25146 2015-01-21 22:29:58 作者 allengran
N10U+USB PRINT SERVER 作者 monok
0 6097 2014-04-23 01:18:51 作者 monok

友情連結

論壇頁尾

Powered by PunBB
© Copyright 2018 Rickard Andersson
RSS Feed