1

我是 ruby​​ 新手,目前在部署 capistrano 时遇到问题。在我得到的错误之下。

cap aborted!
Operation timed out - connect(2)
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `initialize'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `open'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `block in initialize'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:67:in `initialize'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `new'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `start'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:156:in `ssh'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:109:in `block in _execute'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/abstract.rb:75:in `within'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-3.0.0/lib/capistrano/tasks/git.rake:44:in `block (3 levels) in <top (required)>'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `run'
/Users/stefydu/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => git:create_release => git:update
(See full trace by running task with --trace)
4

2 回答 2

0

Capistrano 现在使用 SSH 连接池: https ://github.com/capistrano/sshkit/pull/70

于 2013-12-30T14:33:01.603 回答
0

不是解决方案,而是解决方法的解释:

Capistrano 3 及其 sshkit 不会重用现有的 SSH 连接,而是为每个任务启动一个新连接(请参阅https://github.com/capistrano/sshkit/issues/34)。

一些服务器,分别是它们的防火墙,如果它们来得很快或者如果有太多打开的连接,似乎会阻止新的连接请求。

解决方案:

  • 修复 SSHKit/Capistrano 以重用连接
  • 配置您的服务器/防火墙以允许大量并行 ssh 会话(对于大约 15 个简单的 rails 应用程序)
  • 在下面使用我的技巧(免责声明:不,不要使用它):

我们将在 gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb 中扩展(monkeypatch)执行方法。这可以通过 Capfile 完成:

# Overwrite execute method to avoid timeouts
class SSHKit::Backend::Netssh
  def execute(*args)
    _execute(*args).success?
  rescue Errno::ETIMEDOUT
    @tries ||= 0
    raise "Nope, no way" if @tries > 5
    puts "Timeout. yeah. Try it again (#{@tries})" 
    sleep 5
    @tries += 1
    execute(*args)
    end
end

这给了服务器一个喘息的机会......

于 2013-11-14T12:57:26.937 回答