---
title: "Fedora Core 6 上安裝 beast (2)"
author: "thegiive"
date: "2007-08-15T13:16:53Z"
tags: []
slug: "fedora-core-6-beast-2"
draft: false
lastmod: "2007-08-15T13:16:53Z"
id: 112709
url: "https://thegiive.iteye.com/blog/112709"
---

不喜歡 apache 嗎？apache 沒辦法用 mod\_proxy\_balancer 嗎？沒關係，我找到另外一個不錯的方式了，是 pound + lighttpd. 如果不想用 apache 的話，上一篇的 httpd 相關的東西都不要灌，改灌：

sudo yum install Pound  
sudo yum install lighttpd

我是覺得這邊分大小寫很沒意義，不過 yum 就是這樣﹍。

pound 是什麼？  
The Pound program is a reverse proxy, load balancer and HTTPS front-end for  
Web server(s). Pound was developed to enable distributing the load among  
several Web-servers and to allow for a convenient SSL wrapper for those  
Web servers that do not offer it natively.

lighttpd 我想大家都知道，一個非常快速的 http server, 只不過他的 mod\_proxy 似乎有很多問題，以致於沒辦法用他。所以這部份用 pound 當前端解決這個問題，流程變成：

http request =&gt; pound =&gt; lighttpd or mongrel cluster

安裝好後，先來設定 pound, 不過 https 就先暫時略過不管。  
sudo nano /etc/pound.cfg  
\=========================  
User "pound"  
Group "pound"

ListenHTTP  
    Address 0.0.0.0  
    Port 80  
End

Service  
    URL "/(images|stylesheets|javascripts)/"  
    BackEnd  
        Address 127.0.0.1  
        Port    1999  
    End  
    Session  
        Type    BASIC  
        TTL     300  
    End  
End

Service  
    BackEnd  
        Address 127.0.0.1  
        Port    2000  
    End  
    BackEnd  
        Address 127.0.0.1  
        Port    2001  
    End  
    BackEnd  
        Address 127.0.0.1  
        Port    2002  
    End  
    Session  
        Type    BASIC  
        TTL     300  
    End  
End  
\=========================  
前面的設定是把 host/images, host/stylesheets, host/javascripts 這三個 url 下的 request 都丟給 port 1999 處理，也就是等會 lighttpd 要使用的 port. 這邊使用 regex, 可以自由設定自己要的規則。假使未來 user 要使用 file\_column, 可以再加個 user/avatar 之類的。

下面的則是全部丟給 mongrel\_cluster 處理。設定上應該比 apache 簡單地多。可以先測試看看，先把 lighttpd 的部份 comment 起來，啟動 pound 試試：  
sudo pound

照理說這樣就能使用了。不行的話加個 config 檔路徑給他：  
sudo pound -f /etc/pound.cfg

