---
title: "使用Capistrano部署apache+mongrel cluster"
author: "helpbs"
date: "2007-11-23T17:38:00Z"
tags: []
slug: "capistrano-apache-mongrel-cluster"
draft: false
lastmod: "2012-04-20T18:30:31Z"
id: 1492122
url: "https://helpbs.iteye.com/blog/1492122"
---

部署任务：

机器1 192.168.100.231, os: CentOS release3.6 (Final),装上apache2.3.6+mongrel cluster

机器2 192.168.100.234, os: CentOS release4.3 (Final) 装上 mongrel cluster

关于配置apache+mongrel cluster本文不再赘述，请看本人的文章

[安装和配置Apache + mongrel cluster](http://blog.csdn.net/pwlazy/archive/2007/11/23/1899313.aspx)

关于Capistrano的基础，请看本人的文章

[使用Capistrano部署rails](http://blog.csdn.net/pwlazy/archive/2007/11/21/1896800.aspx)

在这边文章中主要使用了Capistrano部署了一个单实例的mongrel 服务器，并且也只部署了一台机器

基于前两篇的基础，本文描述了如何使用Capistrano部署apache+mongrel cluster应用到多台机器

重点就是 deploy.rb

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:application,"space"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:repository,"http://192.168.100.212:3690/repo/moxtv/branches/space"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:svn\_username,"weip"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:svn\_password,"weip"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#Ifyouaren'tdeployingto/u/apps/#{application}onthetarget  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#servers(whichisthedefault),youcanspecifytheactuallocation  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#viathe:deploy\_tovariable:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#set:deploy\_to,"/var/www/#{application}"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#Ifyouaren'tusingSubversiontomanageyoursourcecode,specify  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#yourSCMbelow:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#set:scm,:subversion  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:use\_sudo,false  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:deploy\_to,"/var/www/webapps/#{application}"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:user,"root"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:password,"secretpa"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)role:app,"192.168.100.231","192.168.100.234"#new0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)role:web,"192.168.100.231"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)role:db,"192.168.100.231",:primary=&gt;true  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)task:chmod,:roles=&gt;:webdo  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"chmod-fR755#{deploy\_to}/current/script/\*"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)end  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)after"deploy:symlink",:chmod  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)default\_environment\["PATH"]="/usr/local/ruby2/bin:/usr/local/apache2.2.6/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/ruby/bin:/usr/local/ant/bin:/usr/java/jdk1.5.0\_05/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#new1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:mongrel\_conf,"#{current\_path}/config/mongrel\_cluster.yml"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:mongrel\_port,"4000"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)set:mongrel\_nodes,"4"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#new2  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)namespace:deploydo  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)task:start,:roles=&gt;:appdo  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"cd#{current\_path}&&mongrel\_railscluster::configure-eproduction-p#{mongrel\_port}-N#{mongrel\_nodes}-c#{current\_path}"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"cd#{current\_path}&&mongrel\_railscluster::start"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#run"rm-rf/home/#{user}/public\_html;ln-s#{current\_path}/public/home/#{user}/public\_html"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"mkdir-p#{deploy\_to}/shared/config"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"mv#{current\_path}/config/mongrel\_cluster.yml#{deploy\_to}/shared/config/mongrel\_cluster.yml"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"ln-s#{deploy\_to}/shared/config/mongrel\_cluster.yml#{current\_path}/config/mongrel\_cluster.yml"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"apachectlstart"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)end  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)end  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)#new3  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)namespace:deploydo  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)task:restart,:roles=&gt;:appdo  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"ln-s#{deploy\_to}/shared/config/mongrel\_cluster.yml#{current\_path}/config/mongrel\_cluster.yml"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"cd#{current\_path}&&mongrel\_railscluster::restart"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)run"apachectlrestart"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)end  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)end  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

主要修改了#new0 ，并删除了单实例mongrel中的spin文件

并加了3个部分，#new1,#new2,#new3

#new1 设置了些 与 mongrel cluster相关的变量

#new2#new3 分别重写了deploy:start和deploy:restart任务

这样就防止了默认的任务去寻找相关的spin文件

配置文件准备就绪，然后cap setup,cap deploy:cold,cap deploy