# 가정 : Rails 설치
# Mongrel 설치
gem install gem-plugin mongrel mongrel_cluster --include-dependencies
Select which gem to install for your platform (i486-linux)
1. mongrel 1.0.1 (mswin32)
2. mongrel 1.0.1 (ruby)
3. mongrel 1.0 (mswin32)
4. mongrel 1.0 (ruby)
5. Skip this gem
6. Cancel installation
> 2
Select which gem to install for your platform (i486-linux)
1. fastthread 1.0 (ruby)
2. fastthread 1.0 (mswin32)
3. fastthread 0.6.4.1 (mswin32)
4. fastthread 0.6.4.1 (ruby)
5. Skip this gem
6. Cancel installation> 1
# Test (rails app만들고, mongrel 서버 시작하기)
$ mkdir ~/rals; cd ~/rails;
$ rails www (www rails app만들기)
$ mongrel_rails cluster::configure-p 8001 -a 127.0.0.1 -N 3
$ mongrel_rails cluster::start
>> http://127.0.0.1:8001 로 접속시, Rails "welcome" 화면을 볼수 있을 것이다.
# Apache 2.2
1. 다음 모듈들 필요
$ a2enmod rewirte
$ a2enmod proxy
$ a2enmod proxy_balancer
> Apache 재시작
2. apache2.conf 에 httpd.conf 추가
"Include /home/xxx/conf/httpd.conf"
3. 위 httpd.conf에는 다음 내용 추가
NameVirtualHost *:80 <VirtualHost *:80> ServerName xxx-server.org Include /home/xxx/conf/www.conf </VirtualHost> <VirtualHost *:80> ServerName www.xxx-server.org Include /home/xxx/conf/www.conf </VirtualHost>
4. 다음은, 다른 Config 파일 link-out 시키는 법
DocumentRoot /home/rcrowley/rails/www/public RewriteEngine On RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://www_mongrel%{REQUEST_URI} [P,QSA,L] <Proxy balancer://www_mongrel> BalancerMember http://127.0.0.1:8001 BalancerMember http://127.0.0.1:8002 BalancerMember http://127.0.0.1:8003 </Proxy>
5. "/etc/init.d/mongre" 을 다음처럼 수정하면 편함
#! /bin/sh do_start() { echo "Starting Mongrel..." mongrel_rails cluster::start -C ~rcrowley/rails/www/config/mongrel_cluster.yml } do_stop() { echo "Stopping Mongrel..." mongrel_rails cluster::stop -C ~rcrowley/rails/www/config/mongrel_cluster.yml } case "$1" in start) do_start ;; stop) do_stop ;; restart|force-reload) do_stop do_start ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 exit 3 ;; esac
5. Mongre 시작
$ update-rc.d mongrel defaults
6. Mongrel - Cluster 로 시작
1) 방법 1
각 rails application 디렉토리 이동 후,
$ mongrel_rails start -e development -d -p 8080 //8080포트로 시작
$ mongrel_rails start -e development -d -p 8090 //8090포트로 시작
2) 방법 2
$ mongrel_rails cluster::configure -e development -p 8080 -N 3 -c /<rails_app_path>
$ mongrel_rails cluster::configure -e development -p 8090 -N 3 -c /<rails_app_path>