【问题标题】:Packer loops through ports when attempting to establish SSH connectionPacker 在尝试建立 SSH 连接时循环通过端口
【发布时间】:2017-02-01 19:14:48
【问题描述】:

当 Packer 到达“等待 SSH 可用...”步骤时。

我的日志显示

14:07:29 [INFO] Attempting SSH connection...
14:07:29 reconnecting to TCP connection for SSH
14:07:29 handshaking with SSH
14:07:29 handshake error: ssh: handshake failed: read tcp 127.0.0.1:60372->127.0.0.1:3057: read: connection reset by peer
14:07:29 [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:60372->127.0.0.1:3057: read: connection reset by peer

14:07:36 [INFO] Attempting SSH connection...
14:07:36 reconnecting to TCP connection for SSH
14:07:36 handshaking with SSH
14:07:36 handshake error: ssh: handshake failed: read tcp 127.0.0.1:60376->127.0.0.1:3057: read: connection reset by peer
14:07:36 [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:60376->127.0.0.1:3057: read: connection reset by peer

每次尝试时请注意不同的端口。

60372
60376

Packer 每 7 秒尝试一个新端口。

有没有办法在构建之前或构建期间配置端口以避免这种尝试/失败方法?

【问题讨论】:

  • 您看到的是 TCP 客户端的典型行为。您想在这里解决什么问题?
  • 问题是找到好端口的时间在 10 到 60 分钟之间。它使构建变得不可预测并且偶尔会超时。我的詹金斯工作是 45 分钟。当我手动运行打包程序时,通常需要 5-15 分钟。
  • "connection reset by peer" 通常表示 ssh 服务器有问题。您确定客户端使用的源端口与您的问题相关吗?
  • 如果我等待足够长的时间,连接最终会建立,其余的都会按预期完成。如何对 ssh 服务器进行故障排除?我应该寻找什么?作为用户,我使用 Powershell SSH 远程访问服务器。它会影响其他传出连接吗?

标签: ssh packer


【解决方案1】:

这是建立 ssh 连接的源端口。它由操作系统分配一个随机可用的高端口。

【讨论】:

  • 好像是反过来的,源端口在 > 第一个端口是目的端口。当第一个失败时,SSH 正在尝试随机端口。
  • 不,看起来不像。
  • 失败是因为sshd还没有启动。
  • 你是对的,那是因为客户操作系统仍在安装和配置中。它的 SSH 代理直到稍后才可用。同时,主机操作系统每 7 秒发送一次垃圾连接。问题是我注意到同一主机上的时间不同。有时需要 5 分钟,有时需要 15 分钟,当我添加 Jenkins(没有并行运行的作业)时,时间会达到 30-40 分钟。
  • 你的 Jenkins 服务器很可能是你笔记本电脑速度的 1/3。尝试在笔记本电脑上运行 Jenkins,您将拥有类似的运行时。安装操作系统很慢 5 分钟以上对于 Linux 来说并不少见。安装 Windows 会慢很多。
【解决方案2】:

问题不在于 SSH 服务器或 TCP/IP。这与 Packer 的设计方式有关。

创建 VM 后,Packer.io 将运行启动命令。这需要时间,而且不同的机器所用的时间也不同。在此期间,您将看到“等待 SSH 可用...”。在后台,Packer.io 将尝试建立 SSH 连接。日志中充斥着这样的消息

Linux
14:07:29 [INFO] Attempting SSH connection...
14:07:29 reconnecting to TCP connection for SSH
14:07:29 handshaking with SSH
14:07:29 handshake error: ssh: handshake failed: read tcp 127.0.0.1:60372->127.0.0.1:3057: read: connection reset by peer
14:07:29 [DEBUG] SSH handshake err: ssh: handshake failed: read tcp    127.0.0.1:60372->127.0.0.1:3057: read: connection reset by peer

Windows
15:54:31 packer.exe: 2017/02/01 15:54:31 [INFO] Attempting SSH connection...
15:54:31 packer.exe: 2017/02/01 15:54:31 reconnecting to TCP connection for SSH
15:54:31 packer.exe: 2017/02/01 15:54:31 handshaking with SSH
15:54:31 packer.exe: 2017/02/01 15:54:31 handshake error: ssh: handshake failed: read tcp 127.0.0.1:62691->127.0.0.1:4289: wsarecv: An existing connection was forcibly closed by the remote host.
15:54:31 packer.exe: 2017/02/01 15:54:31 [DEBUG] SSH handshake err: ssh: handshake failed: read tcp 127.0.0.1:62691->127.0.0.1:4289: wsarecv: An existing connection was forcibly closed by the remote host.

操作系统将启动,来宾上的 SSH 服务器将可用。此时应该建立从主机到来宾的 SSH 连接。

在 Windows 10 Pro 和 Ubuntu 16.04.1 TL 上复制并确认

【讨论】:

    猜你喜欢
    • 2022-01-05
    • 2017-06-24
    • 2015-07-24
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多