經(jīng)過(guò)上一篇的
Mongrel Cluster ,我們可以發(fā)現(xiàn)到我們已經(jīng)可以配置 Mongrel Cluster,再來(lái)的問(wèn)題就是如何使用他?有鑑於之前寫(xiě)過(guò)的
Lighttpd mod_proxy_core 的歷史,我們使用 Lighttpd mod_proxy_core 來(lái)使用 Mongrel Cluster。
首先,先配置 Mongrel Cluster 在本機(jī)端
mongrel_rails cluster::configure \
-e production \
-p 8000 \
-N 3 \
-c /var/www/servers/ \
-a 127.0.0.1 \
--user mongrel \
--group mongrel
- -e :代表啟動(dòng)那個(gè)環(huán)境,這裡是 production 環(huán)境
- -p :代表開(kāi)始從那個(gè) port 開(kāi)始 listen,這裡是 8000
- -N :代表一次 cluster 啟動(dòng)幾個(gè) Mongrel,這裡是三個(gè)
- -c :代表 Mongrel 啟動(dòng)那個(gè)目錄
- -a :代表 listen 在那個(gè) ip
- --user :代表以那個(gè) user 啟動(dòng) Mongrel
- --group :代表以那個(gè) group 開(kāi)始啟動(dòng)
我們啟動(dòng)了三個(gè) Mongrel Cluster,並且 Listen 8000 , 8001 , 8002 port。然後下載
這份 Lighttpd trunk (預(yù)計(jì)會(huì)在 1.5 放入 Lighttpd )
./configure && make && make install
再來(lái),將 lighttpd.conf 加入
server.modules = ( ..... , "mod_proxy_core" , ....)
並將在 lightppd.conf 寫(xiě)入下列的設(shè)定
$HTTP["host"] == "domain.example.com" {
proxy-core.balancer = "round-robin"
proxy-core.protocol = "http"
proxy-core.backends = ( "127.0.0.1:8000", "127.0.0.1:8001" , "127.0.0.1:8002")
}
proxy-core.balancer 代表的意思是如何去分配的 ,一共有 hash, fair, rr 三個(gè) balancer。剩下的都很好看懂吧。
最後重起 lighttpd 即可,這裡的 mod_proxy_core 主要是作 reverse_proxy 的工作
參考連結(jié)
- Rails, Mongrel, Lighty and Mint
- PRE-RELEASE: lighttpd-1.5.0-r1454.tar.gz
- mod-proxy-core and SQF
- Lighttpd 1.5 + Linux Async IO