简体   繁体   English

使用Capistrano将Rails应用程序部署到多个Web服务器

[英]Using Capistrano to deploy a Rails application to multiple web servers

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). 我目前正在为Rails应用程序设置一个新的生产环境,该应用程序包括多个负载均衡的应用程序服务器(目前只有两个,但随着时间的推移会增加)。

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). 我想使用Capistrano(我已经用于现有的单个服务器)在单个命令中处理应用程序到所有这些服务器的部署。 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: 我能看到这样做的唯一方法是使用capistrano-ext (我实际上已经用它来部署到我的测试和登台环境),为每个应用服务器( app1app2等)定义一个新的“环境”并使用以下内容执行部署:

cap app1 app2 app3 deploy

Is this the recommended way of doing it or is there a better approach? 这是推荐的做法还是有更好的方法?

Assuming capistrano multistage : 假设capistrano多级

In config/deploy/production : config/deploy/production

role :app, "server1", "server2", "server3"

Now a cap deploy production will deploy to all 3 servers. 现在, cap deploy production将部署到所有3台服务器。

Yeah. 是啊。 Capistrano manages multiple servers natively. Capistrano本地管理多个服务器。 No need for capistrano ext. 不需要capistrano分机。
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. 此处,任务仅在app和db角色上执行。

You can do the same with the run method. 您可以使用run方法执行相同的操作。

run "rake db:migrate", :roles => :db

The rake db:migrate will be run only on the db server. rake db:migrate将仅在db服务器上运行。

This is what I have tried in rails 4 : 这是我在rails 4尝试过的:

config/deploy.rb: 配置/ deploy.rb:

role :app, %w{server1 server2 server3}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM