Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何解决与';SSH连接被远程端意外关闭';?_Linux_Amazon Web Services_Jenkins_Ssh_Vagrant - Fatal编程技术网

Linux 如何解决与';SSH连接被远程端意外关闭';?

Linux 如何解决与';SSH连接被远程端意外关闭';?,linux,amazon-web-services,jenkins,ssh,vagrant,Linux,Amazon Web Services,Jenkins,Ssh,Vagrant,我的配置: 仅用于Jenkins(2.7.1)的专用服务器(Ubuntu 16.04 LTS) 超过100多个Jenkins作业,每个作业都向AWS()调用vagrant实例 每个作业(供应脚本)可能需要1-2小时才能运行 大多数服务器配置文件(如SSH)都有默认的系统配置 当我同时运行多个Jenkins实例时,它们更有可能因以下错误而失败: 00:00:00.774 + vagrant up --no-provision --destroy-on-error --provider=aws

我的配置:

  • 仅用于Jenkins(2.7.1)的专用服务器(Ubuntu 16.04 LTS)
  • 超过100多个Jenkins作业,每个作业都向AWS()调用vagrant实例
  • 每个作业(供应脚本)可能需要1-2小时才能运行
  • 大多数服务器配置文件(如SSH)都有默认的系统配置
当我同时运行多个Jenkins实例时,它们更有可能因以下错误而失败:

00:00:00.774 + vagrant up --no-provision --destroy-on-error --provider=aws
00:00:09.635 Bringing machine 'MT-aws' up with 'aws' provider...
...
00:01:16.498     MT-aws: Running: inline script
...
00:01:26.415 ==> MT-aws: + echo
00:01:26.415 ==> MT-aws: + sleep 20
00:01:26.427 The SSH connection was unexpectedly closed by the remote end. This
00:01:26.427 usually indicates that SSH within the guest machine was unable to
00:01:26.427 properly start up. Please boot the VM in GUI mode to check whether
00:01:26.427 it is booting properly.
00:01:26.625 Build step 'Execute shell' marked build as failure
事实:

  • 设置脚本在随机位置失败(失败前没有特定代码)
  • 服务器没有过载,有足够的可用RAM和对Gbit网络的访问
  • 我做的工作越多,失败的机会就越大
  • 单独重新运行同一个作业通常效果良好
  • Jenkins在
    /etc/ssh/ssh\u config
    中的默认设置,没有
    ~/.ssh/config

在SSH意外关闭的情况下,如何解决上述问题


我是否需要增加一些SSH超时设置或其他设置?

打开您的
/etc/SSH/sshd\u config
文件:

# vi /etc/ssh/sshd_config
修改设置如下:

ClientAliveInterval 30
ClientAliveCountMax 5
ServerAliveInterval 30
ServerAliveCountMax 5
在哪里,

ClientAliveInterval:设置一个以秒(30)为单位的超时时间间隔,在此时间间隔之后,如果没有从客户端接收到数据,sshd将通过加密通道发送消息,请求客户端响应。默认值为0,表示这些消息将 不会发送到客户端。此选项仅适用于协议版本2

ClientAliveCountMax:设置在sshd没有从客户端接收任何消息的情况下可以发送的客户端活动消息(5)的数量。如果在发送客户端活动消息时达到此阈值,sshd将断开客户端连接,终止会话

关闭并保存文件,然后重新启动
sshd
,例如:

# /etc/init.d/ssh restart
或:


另一个选项是在客户端(您的工作站)的
ssh\u config
文件中启用
ServerAliveInterval
,例如

# vi /etc/ssh/ssh_config
然后按如下方式追加/修改值:

ClientAliveInterval 30
ClientAliveCountMax 5
ServerAliveInterval 30
ServerAliveCountMax 5
在哪里,

ServerAliveInterval:设置一个以秒为单位的超时时间间隔,在此时间间隔之后,如果没有从服务器接收到数据,ssh将通过加密通道发送一条消息,请求服务器响应


在上面的示例中,
ServerAliveInterval
设置为15,并且
ServerAliveCountMax
保留在3,如果服务器没有响应,ssh将在大约45秒后断开连接。同样,此选项仅适用于协议版本2。

另一种方法,如所建议的,是将SSH行添加到Vagrantfile

config.vm.ssh.keep_alive = true
默认情况下,这将每5秒发送一次SSH keep-alive数据包,以保持连接处于活动状态

有关更多信息,请参阅