Pound+Mongrel+Lighttpdで安定で高速なRails環境を実現する。

筆者の環境で、Apache+FastCGI(mod_fastcgi/mod_fcgid)がちょくちょく落ちるので、構成を換えてみた。
以降、落ちることもなく安定しているので公開。

ポイント

  • mongrel_clusterで並列化(サーバ自体は1台なので負荷分散ってわけではない)
    • どれかのプロセスが死んでも安心。冗長化
    • ついでに起動スクリプトを書いとけばサービスとして扱えて便利。
  • 静的ファイルは軽量・高速と評判なLighttpd
  • ロードバランサ兼リバースプロキシはPound

サーバ

mongrel_cluster

Pound

ソースRPMを拾ってきてビルドした。

cd /usr/src/redhat/SRPMS
wget http://www.invoca.ch/pub/packages/pound/pound-2.3.2-2.src.rpm
rpm -ihv pound-2.3.2-2.src.rpm
cd ../SPECS
rpmbuild -bb pound.spec
cd ../RPMS/i386
rpm -ihv pound-2.3.2-2.i386.rpm

設定は、
/etc/pound/pound.cfg で行う。

# グローバル定義
User "pound"
Group "pound"
LogLevel 0
Alive 60

# リスナー定義
ListenHTTP
        Address 121.119.183.55
        Port 80
End
ListenHTTPS
        Address 121.119.183.55
        Port 443
        Cert "/usr/local/certs/pound.pem"
End

# 静的コンテンツはLighttpdで。
Service
        URL "/(images|javascripts|stylesheets)/.*"
        BackEnd
                Address 127.0.0.1
                Port 8001
        End
End

# Rails
Service
        BackEnd
                Address 127.0.0.1
                Port 8100
        End
        BackEnd
                Address 127.0.0.1
                Port 8101
        End
End