通过 SSH 连接运行 CentOS 7 的 Hyper-V 虚拟机速度很慢

通过 SSH 连接运行 CentOS 7 的 Hyper-V 虚拟机速度很慢

我正在运行 Windows 10。我已启用 Hyper-V。我创建了三个运行 Centos 7 的 Hyper-V 虚拟机;具体来说:

Linux 版本 3.10.0-693.21.1.el7.x86_64 ([电子邮件保护]) (gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP 2018 年 3 月 7 日星期三 19:03:37 UTC

我有一个 NAT 网络设置。所有三个虚拟机都位于该网络上。当我从主机(我的 Windows 10 计算机)通过 ssh 连接到其中一个虚拟机时,痛苦地慢的。

发出 ssh 命令后,我等待超过 15 秒才出现输入密码的提示。然后我输入密码并再次等待超过 15 秒:

[email protected]'s password:
Connection to 192.168.40.5 closed by remote host.
Connection to 192.168.40.5 closed.

当我与交换机建立 ssh 连接时-vvv,我看到的内容如下:

debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
...waits...
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: pkalg rsa-sha2-512 blen 535
debug2: input_userauth_pk_ok: fp SHA256:3+l2I9j+Gv/Y2i3ksm00X3lIBjFEepj7uOCN4kQuy2A
debug3: sign_and_send_pubkey: RSA SHA256:3+l2I9j+Gv/Y2i3ksm00X3lIBjFEepj7uOCN4kQuy2A
debug3: send packet: type 50
debug3: receive packet: type 52
debug1: Authentication succeeded (publickey).
Authenticated to ***.***.***.7 ([***.***.***.7]:22).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Requesting [email protected]
debug3: send packet: type 80
debug1: Entering interactive session.
debug1: pledge: network
...waits...
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug3: receive packet: type 91
debug2: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: ssh_packet_set_tos: set IP_TOS 0x10
debug2: client_session2_setup: id 0
debug2: channel 0: request pty-req confirm 1
debug3: send packet: type 98
debug1: Sending environment.
debug3: Ignored env SHELL
debug3: Ignored env TERM
debug3: Ignored env USER
debug3: Ignored env NAME
debug3: Ignored env LS_COLORS
debug3: Ignored env HOSTTYPE
debug3: Ignored env PATH
debug3: Ignored env PWD
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug3: send packet: type 98
debug3: Ignored env SHLVL
debug3: Ignored env HOME
debug3: Ignored env LOGNAME
debug3: Ignored env LESSOPEN
debug3: Ignored env LESSCLOSE
debug3: Ignored env _
debug2: channel 0: request shell confirm 1
debug3: send packet: type 98
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
...waits...
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0

我的机器的sshd_config:

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
SyslogFacility AUTHPRIV
AuthorizedKeysFile      .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication no
GSSAPICleanupCredentials no
UsePAM yes
X11Forwarding yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem       sftp    /usr/libexec/openssh/sftp-server
  • 我在连接任何 CentOS VM 时都遇到了速度缓慢的问题
  • 从主机(Windows 10 机器)或其他 CentOS VM 之一连接时会出现上述缓慢现象
  • 虚拟机位于同一子网
  • 虚拟机被分配了静态 IP 地址

我想解决速度慢的问题。有什么建议或想法吗?

添加其中一个 CentOS VM 的详细信息:

ParentCheckpointId                  : a76e4644-66c3-4d8a-b252-1e671f2c3c7c
ParentCheckpointName                : sbx-misc-app01 - (5/3/2018 - 12:20:00 AM)
VMName                              : sbx-misc-app01
VMId                                : a283e141-b32b-428d-8d3b-a64cf08b1ee8
CheckpointFileLocation              : C:\Hyper-V\Virtual Machines
ConfigurationLocation               : C:\Hyper-V\Virtual Machines
SmartPagingFileInUse                : False
SmartPagingFilePath                 : C:\Hyper-V\Virtual Machines
SnapshotFileLocation                : C:\Hyper-V\Virtual Machines
AutomaticStartAction                : StartIfRunning
AutomaticStartDelay                 : 0
AutomaticStopAction                 : Save
AutomaticCriticalErrorAction        : Pause
AutomaticCriticalErrorActionTimeout : 30
AutomaticCheckpointsEnabled         : True
CPUUsage                            : 0
MemoryAssigned                      : 1612709888
MemoryDemand                        : 1031798784
MemoryStatus                        : OK
NumaAligned                         : False
NumaNodesCount                      : 1
NumaSocketCount                     : 1
Heartbeat                           : OkApplicationsUnknown
IntegrationServicesState            : 
IntegrationServicesVersion          : 0.0
Uptime                              : 18:23:29.4550000
OperationalStatus                   : {Ok}
PrimaryOperationalStatus            : Ok
SecondaryOperationalStatus          : 
StatusDescriptions                  : {Operating normally}
PrimaryStatusDescription            : Operating normally
SecondaryStatusDescription          : 
Status                              : Operating normally
ReplicationHealth                   : NotApplicable
ReplicationMode                     : None
ReplicationState                    : Disabled
ResourceMeteringEnabled             : False
CheckpointType                      : Standard
EnhancedSessionTransportType        : VMBus
Groups                              : {}
Version                             : 8.3
VirtualMachineType                  : RealizedVirtualMachine
VirtualMachineSubType               : Generation2
Notes                               : 
State                               : Running
ComPort1                            : VMComPort (Name = 'COM 1', VMName = 'sbx-misc-app01') [Id = 'Microsoft:A283E141-B32B-428D-8D3B-A64CF08B1EE8\8E3A359F-559A-4B6A-98A9-1690A6100ED7\0', VMId = 
                                      'a283e141-b32b-428d-8d3b-a64cf08b1ee8']
ComPort2                            : VMComPort (Name = 'COM 2', VMName = 'sbx-misc-app01') [Id = 'Microsoft:A283E141-B32B-428D-8D3B-A64CF08B1EE8\8E3A359F-559A-4B6A-98A9-1690A6100ED7\1', VMId = 
                                      'a283e141-b32b-428d-8d3b-a64cf08b1ee8']
DVDDrives                           : {DVD Drive on SCSI controller number 0 at location 1}
FibreChannelHostBusAdapters         : {}
FloppyDrive                         : 
HardDrives                          : {Hard Drive on SCSI controller number 0 at location 0}
RemoteFxAdapter                     : 
VMIntegrationService                : {Guest Service Interface, Heartbeat, Key-Value Pair Exchange, Shutdown...}
DynamicMemoryEnabled                : True
MemoryMaximum                       : 8589934592
MemoryMinimum                       : 536870912
MemoryStartup                       : 8589934592
ProcessorCount                      : 2
BatteryPassthroughEnabled           : True
Generation                          : 2
IsClustered                         : False
ParentSnapshotId                    : a76e4644-66c3-4d8a-b252-1e671f2c3c7c
ParentSnapshotName                  : sbx-misc-app01 - (5/3/2018 - 12:20:00 AM)
Path                                : C:\Hyper-V\Virtual Machines
SizeOfSystemFiles                   : 69632
GuestControlledCacheTypes           : False
LowMemoryMappedIoSpace              : 134217728
HighMemoryMappedIoSpace             : 536870912
LockOnDisconnect                    : Off
CreationTime                        : 5/2/2018 10:23:06 PM
Id                                  : a283e141-b32b-428d-8d3b-a64cf08b1ee8
Name                                : sbx-misc-app01
NetworkAdapters                     : {Network Adapter}
CimSession                          : CimSession: .
ComputerName                        : Thinger
IsDeleted                           : False

这是网络设置代码...

$switch_name = 'sbx-ext01'
$nat_name = 'net-sbx-ext01'
$nat_subnet_prefix_length = 24
$gateway_ip_address = '192.168.40.0'

New-VMSwitch -SwitchName $switch_name -SwitchType Internal

$interface_index = $(Get-NetAdapter -Name "*${switch_name}*").ifIndex

New-NetIPAddress `
    -IPAddress 192.168.40.1 `
    -PrefixLength 24 `
    -InterfaceIndex $interface_index

New-NetNat -Name $nat_name `
    -InternalIPInterfaceAddressPrefix $gateway_ip_address/$nat_subnet_prefix_length

答案1

不清楚“慢得令人痛苦”是什么意思。你的意思是,一旦你通过 ssh 连接,它就会很慢吗?或者你的意思是,一旦你输入密码并按下回车键,需要很长时间(30 秒)才能得到提示?

如果您需要 30-60 秒才能收到提示,这可能是由于 SSH 服务器尝试反向解析连接客户端的 IP 地址。我见过这种情况发生在resolv.conf服务器上配置的 DNS 服务器出现问题时,例如它们超时。

ssd_config一种解决方案是在每台机器上设置以下内容:

UseDNS no

默认情况下启用此功能。

nameserver另一个解决方案是更正resolv.conf

如果这不能解决您的问题,您能否补充更多有关“非常慢”的含义的详细信息?

相关内容