顯示包含「mongrel」標籤的文章。顯示所有文章
顯示包含「mongrel」標籤的文章。顯示所有文章

星期一, 3月 26, 2007

Apache 2.2 + Mongrel 設定方式

設定 Mongrel Cluster

請將你的 Mongrel Cluster 設定好,這裡預設 port 從 4000 ~ 4009 ,一共十個,跑在 production 環境下

mongrel_rails cluster::configure -e production -p 4000 -N 10
mongrel_rails cluster::start
修改 Apache 2.2 設定檔

Apache 的設定檔放在 httpd.conf ,以下修改內容皆在 httpd.conf 裡面設定。

首先確定你的 Apach 2.2 有 enable apache 的其中一個 Module mod_proxy
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
再來我們開始設定 Mongrel Cluster 的 reverse proxy 設定,首先我們給這組 cluster 取名叫做 examplecluster,他是10組 Mongrel ,跑在 port 4000 ~ 4009 之中

# cluster member 1
BalancerMember http://127.0.0.1:4000
BalancerMember http://127.0.0.1:4001
....
BalancerMember http://127.0.0.1:4009
再來假設你的 hostname 為 example.com,我們開始設定 virtual host

ServerName example.com
ServerAdmin root@example.com
DocumentRoot "/var/www/example.com/htdocs"
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !
ProxyPass / balancer://examplecluster/
ProxyPassReverse / balancer://examplecluster/


重 點是在於 ProxyPass,ProxyPass 代表 images,stylesheets,javascript 等 static file 交給 Apache 處理,不要給 Mongrel 處理。 還有 ProxyPassReverse 要指定正確的 cluster name ,我們要指定為 examplecluster。

最後重起 Apache 即可。本設定改自著名的文章 Scaling Rails with Apache 2.2, mod_proxy_balancer and Mongrel,還有 Robin 的 在Windows平台使用Apache2.2和Mongrel运行Ruby on Rails。設定是在 Gentoo Linux + Apache 2.2.3 + Mongrel 跑完全沒有任何問題。

[via: http://lightyror.thegiive.net/2006/12/apache-22-mongrel.html]

Mongrel 使用方式 Part 2 : Mongrel Cluster

看完上一篇,大家一定很想丟雞蛋
這樣的 tutorial 也可以出來混一篇文章
在大家浪費買蛋錢之前,我必須要說,好戲在後頭呀!!!
Mongrel 如果只有單獨啟動在 80 port
他充其量不過是一個速度較普普的 Web Server
但是,當作 Backend Application Server 才是他的宿命呀

今天的需求是這樣
我們可以開啟數個 Mongrel Process 在其他 port
前端開一個 Proxy Server
當 Proxy Server 接受到 request
他會傳給 backend application server
其實作法很像 Mod_fastcgi 的作法
只是中間的 application server 將 fastcgi 改成了 mongrel

如果要開啟眾多的 Mongrel Process
我們當然可以用

mongrel_rails start -d -p 8000 -P log/mongrel_1.pid
mongrel_rails start -d -p 8001 -P log/mongrel_2.pid
....
這樣來執行,但是要管理就變得相當的麻煩
不但要一一起動,要關掉或是重起的變得相當麻煩
如果 Mongrel 那麼麻煩的話
那我們還搞屁,直接用 fastcgi 就好啦 XD
這時候請用 mongrel cluster
有了他,Mongrel 才變成簡單好用的 Application Server

安裝方式
gem i mongrel_cluster
即可

設定方式
一開始,請到 Ruby on Rails 的根目錄
先設定 Mongrel 的設定檔
mongrel_rails cluster::configure -e 那些環境 \
-p 8000 \
-N 3 \
-c /var/www/servers/ \
-a 127.0.0.1 \
--user mongrel \
--group mongrel
他會將 config 寫到 config/database.yml
我解釋一下選項
  • -e 就是用那個環境啟動(production/development/test)
  • -p 就是用那個 port 開始
  • -N 就是開啟幾個 process
  • -c 就是先切到那個目錄,再執行 mongrel cluster (通常是這個Ruby on Rails 的根目錄)
  • -a 就是在那個 host 啟動
  • --user 就是以那個 user 身份啟動
  • --group 就是以那個 group 啟動

如果設定好後,以後使用 mongrel_rails cluster::start 他就會立刻使用剛剛的設定檔
這裡要注意的是 -N 跟 -p 的選項
假設 -p = 8000 -N 為 3
那他會開啟三個mongrel process ,分別以 8000 , 8001 , 8002 來聽
其實 -p 8000 -N 3
就跟
mongrel_rails start -d -p 8000 -P log/mongrel_1.pid
mongrel_rails start -d -p 8001 -P log/mongrel_2.pid
mongrel_rails start -d -p 8002 -P log/mongrel_3.pid
一樣的意義

以此類推假設 -p = 7000 -N 為 5
那他會開啟五個mongrel process ,分別以 7000 , 7001 , 7002 , 7003 , 7004 來聽

使用方式
啟動方式
mongrel_rails cluster::start

關閉方式
mongrel_rails cluster::stop

重起方式
mongrel_rails cluster::restart

參考連結
  1. Rails, Mongrel, Lighty and Mint

[via: http://lightyror.thegiive.net/2006/10/mongrel-part-2-mongrel-cluster.html]

Mongrel 使用方式

Ruby on Rails 架設一直有一個問題
找不到適當的 Application Server
Webricks 太慢,fastcgi 太玄妙,scgi 太年輕
這個時候
只有 Mongrel 可以拯救世界呀~~~~

Mongrel 首頁是這樣寫的

Mongrel is a fast HTTP library and server for Ruby that is intended for hosting Ruby web applications of any kind using plain HTTP rather than FastCGI or SCGI. It is framework agnostic and already supports Ruby On Rails, Og+Nitro, and Camping frameworks.
他跟Webricks 一樣,是一個方便我們架設 Ruby on Rails 環境的網頁伺服器
並且他比 Webricks 還要來得快速

安裝方式很簡單
gem i mongrel
使用方式呢,基本上跟 Webrick 差不多
到 Rails 根目錄
打入
mongrel_rails start
你就會發現他已經可以使用了

如果要用 deamon 模式來使用的話
打入
mongrel_rails start -d
即可

如果要使用特定的 port
mongrel_rails start -p 1234
即可

用不同環境啟動
mongrel_rails start -e production/development/test
即可

指定log file
mongrel_rails start -l log/mongrel_log
即可

有啟動的問題
mongrel_rails start -h
即可

重起 Mongrel
mongrel_rails restart

停止 Mongrel
mongrel_rails stop

[via: http://lightyror.thegiive.net/2006/10/mongrel.html]