【OpenStack】SSH登录虚拟机出现"Read from socket failed: Connection reset by peer"问题的解决办法

声明:

本博客欢迎转发,但请保留原作者信息!

新浪微博:@孔令贤HW

博客地址:http://blog.csdn.net/lynn_kong

内容系本人学习、研究和总结,如有雷同,实属荣幸!


1、问题现象

版本:Grizzly master分支代码2013.06.17
部署:三个节点(Controller/Compute + Network + Compute)
使用的镜像:precise-server-cloudimg-i386-disk1.img
创建虚拟机命令:nova boot ubuntu-keypair-test --image 1f7f5763-33a1-4282-92b3-53366bf7c695 --flavor 2 --nic net-id=3d42a0d4-a980-4613-ae76-a2cddecff054 --availability-zone nova:compute233 --key_name mykey

虚拟机ACTIVE之后,可以ping通虚拟机的fixedip(10.1.1.6)和floatingip(192.150.73.5)。VNC访问虚拟机正常,出现登录界面。因为Ubuntu的镜像无法使用密码登录,所以只能通过SSH访问,这也是创建虚拟机时指定key_name的原因。

在NetworkNode通过ssh登录虚拟机失败:

root@network232:~# ssh -i mykey.pem ubuntu@192.150.73.5 -v
OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.150.73.5 [192.150.73.5] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file mykey.pem type -1
debug1: identity file mykey.pem-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: SSH2_MSG_KEXINIT sent
Read from socket failed: Connection reset by peer
虚拟机启动日志:

Begin: Running /scripts/init-bottom ... done.
[    1.874928] EXT4-fs (vda1): re-mounted. Opts: (null)
cloud-init start-local running: Mon, 17 Jun 2013 03:39:11 +0000. up 4.59 seconds
no instance data found in start-local
ci-info: lo    : 1 127.0.0.1       255.0.0.0       .
ci-info: eth0  : 1 10.1.1.6        255.255.255.0   fa:16:3e:31:f4:52
ci-info: route-0: 0.0.0.0         10.1.1.1        0.0.0.0         eth0   UG
ci-info: route-1: 10.1.1.0        0.0.0.0         255.255.255.0   eth0   U
cloud-init start running: Mon, 17 Jun 2013 03:39:14 +0000. up 8.23 seconds
2013-06-17 03:39:15,590 - util.py[WARNING]: 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [0/120s]: http error [404]
2013-06-17 03:39:17,083 - util.py[WARNING]: 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [2/120s]: http error [404]
2013-06-17 03:39:18,643 - util.py[WARNING]: 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [3/120s]: http error [404]
2013-06-17 03:39:20,153 - util.py[WARNING]: 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [5/120s]: http error [404]
2013-06-17 03:39:21,638 - util.py[WARNING]: 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [6/120s]: http error [404]
2013-06-17 03:39:23,071 - util.py[WARNING]: 'http://169.254.169.254/2009-04-04/meta-data/instance-id' failed [8/120s]: http error [404]
2013-06-17 03:41:15,356 - DataSourceEc2.py[CRITICAL]: giving up on md after 120 seconds

no instance data found in start
Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
 * Starting AppArmor profiles                                            [ OK ] 
landscape-client is not configured, please run landscape-config.
 * Stopping System V initialisation compatibility                        [ OK ]
 * Stopping Handle applying cloud-config                                 [ OK ]
 * Starting System V runlevel compatibility                              [ OK ]
 * Starting ACPI daemon                                                  [ OK ]
 * Starting save kernel messages                    
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
Connection reset by peer是一个常见的网络错误,它表示在TCP连接中对方(peer)意外关闭了连接。这种情况通常发生在服务器端关闭了连接,而客户端仍然试图读取数据。 在modbus TCP协议中,如果客户端在服务器端关闭连接后仍然尝试读取数据,就会出现Connection reset by peer错误。这通常是由于客户端在服务器关闭连接后没有正确处理连接关闭的情况导致的。 为了解决这个问题,你可以在客户端代码中添加异常处理来捕获Connection reset by peer错误,并在捕获到错误时进行相应的处理,例如重新建立连接或者退出程序。 以下是一个示例代码,演示了如何处理Connection reset by peer错误: ```python import socket # 创建socket连接 client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = ('localhost', 502) client_socket.connect(server_address) try: # 发送请求 request = b'\x01\x03\x00\x00\x00\x02\xC4\x0B' client_socket.sendall(request) # 接收响应 response = client_socket.recv(1024) print("Received response:", response) except ConnectionResetError: print("Connection reset by peer. Reconnecting...") # 重新建立连接 client_socket.close() client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect(server_address) finally: # 关闭连接 client_socket.close() ``` 在上述代码中,我们使用try-except语句来捕获ConnectionResetError异常,如果捕获到该异常,就会打印出"Connection reset by peer. Reconnecting..."的提示,并重新建立连接。无论是否捕获到异常,最后都会关闭连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值