使用Amazon RDS进行部署时,Capistrano超时

时间:2011-06-07 17:46:45

标签: capistrano amazon-rds

我似乎无法让Capistrano与AmazonRDS很好地配合。我已经到处查看有关正确设置的任何信息,但没有找到任何信息。现在,当我cap deploy时,过程会超时。

这是我的deploy.rb:

set :deploy_to, "/opt/bitnami/apps/annarbortshirtcompany.com/cms/" 
set :scm, :git
set :repository,  "ssh://user@ec2-repository.compute-1.amazonaws.com/~/repo/cms.git"
set :deploy_via, :remote_cache

set :user, "user"
ssh_options[:keys] = [File.join(ENV["HOME"], "EC2", "admin.pem")]
ssh_options[:forward_agent] = true
set :branch, "master"
set :use_sudo, true

set :location, "ec2-webserver.compute-1.amazonaws.com"
role :web, location
role :app, location
role :db, "cmsinstance.c7r8frl6npxn.us-east-1.rds.amazonaws.com", :primary => true

# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

RDS数据库实例的用户名与此处设置的SSH用户名不同,但在我的database.yml中定义。我认为这可能不是由capistrano读取的,但不知道如何实现这一点。

当我“限制部署”时:

ubuntu@ubuntu-VirtualBox:~/RailsApps/cms$ cap deploy
  * executing `deploy'
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote ssh://user@ec2-repository.compute-1.amazonaws.com/~/repo/cms.git master"
    command finished in 1590ms
  * executing "if [ -d /app-directory/shared/cached-copy ]; then cd /app-directory/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard ffc4ec7762566f801c4a9140aa3980dc71e3d06f && git clean -q -d -x -f; else git clone -q  ssh://user@ec2-repository.amazonaws.com/~/repo/cms.git /app-directory/shared/cached-copy && cd /app-directory/shared/cached-copy && git checkout -q -b deploy ffc4ec7762566f801c4a9140aa3980dc71e3d06f; fi"
    servers: ["ec2-webserver.compute-1.amazonaws.com", "dbinstance.us-east1.rds.amazonaws.com"]
*** [deploy:update_code] rolling back
  * executing "rm -rf /app-directory/releases/20110607161612; true"
    servers: ["ec2-webserver.compute-1.amazonaws.com", "dbinstance.us-east1.rds.amazonaws.com"]
 ** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: dbinstance.us-east1.rds.amazonaws.com (Errno::ETIMEDOUT: Connection timed out - connect(2))
    connection failed for: dbinstance.us-east1.rds.amazonaws.com (Errno::ETIMEDOUT: Connection timed out - connect(2))

为什么要“更新所有服务器上的缓存结帐”?此时甚至不需要DB服务器。我很难解决这个问题。希望有人能指出我正确的方向!

1 个答案:

答案 0 :(得分:26)

我遇到了这个问题,并且因为我尴尬地说这是一个好的5或6个小时而挣扎。最后,当我意识到问题是什么时,我感觉自己好像在打扰自己,因为我曾经知道这一点,但却忘了它。这是问题的症结所在,从deploy.rb的这一部分开始:

set :location, "ec2-webserver.compute-1.amazonaws.com"
role :web, location
role :app, location
role :db, "cmsinstance.c7r8frl6npxn.us-east-1.rds.amazonaws.com", :primary => true

当您为Capistrano定义机器角色时,您实际上并未确定哪些机器将扮演特定角色...而是在识别时Capistrano代码将在哪台机器上运行为角色应用部署配方。因此,当您定义:db角色时,您希望指向您的EC2实例, RDS实例。你不能ssh到RDS机器,所以Capistrano不可能在那里运行配方。相反,指向:db到您指向的同一台机器:web和:app,即

set :location, "ec2-webserver.compute-1.amazonaws.com"
role :web, location
role :app, location
role :db, location, :primary => true

RDS机器如何参与?好吧,这是database.yml文件,它指示哪台机器实际运行需要执行SQL的RDBMS。您只需要确保为目标数据库设置host:值,例如:

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: <your_db>_production
  pool: 5
  username: <username>
  password: <password>
  host: cmsinstance.c7r8frl6npxn.us-east-1.rds.amazonaws.com

有意义吗?

我希望这可以拯救别人我遇到的挫败感。

  • 大卫