使用 Capistrano 将 Rails 应用程序部署到多个 Web 服务器 [英] Using Capistrano to deploy a Rails application to multiple web servers
问题描述
我目前正在为 Rails 应用程序设置一个新的生产环境,其中包括多个负载平衡的应用程序服务器(目前只有两个,但随着时间的推移会增加).
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).
我想使用 Capistrano(我已将其用于我现有的单个服务器)在单个命令中将应用程序部署到所有这些服务器.我能看到的唯一方法是使用 capistrano-ext
(我实际上已经使用它来部署到我的测试和登台环境),为每个应用程序服务器定义一个新的环境"(app1
、app2
等)并使用以下内容执行部署:
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?
推荐答案
是的.Capistrano 本地管理多个服务器.不需要 capistrano 分机.
您只需要定义多个角色
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
这里,任务将只在 app 和 db 角色上执行.
Here, the task will be executed only on the app and db roles.
你可以用 run 方法做同样的事情.
You can do the same with the run method.
run "rake db:migrate", :roles => :db
rake db:migrate 将仅在 db 服务器上运行.
The rake db:migrate will be run only on the db server.
这篇关于使用 Capistrano 将 Rails 应用程序部署到多个 Web 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!