部署任务:
机器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本文不再赘述,请看本人的文章
关于Capistrano的基础,请看本人的文章
在这边文章中主要使用了Capistrano部署了一个单实例的mongrel 服务器,并且也只部署了一台机器
基于前两篇的基础,本文描述了如何使用Capistrano部署apache+mongrel cluster应用到多台机器
重点就是 deploy.rb
set
:application
,
"
space
"
set
:repository
,
"
http://192.168.100.212:3690/repo/moxtv/branches/space
"
set
:svn_username
,
"
weip
"
set
:svn_password
,
"
weip
"
#
If
youaren'tdeployingto
/
u
/
apps
/#
{application}
on
thetarget
#
servers
(
whichisthedefault
),
youcanspecifytheactuallocation
#
viathe
:deploy_to
variable:
#
set
:deploy_to
,
"
/var/www/#{application}
"
#
If
youaren'tusingSubversiontomanageyoursourcecode
,
specify
#
yourSCMbelow:
#
set
:scm
,
:subversion
set
:use_sudo
,
false
set
:deploy_to
,
"
/var/www/webapps/#{application}
"
set
:user
,
"
root
"
set
:password
,
"
secretpa
"
role
:app
,
"
192.168.100.231
"
,
"
192.168.100.234
"
#
new
0
role
:web
,
"
192.168.100.231
"
role
:db
,
"
192.168.100.231
"
,
:primary
=>
true
task
:chmod
,
:roles
=>
:web
do
run
"
chmod-fR755#{deploy_to}/current/script/*
"
end
after
"
deploy:symlink
"
,
:chmod
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
"
#
new
1
set
:mongrel_conf
,
"
#{current_path}/config/mongrel_cluster.yml
"
set
:mongrel_port
,
"
4000
"
set
:mongrel_nodes
,
"
4
"
#
new
2
namespace
:deploy
do
task
:start
,
:roles
=>
:app
do
run
"
cd#{current_path}&&mongrel_railscluster::configure-eproduction-p#{mongrel_port}-N#{mongrel_nodes}-c#{current_path}
"
run
"
cd#{current_path}&&mongrel_railscluster::start
"
#
run
"
rm-rf/home/#{user}/public_html;ln-s#{current_path}/public/home/#{user}/public_html
"
run
"
mkdir-p#{deploy_to}/shared/config
"
run
"
mv#{current_path}/config/mongrel_cluster.yml#{deploy_to}/shared/config/mongrel_cluster.yml
"
run
"
ln-s#{deploy_to}/shared/config/mongrel_cluster.yml#{current_path}/config/mongrel_cluster.yml
"
run
"
apachectlstart
"
end
end
#
new
3
namespace
:deploy
do
task
:restart
,
:roles
=>
:app
do
run
"
ln-s#{deploy_to}/shared/config/mongrel_cluster.yml#{current_path}/config/mongrel_cluster.yml
"
run
"
cd#{current_path}&&mongrel_railscluster::restart
"
run
"
apachectlrestart
"
end
end
主要修改了#new0 ,并删除了单实例mongrel中的spin文件
并加了3个部分,#new1,#new2,#new3
#new1 设置了些 与 mongrel cluster相关的变量
#new2#new3 分别重写了deploy:start和deploy:restart任务
这样就防止了默认的任务去寻找相关的spin文件
配置文件准备就绪,然后cap setup,cap deploy:cold,cap deploy