Ton*_*ita 8 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
Run Code Online (Sandbox Code Playgroud)
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))
Run Code Online (Sandbox Code Playgroud)
为什么要"更新所有服务器上的缓存结帐"?此时甚至不需要DB服务器.我很难解决这个问题.希望有人可以指出我正确的方向!
小智 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
Run Code Online (Sandbox Code Playgroud)
当您为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
Run Code Online (Sandbox Code Playgroud)
那么RDS机器如何参与呢?好吧,这是database.yml文件,它指示哪台机器实际运行需要执行SQL的RDBMS.您只需要确保为目标数据库设置host:value,例如:
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
Run Code Online (Sandbox Code Playgroud)
合理?
我希望这可以拯救别人我遇到的挫折感.