【问题标题】:Why does scp sporadically fail, when doing multiple scps in parallel?为什么 scp 在并行执行多个 scp 时偶尔会失败?
【发布时间】:2016-08-07 20:55:06
【问题描述】:

我有一个小应用程序正在尝试执行十几个并行“scp”运行,从远程系统中提取文件。通常,它运行良好。 有时,一两个运行的 scp 会悄悄地死掉。 (如果从 Linux 中提取,则为“安静”。如果从 HP-UX 中提取,我会收到一条消息 比如对等连接重置。)

如果我在我的 scp 命令中添加“-v”,那么当发生故障时,我看到我正在 获取“ssh_exchange_identification:读取:对等方重置连接” (在 Linux 上...尚未在 HP-UX 上尝试过 -v)。

这是典型运行的“scp -v”输出,其中有一个“错误” 运行和“良好”运行分歧表明:

Executing: program /usr/bin/ssh host wilbur, user (unspecified), command scp -v -p -f /home/sieler/source/misc/[p-q]*.[ch]
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 51: Applying options for *
debug1: Connecting to wilbur [10.84.3.61] port 22.
debug1: Connection established.
debug1: identity file /Users/sieler/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/sieler/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/sieler/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/sieler/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/sieler/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/sieler/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/sieler/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/sieler/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9

'bad' 和 'good' 运行匹配到这一点,然后...

不好:

ssh_exchange_identification: read: Connection reset by peer

好:

debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug1: Authenticating to wilbur:22 as 'sieler'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr umac-64@openssh.com none
debug1: kex: client->server aes128-ctr umac-64@openssh.com none
...

虽然脚本和 scp 运行的通常主机是 Mac,运行 OS X 10.11.4,但该问题已在多种组合中重现 Mac/Linux/HP-UX(足以排除它是 Mac 或 HP-UX 特定问题)。

IIRC,使用scp 从 Linux 拉到 Mac 有问题, 以及从 HP-UX 拉到 Mac,从 Linux 拉到 HP-UX。
没有尝试从 Mac 或 HP-UX 拉到 Linux。

scp/ssh/openssh 是否存在并行使用有时会失败的问题?

如果我在带有-ddd 的Linux 系统上运行sshd,那么恶魔会在之后停止 第一个scp 访问它(scp 没有问题), 其他 11 个 scp 运行失败。

谢谢

【问题讨论】:

  • Jakuje 指向“MaxStartups”的指针为我解决了我的问题。

标签: linux ssh scp openssh


【解决方案1】:

这可能是由于sshd_config 中并行会话的限制造成的。默认情况下,服务器配置为“随机提前丢弃”,这意味着如果活动量大于某个限制,则拒绝新连接。负责的选项是MaxStartups(来自人sshd_config):

MaxStartups

指定到 SSH 守护程序的最大并发未经身份验证的连接数。其他连接将被丢弃,直到身份验证成功或LoginGraceTime 连接过期。默认为 10:30:100。

或者,可以通过指定三个冒号分隔的值“start:rate:full”(例如“10:30:60”)来启用随机提前丢弃。如果当前有“开始”(10)个未经身份验证的连接,sshd(8)将拒绝连接尝试,概率为“rate/100”(30%)。如果未经身份验证的连接数达到“满” (60),则概率线性增加,并且所有连接尝试都将被拒绝。

将值提高到大于您预期的连接数量应该可以解决您的问题。否则,您可以在sshd_config 中设置LogLevel DEBUG3 以在系统日志中查看更多日志。


但是当你连接到同一个服务器时,最好使用连接多路复用。它会更快,你不会有这些问题。查看ssh_config 中的ControlMaster 选项或查看my similar answer 以快速了解这个“魔法”。

【讨论】:

    猜你喜欢
    • 2023-01-30
    • 2020-09-06
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 2011-04-20
    • 2021-08-20
    相关资源
    最近更新 更多