mongrelをインストールしてみる
mongrelはRailsを早く走らせてくれるWebサーバらしい。ちょっと試してみる。
まず、mongrelはスレッド起動などが無いため、1ポート1プロセス。インターネットサービスとしては使えません。なので、後述するmongrel_cluster+Apache mod_proxyと併用します。
# rdocをインストールしてない人は
yum -y install rdoc
# mongrelのインストール
gem install mongrel --include-dependencies
cd RAILS_ROOT
mongrel_rails start -d development -p 3000 -B
mongrel_rails stop
とりあえず、これで動きます。-Bを付けるとデバッグモードです。これつけるとかなり遅い。
次にmongrel_clusterのインストール。
gem install mongrel_cluster --include-dependencies
cd RAILS_ROOT
mongrel_rails cluster::configure -e production -p 4000 -N 3
mongrel_rails cluster::start
mongrel_rails cluster::stop
一度設定ファイル(config/mongrel_cluster.yml)を作るようです。上記だとproductionに対してポート4000-4002で起動できるようになりました。この時点では、単に複数ポートでmongrelが起動しているだけなので、ロードバランスさせる必要があります。それはapacheのmod_proxyで実現。mod_proxyやらmod_proxy_balancerなどのインストールは割愛。
conf.d/proxy.conf
<VirtualHost *:12400>
ServerName mongrel.localhost:80
# アクセスログ、エラーログの出力先
CustomLog logs/proxy_access_log combined
ErrorLog logs/proxy_error_log
# リバース・プロキシの設定
ProxyPass / balancer://mongrel/ stickysession=jsessionid nofailover=On
ProxyPassReverse / balancer://mongrel/
<Proxy balancer://mongrel>
BalancerMember http://mongrel.localhost:4000
BalancerMember http://mongrel.localhost:4001
BalancerMember http://mongrel.localhost:4002
</Proxy>
</VirtualHost>
このファイルをhttpd.confでインクルードします。
ちなみに、mongrel(マングレル、モングレル)とは雑種とか混血という意味。
@ Nowhere Near - Mongrel を使ってみる
by etrojan2006 | 2007-08-15 18:24 | Ruby

