#1 2010-10-26 23:53:05
簡單好用的 Server Load Balancer - HAProxy
最近因客戶需求,需要SLB(Server Load Balancer),所以花了一點時間研究SLB,原來在Optware裡就有一套免費的SLB - HAProxy。雖然免錢,但是該有的功能都沒少,例如可以設定後端 Server 數量,要多久去檢查一次 Server 是否掛點,可設定檢查的方式(路徑? 檔案?),若 Server 已經掛點就可以馬上將此機器從服務中抽離,只要 Server 恢復運作,將會自動回復服務,最重要的是還可提供即時統計報表。
HAProxy基本架構如下,當外部 User 對 Web 主機發出連線需求,HAProxy 可依據設定的權重,將此連線需求重新分配給底下的三台 Web Server,以達到負載平衡的功效。
底下開始安裝流程:
$ 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 

參考資料:
http://haproxy.1wt.eu/
部份圖片取自:
http://hankycheng.blogspot.com/2010/08/ … lance.html
技術問題請於論壇上集眾人之力公開討論,感恩

離線
相關討論主題
| 主題 | 回覆 | 點閱 | 最後發表 | 
|---|---|---|---|
| 
                                請問 tomato 有沒有辦法架 內網ppoe Server 嗎? 作者 chengsheng16
                             | 0 | 4209 | 2020-04-08 00:39:39 作者 chengsheng16 | 
| 3 | 14802 | 2016-06-17 11:52:43 作者 join600 | |
|  | 28 | 207130 | 2016-04-27 16:52:53 作者 kevin1412 | 
| 
                                一個好用的軟體--VirtualHere USB server 作者 allengran
                             | 7 | 31083 | 2015-01-21 22:29:58 作者 allengran | 
| 
                                N10U+USB PRINT SERVER 作者 monok
                             | 0 | 7449 | 2014-04-23 01:18:51 作者 monok | 











