mod_cluster+mongrelでサーバー環境構築手順

今回は手っ取り早くrootで動かしちゃうから権限周りは気にしない。


■サーバ環境
・CentOS5
・Ruby1.8.6


■アプリ
# /var/www/htdocs/testapp


mongrelmongrel_clusterをインストール
# gem install mongrel
# gem install mongrel_cluster


■pid生成ディレクトリを生成
# mkdir /var/run/mongrel
# chmod 775 /var/run/mongrel


mongrel設定ファイルを生成
# mkdir /etc/mongrel_cluster/testapp
# ln -s /var/www/htdocs/testapp/config/\
mongrel_cluster.yml /etc/mongrel_cluster/testapp
# cd /var/www/htdocs/testapp
# mongrel_rails cluster:configure -e production \
-p 3001 -a 0.0.0.0 -l /var/www/htdocs/testapp/log/mongrel.log \
-P /var/run/mongrel/testapp.pid \
-c /var/www/htdocs/testapp/public \
-r /var/www/htdocs/testapp \
-N 3 --user root --group root


■動作確認
# cd /var/www/htdocs/testapp
# mongrel_rails cluster:start ←開始
starting port 3001
starting port 3002
starting port 3003

# mongrel_rails cluster:stop ←終了
stopping port 3001
stopping port 3002
stopping port 3003


■サービス登録の準備
# cp (rubyのパス)/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/\
resources/mongrel_cluster /etc/init.d/mongrel_cluster_testapp
# vi /etc/init.d/mongrel_cluster_opac
--冒頭を下記に変更
CONF_DIR=/etc/mongrel_cluster/opac
PID_DIR=/var/run/mongrel/opac.pid
USER=root
--
# chmod 755 /etc/init.d/mongrel_cluster_testapp


■サービス起動/終了
# /etc/init.d/mongrel_cluster_testapp start
Starting all mongrel_clusters...

# /etc/init.d/mongrel_cluster_testapp stop
Stopping all mongrel_clusters...


■サービス起動レベルを設定
# chkconfig --level=35 mongrel_cluster_testapp on
# chkconfig --list ←設定確認