這邊我是在想要不要把 config 也放到 beast 裡面，不過 pound 應該只會有一個，所以我想還是放到 /etc 下好了。停止 pound 的方式：  
sudo kill \`sudo cat /var/run/pound.pid\`

製作 lighttpd 設定檔：  
nano config/lighttpd.conf  
\==========================  
server.modules = (  
"mod\_access",  
"mod\_accesslog"  
)

server.port = 1999  
server.bind = "127.0.0.1"  
server.document-root = "/home/YOUR\_NAME/projects/beast/stable-1.0/public"

server.username = "YOUR\_NAME"  
server.groupname = "YOUR\_NAME"  
server.pid-file = "/home/YOUR\_NAME/projects/beast/stable-1.0/tmp/pids/lighttpd.pid"  
server.errorlog = "/home/YOUR\_NAME/projects/beast/stable-1.0/log/lighttpd\_error.log"  
index-file.names = ( "index.html", "default.html" )  
accesslog.filename = "/home/YOUR\_NAME/projects/beast/stable-1.0/log/lighttpd\_access.log"

\# mimetype mapping  
mimetype.assign = (  
".rpm" =&gt; "application/x-rpm",  
".pdf" =&gt; "application/pdf",  
".sig" =&gt; "application/pgp-signature",  
".spl" =&gt; "application/futuresplash",  
".class" =&gt; "application/octet-stream",  
".ps" =&gt; "application/postscript",  
".torrent" =&gt; "application/x-bittorrent",  
".dvi" =&gt; "application/x-dvi",  
".gz" =&gt; "application/x-gzip",  
".pac" =&gt; "application/x-ns-proxy-autoconfig",  
".swf" =&gt; "application/x-shockwave-flash",  
".tar.gz" =&gt; "application/x-tgz",  
".tgz" =&gt; "application/x-tgz",  
".tar" =&gt; "application/x-tar",  
".zip" =&gt; "application/zip",  
".mp3" =&gt; "audio/mpeg",  
".m3u" =&gt; "audio/x-mpegurl",  
".wma" =&gt; "audio/x-ms-wma",  
".wax" =&gt; "audio/x-ms-wax",  
".ogg" =&gt; "application/ogg",  
".wav" =&gt; "audio/x-wav",  
".gif" =&gt; "image/gif",  
".jpg" =&gt; "image/jpeg",  
".jpeg" =&gt; "image/jpeg",  
".png" =&gt; "image/png",  
".xbm" =&gt; "image/x-xbitmap",  
".xpm" =&gt; "image/x-xpixmap",  
".xwd" =&gt; "image/x-xwindowdump",  
".css" =&gt; "text/css",  
".html" =&gt; "text/html",  
".htm" =&gt; "text/html",  
".js" =&gt; "text/javascript",  
".asc" =&gt; "text/plain",  
".c" =&gt; "text/plain",  
".cpp" =&gt; "text/plain",  
".log" =&gt; "text/plain",  
".conf" =&gt; "text/plain",  
".text" =&gt; "text/plain",  
".txt" =&gt; "text/plain",  
".dtd" =&gt; "text/xml",  
".xml" =&gt; "text/xml",  
".mpeg" =&gt; "video/mpeg",  
".mpg" =&gt; "video/mpeg",  
".mov" =&gt; "video/quicktime",  
".qt" =&gt; "video/quicktime",  
".avi" =&gt; "video/x-msvideo",  
".asf" =&gt; "video/x-ms-asf",  
".asx" =&gt; "video/x-ms-asf",  
".wmv" =&gt; "video/x-ms-wmv",  
".bz2" =&gt; "application/x-bzip",  
".tbz" =&gt; "application/x-bzip-compressed-tar",  
".tar.bz2" =&gt; "application/x-bzip-compressed-tar"  
)  
\==========================  
我很想省略 mime-type 設定，不過不設的話 firefox 好像會有問題。safari 和 opera 是 ok 的，IE 我沒得測就沒測了。反正要設就是了，有沒有問題不影響。只是希望 lighttpd 能內建這些設定﹍。

啟動 lighttpd  
sudo lighttpd -f config/lighttpd.conf

這樣就算大功告成了！剛剛有測試 pound 的話記得改回原本設定並重新啟動。比較詳細的介紹與說明可以參考這篇：  
[Configuring pound with lighttpd and mongrel.](http://www.aidanf.net/rails/configuring-pound-with-lighttpd-and-mongrel)

\*

summary:

用到的 server:

(1)  
apache2.2 =&gt;  
reverse proxy + load balancer + serve static files

(2)  
pound =&gt; reverse proxy + load balancer  
lighttpd =&gt; serve static files

(3)  
mongrel\_cluster =&gt; setup mongrel cluster  
mongrel =&gt; serve beast

結果就是 ((1) or (2)) + (3)

操作 apache:  
啟動：sudo apachectl start  
停止：sudo apachectl stop  
重啟：sudo apachectl restart

操作 pound:  
啟動：sudo pound -f /etc/pound.cfg  
　或：sudo /etc/init.d/pound start

停止：sudo kill \`sudo cat /var/run/pound.pid\`  
　或：sudo /etc/init.d/pound stop

重啟：sudo /etc/init.d/pound restart

操作 lighttpd:  
啟動：sudo lighttpd -f config/lighttpd.conf  
　或：sudo /etc/init.d/lighttpd start

停止：sudo kill \`cat tmp/pids/lighttpd.pid\`  
　或：sudo /etc/init.d/lighttpd stop

重啟：sudo /etc/init.d/lighttpd restart

操作 mongrel\_cluster:  
啟動：sudo mongrel\_rails cluster::start  
停止：sudo mongrel\_rails cluster::stop  
重啟：sudo mongrel\_rails cluster::restart

操作 postgresql:  
啟動：sudo pg\_ctl start  
停止：sudo pg\_ctl stop  
重啟：sudo pg\_ctl restart