Net-ssh会话超时 [英] Net-ssh session timeout

查看:76
本文介绍了Net-ssh会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Net-ssh启动远程Python脚本.当Python脚本执行时间较长(大约20分钟)时,Ruby脚本似乎挂起并且永远无法完成.

I am using Net-sshto launch a remote Python script. The Ruby script seems to hang and never complete when the Python script takes a long time to execute (around 20 minutes).

我已经通过直接运行脚本来对其进行了测试,并且脚本完整无误.当在较短的时间内执行脚本时,一切也都可以正常工作.

I have tested the script by running it directly and it completes without any error. Also everything works fine when the script is executed in a shorter amount of time.

这是我正在使用的代码的一部分:

This is an extract of the code I am using:

(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会话的某种超时有关吗?

Could this be related to some kind of timeout for the ssh session?

我已经验证了脚本在远程服务器上已成功完成.

I have verified that the script is completed successfully on the remote server.

推荐答案

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

The problem was associated to the SSH server time out. I solved the problem by changing the settings on the server. I have added the following line:

ClientAliveInterval 60

/etc/ssh/sshd_config

基于文章应该可以在客户端上进行类似的修改:

Based on this article it should be possible to make a similar modification on the client:

ServerAliveInterval 60

/etc/ssh/ssh_config

这篇关于Net-ssh会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