burn baby burn!!!

マンチェスター・ユナイテッド?なにそれ、いくら? ー M.ジャクソン

【Rails】mongrel cluster&apacheのリバースプロキシで複数のアプリ共存

Railsアプリを一つのサーバで複数立ち上げたい、しかも各アプリをクラスタリングしたい、ということで調べてみたことをまとめます。

少ない投資でプロトタイプやβサービスをいろいろ作りたいときに必要なネタだと思います。

以下の内容についてはapacheのmod_proxy、mod_proxy_balancerが有効になっていることが前提です。またパスは環境によって異なると思いますので参考までに。

備忘録兼ねてますので途中の冗長な作業も書いてますがあしからず、です。

■apacheのリバースプロキシの設定

/etc/httpd/conf.d/のproxy.confの内容を以下のように変更します(ファイルがなければ作成)。

# cd /etc/httpd/conf.d/
# vi proxy.conf

ProxyRequests Off
<proxy *>
Order deny,allow
Allow from all
</proxy>

ProxyPass /myapp1 balancer://mycluster1 lbmethod=byrequests
ProxyPassReverse /myapp1 balancer://mycluster1
<proxy balancer://mycluster1>
BalancerMember http://127.0.0.1:3000/myapp1 loadfactor=10
BalancerMember http://127.0.0.1:3001/myapp1 loadfactor=10
BalancerMember http://127.0.0.1:3002/myapp1 loadfactor=10
</proxy>

ProxyPass /myapp2 balancer://mycluster2 lbmethod=byrequests
ProxyPassReverse /myapp2 balancer://mycluster2
<proxy balancer://mycluster2>
BalancerMember http://127.0.0.1:4000/myapp2 loadfactor=10
BalancerMember http://127.0.0.1:4001/myapp2 loadfactor=10
BalancerMember http://127.0.0.1:4002/myapp2 loadfactor=10
</proxy>

#ロードバランス管理画面の設定
<location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from *.*. #管理画面を使用するクライアントやネットワークを指定
</location>

これでmyapp1とmyapp2という二つのRailsアプリをそれぞれクラスタリングした状態でたてられます。

ポート80で入った要求を、/myapp1ならポート3000〜3002に /myapp2ならポート4000〜4002に振り分けてやる訳です。

※上の設定の場合、ロードバランサーの管理画面のURLは http://hoge/balancer-manager となります。

proxy.confを修正したら設定を反映するためにapacheを再起動します。

# cd /etc/rc.d/init.d
# ./httpd restart

■mongrelのクラスター起動

# cd hoge/myapp1
# mongrel_rails cluster::configure -e production -p 3000 -N 3 –prefix /myapp1
# mongrel_rails cluster::start

# cd hoge/myapp2
# mongrel_rails cluster::configure -e production -p 4000 -N 3 –prefix /myapp2
# mongrel_rails cluster::start

※停止の時は mongrel_rails cluster::stop

—rabbitonigiri
(posted in the Ruby on Rails category)

このエントリをdel.icio.usに追加このエントリをはてなブックマークに追加

Find this post interesting? Besides commenting below, you can follow responses with the RSS 2.0 feed or trackback from your own site.


2 Responses to “【Rails】mongrel cluster&apacheのリバースプロキシで複数のアプリ共存”

  1. maru says:
    2月 29, 2008, 3:33:08

    あん。
    –prefix /myapp1
    じゃん
    -prefix /myapp1
    じゃなくて。

    バージョン違いのせいかなー?

  2. toyosystem | Rails+Capistrano+Apache2.2+Mongrel_clusterのメモ says:
    10月 17, 2008, 18:50:32

    […] burn baby burn!!!(Archives) 【Rails】mongrel cluster&apacheのリバースプロキシで複数のアプリ共存 […]


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Starburst Theme designed by Claire
powered by WordPress ME2.0.3 | valid XHTML and CSS