简体   繁体   English

Ruby net / ssh与特定主机挂起

[英]Ruby net/ssh hangs with specific host

I have an issue where if I'm trying to create a ssh connection to a specific host, the connection hangs without timing out. 我有一个问题,如果我要创建到特定主机的ssh连接,该连接将挂起而不会超时。 I have tried connecting to this host from the same machine from outside the rails console and it works so I'm assuming this shouldn't be anything related to routing/firewall. 我尝试从Rails控制台外部的同一台计算机连接到该主机,并且它可以正常工作,因此我假设这与路由/防火墙无关。 I can also confirm I have several other hosts with the exact same OS configuration in different places and they work. 我还可以确认我在不同的地方还有其他几台具有完全相同的OS配置的主机,并且它们可以正常工作。

This is the log when running Net::SSH.start in debug mode: 这是在调试模式下运行Net::SSH.start时的日志:

ssh = Net::SSH.start("1.2.3.4", "user", password: "password", verbose: :debug)
2014-02-27 13:17:43 +0100 [DEBUG] establishing connection to 1.2.3.4:22
2014-02-27 13:17:43 +0100 [DEBUG] connection established
2014-02-27 13:17:43 +0100 [INFO] negotiating protocol version
2014-02-27 13:17:43 +0100 [DEBUG] remote is `SSH-2.0-OpenSSH_4.3'
2014-02-27 13:17:43 +0100 [DEBUG] local is `SSH-2.0-Ruby/Net::SSH_2.6.8 i686-linux'
2014-02-27 13:17:43 +0100 [DEBUG] read 704 bytes
2014-02-27 13:17:43 +0100 [DEBUG] received packet nr 0 type 20 len 700
2014-02-27 13:17:43 +0100 [INFO] got KEXINIT from server
2014-02-27 13:17:43 +0100 [INFO] sending KEXINIT
2014-02-27 13:17:43 +0100 [DEBUG] queueing packet nr 0 type 20 len 1620
2014-02-27 13:17:43 +0100 [DEBUG] sent 1624 bytes
2014-02-27 13:17:43 +0100 [INFO] negotiating algorithms
2014-02-27 13:17:43 +0100 [DEBUG] negotiated:
* kex: diffie-hellman-group-exchange-sha1
* host_key: ssh-rsa
* encryption_server: aes128-cbc
* encryption_client: aes128-cbc
* hmac_client: hmac-sha1
* hmac_server: hmac-sha1
* compression_client: none
* compression_server: none
* language_client: 
* language_server: 
2014-02-27 13:17:43 +0100 [DEBUG] exchanging keys
2014-02-27 13:17:43 +0100 [DEBUG] queueing packet nr 1 type 34 len 20
2014-02-27 13:17:43 +0100 [DEBUG] sent 24 bytes

At this point the ssh connection just hangs and could stay like this for 15-30 minutes. 此时,ssh连接刚刚挂起,可以像这样保持15-30分钟。 Unfortunately I have no error message or anything so I'm really clueless about what the problem might be. 不幸的是,我没有任何错误消息或任何消息,因此我对问题可能是什么一无所知。

Some specs: 一些规格:

ruby-2.0.0-p0
rails (3.2.13)
net-ssh-2.8.0

The IP address in the log is not a real IP on purpose. 日志中的IP地址不是故意的真实IP。

Any suggestion about what the problem could be? 关于这个问题可能有什么建议吗? Or maybe some other log or place I could check out? 还是我可以签出的其他日志或地方? I found a similar problem outside SO but it didn't get a solution so I'm trying to ask here... 我在SO之外发现了类似的问题,但没有找到解决方案,所以我想在这里问...

I solved by reducing maximum transmission unit (MTU). 我通过减少最大传输单位 (MTU)来解决。 My environment was some specific case. 我的环境是一些特定情况。 I was trying ssh from VMware Virtual Machine to Openstack Instance. 我正在尝试从VMware虚拟机到Openstack实例使用ssh。 And openstack needed smaller packet to be connected by kitchen-openstack which is using fog , using NET::SSH. Openstack需要较小的数据包通过使用 fogkitchen-openstack通过NET :: SSH连接。 Not sure if this works for you, but have a try for these commands (assuming in Ubuntu): 不知道这是否适合您,但是请尝试以下命令(假设在Ubuntu中):

  1. check your MTU 检查您的MTU

    sudo netstat -i 须藤netstat -i

  2. You'll get some output like this, in the second column, you can check MTU: 您将获得类似以下的输出,在第二列中,您可以检查MTU:

    Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg Iface MTU满足RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg

    eth0 1500 0 9658 0 0 0 308 0 0 0 BMRU eth0 1500 0 9658 0 0 0 308 0 0 0 BMRU

    lo 16436 0 12952 0 0 0 12952 0 0 0 LRU lo 16436 0 12952 0 0 0 12952 0 0 0 LRU

  3. For network interface eth0, you can try to reduce MTU from 1500 to, for example 1400 like this: 对于网络接口eth0,您可以尝试将MTU从1500降低到例如1400,如下所示:

    sudo ifconfig eth0 mtu 1400 须藤ifconfig eth0 mtu 1400

  4. try net ssh 试试net ssh

    ssh = Net::SSH.start("1.2.3.4", "user", password: "password", verbose: :debug) ssh = Net :: SSH.start(“ 1.2.3.4”,“ user”,密码:“ password”,详细::debug)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM