三台相同的服务器 — 全部通过 scp 接受 61 KB 的文件,但其中两台拒绝任何超过 62 KB 的文件

三台相同的服务器 — 全部通过 scp 接受 61 KB 的文件,但其中两台拒绝任何超过 62 KB 的文件

我有三台 VM 服务器,运行相同的 Ubuntu 18.04 LTS。具有增量 IP 范围的标识符:

99.99.99.140
99.99.99.141
99.99.99.142

其中之一 (.141) 在将数据发送到任何托管在万维网上。我正在运行一个超级简单的测试来复制文件:

#!/bin/bash
# scp-speed-test.sh
# Author: Alec Jacobson alecjacobsonATgmailDOTcom
#
# Test ssh connection speed by uploading and then downloading a 10000K test
# file (optionally user-specified size)
#
# Usage:
#   ./scp-speed-test.sh user@hostname [test file size in KBs]
#

ssh_server=$1
test_file=".scp-test-file"

test_size=$2

# generate a x kilobytes random file
echo "Generating $test_size KB test file..."
`dd if=/dev/urandom of=$test_file bs=$(echo "$test_size*1024" | bc) \
  count=1 &> /dev/null`

# upload test
echo "Testing upload to $ssh_server..."
up_speed=`scp -v $test_file $ssh_server:$test_file 2>&1 | \
  grep "Bytes per second" | \
  sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\1/g"`
up_speed=`echo "($up_speed*0.0009765625*100.0+0.5)/1*0.01" | bc`

# download test
echo "Testing download to $ssh_server..."
down_speed=`scp -v $ssh_server:$test_file $test_file 2>&1 | \
  grep "Bytes per second" | \
  sed "s/^[^0-9]*\([0-9.]*\)[^0-9]*\([0-9.]*\).*$/\2/g"`
down_speed=`echo "($down_speed*0.0009765625*100.0+0.5)/1*0.01" | bc`

# clean up
echo "Removing test file on $ssh_server..."
`ssh $ssh_server "rm $test_file"`
echo "Removing test file locally..."
`rm $test_file`

# print result
echo ""
echo "Upload speed:   $up_speed KB/s"
echo "Download speed: $down_speed KB/s"

当上传到所有三个服务器时61千字节文件,一切顺利:

ZENBOOK:~$ ./scp-speed-test.sh [email protected] 61
Generating 61 KB test file...
Testing upload to [email protected]...
Testing download to [email protected]...
Removing test file on [email protected]...
Removing test file locally...

Upload speed:   78.98 KB/s
Download speed: 73.88 KB/s


ZENBOOK:~$ ./scp-speed-test.sh [email protected] 61
Generating 61 KB test file...
Testing upload to [email protected]...
Testing download to [email protected]...
Removing test file on [email protected]...
Removing test file locally...

Upload speed:   77.13 KB/s
Download speed: 74.59 KB/s


ZENBOOK:~$ ./scp-speed-test.sh [email protected] 61
Generating 61 KB test file...
Testing upload to [email protected]...
Testing download to [email protected]...
Removing test file on [email protected]...
Removing test file locally...

Upload speed:   73.11 KB/s
Download speed: 73.85 KB/s

然而,当重复上述,但与62千字节,突然,其中两个失败(.140 和 .142):


ZENBOOK:~$ ./scp-speed-test.sh [email protected] 62
Generating 62 KB test file...
Testing upload to [email protected]...
(standard_in) 1: syntax error
(standard_in) 1: syntax error
Testing download to [email protected]...
Removing test file on [email protected]...
Removing test file locally...

Upload speed:    KB/s                <-----------------------------------
Download speed: 65.02 KB/s


ZENBOOK:~$ ./scp-speed-test.sh [email protected] 62
Generating 62 KB test file...
Testing upload to [email protected]...
Testing download to [email protected]...
Removing test file on [email protected]...
Removing test file locally...

Upload speed:   81.97 KB/s
Download speed: 75.92 KB/s


ZENBOOK:~$ ./scp-speed-test.sh [email protected] 62
Generating 62 KB test file...
Testing upload to [email protected]...
(standard_in) 1: syntax error
(standard_in) 1: syntax error
Testing download to [email protected]...
Removing test file on [email protected]...
Removing test file locally...

Upload speed:    KB/s                <-----------------------------------
Download speed: 57.48 KB/s

如上所示,.140 和 .142 都无法正确接收文件。但,.141是在向任何主机发送大量(1 MB 以上)数据时出现问题的问题。

在 .140 上运行,文件大小为 62 KB:scp -vvv .scp-test-file [email protected]:.scp-test-file

debug1: Sending command: scp -v -t .scp-test-file
debug2: channel 0: request exec confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
Sending file modes: C0644 63488 .scp-test-file
debug2: channel 0: rcvd ext data 33
Sink: C0644 63488 .scp-test-file
.scp-test-file                                                                                                                              0%    0     0.0KB/s   --:-- ETA
debug2: channel 0: written 33 to efd 7

大约 20 秒后超时:

Sink: C0644 63488 .scp-test-file
.scp-test-file                                                                                                                              0%    0     0.0KB/s   --:-- ETA
debug2: channel 0: written 33 to efd 7
debug3: send packet: type 1
Connection reset by 99.99.99.140 port 22
lost connection

我读了https://superuser.com/questions/395356/scp-doesnt-work-but-ssh-does,但这并不是 scp 不起作用,它只是不适用于超过 62 KB 的任何内容。

另一个指向PMTU黑洞的方向,https://serverfault.com/questions/120505/problems-with-scp-stalling-during-file-copy-over-vpn,但我找不到任何类似的东西。

在他们的网络接口上运行 diff 不会给我带来任何结果:

ZENBOOK:~$ diff <(ssh [email protected] 'ifconfig | grep mtu | grep -v veth') <(ssh [email protected] 'ifconfig | grep mtu | grep -v veth')
ZENBOOK:~$ diff <(ssh [email protected] 'ifconfig | grep mtu | grep -v veth') <(ssh [email protected] 'ifconfig | grep mtu | grep -v veth')
ZENBOOK:~$ diff <(ssh [email protected] 'ifconfig | grep mtu | grep -v veth') <(ssh [email protected] 'ifconfig | grep mtu | grep -v veth')
ZENBOOK:~$

我将如何进一步调试这个?

编辑:来自评论:

为了消除可能的其他原因,我首先检查每个目标系统上的登录脚本是否不会输出任何消息或终端控制转义代码(如果连接不是交互式的)。例如,如果您运行 ssh[电子邮件受保护]/bin/true | od -t x1z,输出应该只是 0000000,没有其他内容。 ... – 昨天电信

ZENBOOK:~$ ssh [email protected] /bin/true | od -t x1z
0000000
ZENBOOK:~$ ssh [email protected] /bin/true | od -t x1z
0000000
ZENBOOK:~$ ssh [email protected] /bin/true | od -t x1z
0000000

相关内容