1/05/2007

[整理] Windows 上面跑 Apache 2.2 + Mongrel

Windows 上面 Ruby 效能不佳,所以我曾經建議不使用 Windows 作為 Service 環境。但是如果你真的要用 Windows 作為 Server ,你可以看這一篇。

不過請注意,我在之前就講過,我沒有 Windows 可以測試,只能整理別人的文章。尤其參考最多的是 Robbin 寫的 在Windows平台使用Apache2.2和Mongrel运行Ruby on Rails,雖然沒有照著翻譯,但是你依舊可以視這篇文章為 Robbin 本文的繁體中文整理翻譯版,榮耀是歸於 Robbin 的。

安裝 Ruby on Rails and Mongrel
下載Windows版的Ruby來安裝,安裝時請記得裝 RubyGems。再來請用 gem 安裝下列三個套件
gem i rails mongrel mongrel_service –y
啟動 mongrel_service
mongrel_service 就是 Windows 上面 Win32 Service 的 plugin。我們要先將 Mongrel 登記為其中一個 Windows Service。
mongrel_rails service::install -N service_name -c c:\rails\service -p 3000 –e production
  • -N :win32 service 名字
  • -c:Rails 程式 root 目錄
  • -p:聽的 port
  • -e:Rails 環境
仔細去看Win32 的service list,你會發現出現了一個你剛剛登記的 service_name。啟動的話就是
mongrel_rails service::start -N service_name
停止就是
mongrel_rails service::stop -N service_name
取消 service 登記就是
mongrel_rails service::remove -N service_name
如果你想 Windows 啟動,自動啟動 Mongrel Service,請按下
sc config service_name start= auto
如果你想說順便一起啟動 Mongrel Service 跟 MySQL,請按下
sc config service_name start= auto dependency= MySql

Mongrel_cluster ?
大家一定很懷念 Mongrel Cluster 這樣的神兵利器吧,很可惜,Windows 上面沒有 Mongrel Cluster,所以大家要啟動 3000 ~ 3009 就得這樣搞
mongrel_rails service::install -N service_name1 -p 3000 –e production
mongrel_rails service::install -N service_name2 -p 3001 –e production
mongrel_rails service::install -N service_name3 -p 3002 –e production
...
mongrel_rails service::install -N service_name4 -p 3009 –e production
笨嗎?蠢嗎?所以才跟你說 Ruby on Rails 不適合用 Windows 咩。
安裝 Apache 2.2
去 Apache 網站下載 Apache 2.2 Windows 版本。然後在httpd.conf enable module
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
使用 config file 就如同我這個網頁寫的方式,或是直接看 Robbin 寫的也可以。


延伸閱讀


沒有留言: