使用Capistrano将Rails应用程序部署到多个Web服务器 [英] Using Capistrano to deploy a Rails application to multiple web servers
问题描述
我想使用Capistrano(我已经用于我现有的单个服务器)的单个命令来处理所有这些服务器的应用程序部署。我可以看到这样做的唯一方法是使用 capistrano-ext
(我实际上已经使用它来部署到我的测试和分段环境),通过定义一个新的环境对于每个应用程序服务器( app1
, app2
等等),并使用以下方式执行部署:
cap app1 app2 app3 deploy
这是推荐的做法还是有更好的方法?
是的。 Capistrano本机管理多台服务器。不需要capistrano ext。
您只需定义多个 roles < a>
角色:app,myserver.example.com
role:db,mysecondserver.example。 com
默认情况下,您的任务将在每个服务器上执行。但是您可以将任务限制在一个或几个服务器上。
task:migrate,:roles => [:app,:db] do
#...
end
在这里,任务只能在应用程序和db角色上执行。
可以使用run方法执行相同操作。
运行rake db:migrate,:roles => :db
rake db:migrate只能在数据库服务器上运行。
I'm currently setting up a new production environment for a Rails application which includes multiple, load-balanced application servers (currently only two, but this will increase over time).
I'd like to handle deployment of the app to all these servers in a single command using Capistrano (which I already use for my existing, single server). The only way I can see of doing this is to use capistrano-ext
(which I actually already use to deploy to my test and staging environments), by defining a new 'environment' for each application server (app1
, app2
and so on) and performing a deployment using something like:
cap app1 app2 app3 deploy
Is this the recommended way of doing it or is there a better approach?
Yeah. Capistrano manages multiple servers natively. No need for capistrano ext.
You only need to define multiple roles
role :app, "myserver.example.com"
role :db, "mysecondserver.example.com"
By default your tasks will be executed on every server. But you can limit a task to one or some servers only.
task :migrate, :roles => [:app, :db] do
# ...
end
Here, the task will be executed only on the app and db roles.
You can do the same with the run method.
run "rake db:migrate", :roles => :db
The rake db:migrate will be run only on the db server.
这篇关于使用Capistrano将Rails应用程序部署到多个Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!