CentOS5.1+apache+mongrelでクラスタ環境を作る

apachemongrelクラスタ環境を構築したさいのメモです

環境は
OSがCentOSruby,rails,mongrelはインストール済の環境を使用しています

apacheのインストール
centosapacheをインストールします
yumでインストール


# yum install httpd
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies

    • > Populating transaction set with selected packages. Please wait.
      • > Downloading header for httpd to pack into transaction set.

httpd-2.2.3-11.el5_1.cent 100% |=========================| 55 kB 00:00

    • > Running transaction check

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Updating:
httpd i386 2.2.3-11.el5_1.centos.3 base 1.1 M

Transaction Summary
=============================================================================
Install 0 Package(s)
Update 1 Package(s)
Remove 0 Package(s)

Total download size: 1.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/1): httpd-2.2.3-11.el5 100% |=========================| 1.1 MB 00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : httpd ######################### [1/2]
Cleanup : httpd ######################### [2/2]

Updated: httpd.i386 0:2.2.3-11.el5_1.centos.3
Complete!

次にapacheの設定を行います
httpd.confに設定を追加します
---
ProxyPass / balancer://clstr/⇒http://host/clstr/でアクセスすることになります
BalancerMember http://127.0.0.1:3010クラスタを組むhostを記述します
loadfactor⇒分散の優先度の設定
keepalive⇒on:有効/off:無効
---
apacheの設定はこのサイトに詳しくのってます
http://www.asahi-net.or.jp/~aa4t-nngk/apache3.html

#vim /etc/httpd/conf/httpd.conf

DocumentRoot "/Cent_app/app/public"

Options FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny

ProxyPass / balancer://clstr/

BalancerMember http://127.0.0.1:3010 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3011 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3012 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3013 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3014 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3015 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3016 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3017 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3018 loadfactor=10 keepalive=On
BalancerMember http://127.0.0.1:3019 loadfactor=10 keepalive=On


最後に自動起動の設定をします

# chkconfig httpd on
# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
mongrel_clusterのインストール
mongrel_clusterをインストールします

# gem install mongrel_cluster
Successfully installed mongrel_cluster-1.0.5
1 gem installed
次にmongrel_clusterの設定を行います
mongrel_cluster.ymlを作成する

#cd /railsのルートディレクト
#mongrel_rails cluster::configure -e production -p 3010 -a 127.0.0.1 -N 10 -c /Cent_app/app/
Writing configuration file to config/mongrel_cluster.yml.
作成された mongrel_cluster.ymlを確認する
---
servers⇒起動するmongrelサーバの個数下の場合ポートが3010から3019までの10個が起動する
---

mongrel_cluster.yml
---
cwd: /Cent_app/app/
log_file: log/mongrel.log
port: "3010"
environment: production
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
servers: 10
以上で構築は完了です
mongrelをスタートさせる場合は以下のコマンドを入力してください

#cd /railsのルートディレクト
#mongrel_rails cluster::start