【问题标题】:error deploying my rails application with capisrano on aws在 aws 上使用 capisrano 部署我的 rails 应用程序时出错
【发布时间】:2016-11-17 12:08:40
【问题描述】:

我遵循了关于部署到 aws ec2 https://www.sitepoint.com/deploy-your-rails-app-to-aws/ 的指南。

我使用的是 ubuntu 16 服务器。

一切都已完美安装在服务器上,但是当我运行 cap production deploy --trace 时,这是输出。

** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke rvm:hook (first_time)
** Execute rvm:hook
** Invoke rvm:check (first_time)
** Execute rvm:check
cap aborted!
Net::SSH::ConnectionTimeout: Net::SSH::ConnectionTimeout
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:90:in `rescue in initialize'
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:57:in `initialize'
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in `new'
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in `start'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in `call'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in `with'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:155:in `with_ssh'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:108:in `execute_command'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `tap'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:60:in `capture'
/var/lib/gems/2.1.0/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:9:in `block (3 levels) in <top (required)>'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `run'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Errno::ETIMEDOUT: Connection timed out - connect(2) for 172.31.11.127:22
/usr/lib/ruby/2.1.0/socket.rb:65:in `connect'
/usr/lib/ruby/2.1.0/socket.rb:65:in `connect_internal'
/usr/lib/ruby/2.1.0/socket.rb:140:in `connect'
/usr/lib/ruby/2.1.0/socket.rb:338:in `block in tcp'
/usr/lib/ruby/2.1.0/socket.rb:232:in `each'
/usr/lib/ruby/2.1.0/socket.rb:232:in `foreach'
/usr/lib/ruby/2.1.0/socket.rb:328:in `tcp'
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:70:in `initialize'
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in `new'
/var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in `start'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in `call'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in `with'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:155:in `with_ssh'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:108:in `execute_command'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `tap'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:60:in `capture'
/var/lib/gems/2.1.0/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:9:in `block (3 levels) in <top (required)>'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `run'
/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => rvm:check

我的 Capistrano production.rb 文件:

server '172.31.11.127', user: 'deploy', roles: %w{web app db}

我的 Capistrano deploy.rb 文件:

set :branch, :master   
set :deploy_to, '/home/deploy/rd'
set :pty, true

set :linked_files, %w{config/database.yml config/application.yml}

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}


set :keep_releases, 5  
set :rvm_type, :user
set :rvm_ruby_version, 'ruby 2.1.5'

set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock"    #accept array for multi-bind
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma_error.log"
set :puma_error_log, "#{shared_path}/log/puma_access.log"
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads, [0, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false

【问题讨论】:

  • 尝试在命令行检查ssh ubuntu@52.2.139.74,当你在服务器authorized_keys文件中添加你的公钥时,需要重启ssh服务
  • 我重新启动了服务,但仍然出现错误。 ip 52.2.139.74 属于谁或什么?
  • sry 错误的 ip 52.2.139.74
  • 我猜您的 Ubuntu 实例上没有 deploy 用户...也许可以尝试使用 ubuntu 用户,因为 Capistrano 正在尝试以 @987654328 的身份通过 SSH 连接到您的实例@.

标签: ruby-on-rails amazon-web-services rvm capistrano rvm-capistrano


【解决方案1】:

连接超时意味着某些防火墙规则阻止了您在端口 22 上与正在部署代码的机器的 ssh 连接。下面的消息-

/var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:inblock (2 levels) in execute' Errno::ETIMEDOUT: Connection timed out - connect(2) for 172.31.11.127:22 /usr/lib/ruby/2.1.0/socket.rb:65:in connect'

清楚地表明客户端计算机上的连接超时后超时期限到期。 当我看到您在 aws instance 中使用 capistrano 时,请检查 capistrano 机器尝试连接的客户端机器的安全组。至少应该为 capistrano 机器的 ip/子网打开端口 22。

【讨论】:

  • 你建议我怎么做?我允许 ip 连接到防火墙中的端口 22 并得到同样的错误
  • 您的部署用户是否存在于您部署代码的服务器机器上?
猜你喜欢
  • 2017-03-04
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
  • 2013-03-12
  • 2014-08-13
  • 2019-11-11
  • 1970-01-01
  • 2012-09-24
相关资源
最近更新 更多