1. 创建一个项目
cd ~/public_html rails railsapp
2. Apache 需要激活 proxy 和 rewrite 模块
一般安装的apache 需要执行以下命令:
sudo a2enmod proxy sudo a2enmod proxy_balancer sudo a2enmod proxy_http sudo a2enmod rewrite
3. 重新加载 Apache
sudo /etc/init.d/apache2 force-reload
4. 安装 Mongrel 和 Mongrel Cluster
sudo gem install mongrel **************************** gem_plugin-0.2.3 daemons-1.0.10 fasthread-1.0.1 cgi-multipart_eof_fix-2.5.0 mongrel-1.1.4
mongrel 的使用(http://articles.slicehost.com/2008/5/9/ubuntu-hardy-mongrel-and-mongrel-clusters)
开启 mongrel_rails start -e production -p 6000 关闭 mongrel_rails stop
5. 安装 mongrel_cluster
gem install mongrel_cluster
6. 创建一个文件放置执行 mongrel_cluster 生成的.yml文件的引用
sudo mkdir /etc/mongrel_cluster
7. 执行 mongrel_rails 生成 mongrel_cluster.yml 文件
cd ~/public_html/railsapp mongrel_rails cluster::configure -e production -p 5000 -N 3 -c /home/demo/public_html/railsapp -a 127.0.0.1
在你的项目 /config 中将会看到生成的 mongrel_cluster.yml 文件
cwd: /home/demo/public_html/railsapp log_file: log/mongrel.log port: "5000" environment: production address: 127.0.0.1 pid_file: tmp/pids/mongrel.pid servers: 3
8. 在/etc/mongrel_cluster文件夹中创建一个 mongrel_cluster.yml 的引用
sudo ln -s /home/demo/public_html/railsapp/config/mongrel_cluster.yml /etc/mongrel_cluster/railsapp.yml
9. 开始 cluster
mongrel_cluster_ctl start
10. 配置apache ,在 /etc/apache2/sites-abailable/中新建一个 demain.com 文件
sudo vi /etc/apache2/sites-available/domain.com
写入以下代码:
<VirtualHost *:80> ServerName domain.com ServerAlias www.domain.com DocumentRoot /home/demo/public_html/railsapp/public RewriteEngine On <Proxy balancer://mongrel1> BalancerMember http://127.0.0.1:5000 BalancerMember http://127.0.0.1:5001 BalancerMember http://127.0.0.1:5002 </Proxy> # Redirect all non-static requests to thin RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://mongrel1%{REQUEST_URI} [P,QSA,L] ProxyPass / balancer://mongrel1/ ProxyPassReverse / balancer://mongrel1/ ProxyPreserveHost on <Proxy *> Order deny,allow Allow from all </Proxy> # Custom log file locations ErrorLog /home/demo/public_html/railsapp/log/error.log CustomLog /home/demo/public_html/railsapp/log/access.log combined </VirtualHost>
11 . 完成以上步骤,我们必须激活 domain.com
sudo a2ensite domain.com
12 . 重新加载apache
sudo /etc/init.d/apache2 reload
参考网站:http://articles.slicehost.com/2008/5/9/ubuntu-hardy-mongrel-and-mongrel-clusters