gpt4 book ai didi

linux - 如何解决 'The SSH connection was unexpectedly closed by the remote end' 的问题?

转载 作者:太空狗 更新时间:2023-10-29 12:12:12 25 4
gpt4 key购买 nike

我的配置:

  • 专用服务器 (Ubuntu 16.04 LTS) 仅用于 Jenkins (2.7.1),
  • 超过 100 个 Jenkins 作业,每个作业都向 AWS (Vagrantfile) 调用 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 网络访问权限,
  • 我并行运行的作业越多,它们失败的机会就越大,
  • 单独重新运行同一个作业通常效果很好,
  • /etc/ssh/ssh_config 中的默认设置,没有用于 Jenkins 的 ~/.ssh/config

如何解决上述 SSH 意外关闭的问题?

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

最佳答案

打开你的 /etc/ssh/sshd_config 文件:

# vi /etc/ssh/sshd_config

修改设置如下:

ClientAliveInterval 30
ClientAliveCountMax 5

在哪里,

ClientAliveInterval: Sets a timeout interval in seconds (30) after which if no data has been received from the client, sshd will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.

ClientAliveCountMax: Sets the number of client alive messages (5) which may be sent without sshd receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session.

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

# /etc/init.d/ssh restart

或:

# service sshd restart

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

# vi /etc/ssh/ssh_config

然后按如下方式追加/修改值:

ServerAliveInterval 30
ServerAliveCountMax 5

在哪里,

ServerAliveInterval: Sets a timeout interval in seconds after which if no data has been received from the server, ssh will send a message through the encrypted channel to request a response from the server.

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

关于linux - 如何解决 'The SSH connection was unexpectedly closed by the remote end' 的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39175996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com