部署到Ubuntu服务器时Capistrano部署错误

时间:2015-11-06 13:05:47

标签: ruby-on-rails nginx capistrano devops

我正在关注此blog,设置我的rails服务器,运行此命令后,我收到以下错误

cap production deploy:initial --trace


cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 104.197.138.17: connection closed by remote host
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Net::SSH::Disconnect: connection closed by remote host
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:50:in `rescue in block (2 levels) in negotiate!'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:46:in `block (2 levels) in negotiate!'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:45:in `loop'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:45:in `block in negotiate!'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:43:in `loop'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:43:in `negotiate!'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:32:in `initialize'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:84:in `new'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:84:in `block in initialize'
/home/vagrant/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/timeout.rb:75:in `timeout'
/home/vagrant/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/timeout.rb:126:in `timeout'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:84:in `initialize'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh.rb:207:in `new'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh.rb:207:in `start'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:187:in `with_ssh'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:137:in `block in _execute'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `tap'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `_execute'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:62:in `test'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:21:in `block (3 levels) in <top (required)>'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
EOFError: end of file reached
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:47:in `readpartial'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:47:in `block (2 levels) in negotiate!'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:45:in `loop'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:45:in `block in negotiate!'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:43:in `loop'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:43:in `negotiate!'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/server_version.rb:32:in `initialize'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:84:in `new'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:84:in `block in initialize'
/home/vagrant/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/timeout.rb:75:in `timeout'
/home/vagrant/.rvm/rubies/ruby-2.1.7/lib/ruby/2.1.0/timeout.rb:126:in `timeout'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:84:in `initialize'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh.rb:207:in `new'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/net-ssh-2.9.2/lib/net/ssh.rb:207:in `start'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/connection_pool.rb:50:in `call'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/connection_pool.rb:50:in `create_new_entry'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/connection_pool.rb:22:in `checkout'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:187:in `with_ssh'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:137:in `block in _execute'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `tap'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `_execute'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:62:in `test'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:21:in `block (3 levels) in <top (required)>'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/vagrant/.rvm/gems/ruby-2.1.7/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => rvm:hook

2 个答案:

答案 0 :(得分:1)

看来Capistrano无法连接到服务器并且超时,最可能的罪魁祸首是它没有正确读取SSH密钥。测试它的最简单方法是尝试创建一个ssh配置文件:

nano ~/.ssh/config

添加:

Host 104.197.138.17
    HostName 104.197.138.17
    IdentityFile ~/.ssh/id_rsa

尝试:

ssh deploy@104.197.138.17

确保连接。 (我假设104.197.138.17是​​你服务器的IP ......)

如果有效,请再次尝试cap production deploy:check

-

这里发生的是ssh配置将额外的参数提供给该主机的任何SSH调用(在本例中为IP)。如果需要,您可以将主机更改为“mysite.com”,如果您想创建一些分隔,则可以运行ssh deploy@mysite.com。数字海洋has tutorial about it

答案 1 :(得分:0)

所以在Capistrano生成的deploy.rb文件中,我注释掉了 这条线。它开始起作用了。

set :ssh_options,{ forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }