Net-ssh 会话超时

Net-ssh session timeout

我正在使用 Net-ssh 启动远程 Python 脚本。当 Python 脚本需要很长时间执行(大约 20 分钟)时,Ruby 脚本似乎挂起并且永远不会完成。

我直接通过 运行 测试了脚本,它没有任何错误地完成了。当脚本在较短的时间内执行时,一切都正常。

这是我正在使用的代码的摘录:

(0..(@number_of_vms - 1)).each_with_index do |vm, i|
  threads << Thread.new do
    Net::SSH.start('ip-address-vm', user, options = ...) do |session|
      cmd = 'python python_script.py'
      output = session.exec!(cmd)
    end
  end
end
threads.each {|thr| thr.join }

这可能与 ssh 会话的某种超时有关吗?

编辑:我已验证脚本已在远程服务器上成功完成。

该问题与 SSH 服务器超时有关。我通过更改服务器上的设置解决了这个问题。我添加了以下行:

ClientAliveInterval 60

/etc/ssh/sshd_config

根据this文章,应该可以在客户端进行类似的修改:

ServerAliveInterval 60

/etc/ssh/ssh_config