`

Fedora Core 6 上安裝 beast (2)

阅读更多
不喜歡 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 => pound => 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" => "application/x-rpm",
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "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.

*

summary:

用到的 server:

(1)
apache2.2 =>
reverse proxy + load balancer + serve static files

(2)
pound => reverse proxy + load balancer
lighttpd => serve static files

(3)
mongrel_cluster => setup mongrel cluster
mongrel => 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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics