【问题标题】:Vagrant-Libvirt Hanging on SSH ConnectionVagrant-Libvirt 挂在 SSH 连接上
【发布时间】:2015-10-13 20:36:16
【问题描述】:

当我运行 vagrant up 时,我的设置在尝试使用 insecure_private_key 连接到 VM 时挂起。它不断尝试和尝试类似这样的输出:

 INFO retryable: Retryable exception raised: #<Errno::ECONNRESET: Connection reset by peer>
 INFO ssh: Attempting to connect to SSH...
 INFO ssh:   - Host: 192.168.121.80
 INFO ssh:   - Port: 22
 INFO ssh:   - Username: vagrant
 INFO ssh:   - Password? false
 INFO ssh:   - Key Path: ["/home/users/swalter/.vagrant.d/insecure_private_key"]
DEBUG ssh: == Net-SSH connection debug-level log START ==
DEBUG ssh: D, [2015-10-13T15:04:11.236064 #24396] DEBUG -- net.ssh.transport.session[3fa468444c28]: establishing connection to 192.168.121.80:22
D, [2015-10-13T15:04:11.236454 #24396] DEBUG -- net.ssh.transport.session[3fa468444c28]: connection established
I, [2015-10-13T15:04:11.236614 #24396]  INFO -- net.ssh.transport.server_version[3fa468444264]: negotiating protocol version
D, [2015-10-13T15:04:11.262088 #24396] DEBUG -- net.ssh.transport.server_version[3fa468444264]: remote is `SSH-2.0-OpenSSH_5.3'
D, [2015-10-13T15:04:11.262176 #24396] DEBUG -- net.ssh.transport.server_version[3fa468444264]: local is `SSH-2.0-Ruby/Net::SSH_2.9.1 x86_64-linux'
D, [2015-10-13T15:04:11.263494 #24396] DEBUG -- tcpsocket[3fa468444868]: read 840 bytes
D, [2015-10-13T15:04:11.263615 #24396] DEBUG -- tcpsocket[3fa468444868]: received packet nr 0 type 20 len 836
I, [2015-10-13T15:04:11.263706 #24396]  INFO -- net.ssh.transport.algorithms[3fa4683ed9c8]: got KEXINIT from server
I, [2015-10-13T15:04:11.263819 #24396]  INFO -- net.ssh.transport.algorithms[3fa4683ed9c8]: sending KEXINIT
D, [2015-10-13T15:04:11.264016 #24396] DEBUG -- tcpsocket[3fa468444868]: queueing packet nr 0 type 20 len 2020
D, [2015-10-13T15:04:11.264098 #24396] DEBUG -- tcpsocket[3fa468444868]: sent 2024 bytes
I, [2015-10-13T15:04:11.264130 #24396]  INFO -- net.ssh.transport.algorithms[3fa4683ed9c8]: negotiating algorithms
D, [2015-10-13T15:04:11.264253 #24396] DEBUG -- net.ssh.transport.algorithms[3fa4683ed9c8]: 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:
D, [2015-10-13T15:04:11.264283 #24396] DEBUG -- net.ssh.transport.algorithms[3fa4683ed9c8]: exchanging keys
D, [2015-10-13T15:04:11.264478 #24396] DEBUG -- tcpsocket[3fa468444868]: queueing packet nr 1 type 34 len 20
D, [2015-10-13T15:04:11.264533 #24396] DEBUG -- tcpsocket[3fa468444868]: sent 24 bytes
D, [2015-10-13T15:04:11.265762 #24396] DEBUG -- tcpsocket[3fa468444868]: read 152 bytes
D, [2015-10-13T15:04:11.265844 #24396] DEBUG -- tcpsocket[3fa468444868]: received packet nr 1 type 31 len 148
D, [2015-10-13T15:04:11.267446 #24396] DEBUG -- tcpsocket[3fa468444868]: queueing packet nr 2 type 32 len 140
D, [2015-10-13T15:04:11.267521 #24396] DEBUG -- tcpsocket[3fa468444868]: sent 144 bytes
D, [2015-10-13T15:04:11.269986 #24396] DEBUG -- tcpsocket[3fa468444868]: read 720 bytes
D, [2015-10-13T15:04:11.270066 #24396] DEBUG -- tcpsocket[3fa468444868]: received packet nr 2 type 33 len 700
D, [2015-10-13T15:04:11.271360 #24396] DEBUG -- tcpsocket[3fa468444868]: queueing packet nr 3 type 21 len 20
D, [2015-10-13T15:04:11.271432 #24396] DEBUG -- tcpsocket[3fa468444868]: sent 24 bytes
D, [2015-10-13T15:04:11.271491 #24396] DEBUG -- tcpsocket[3fa468444868]: received packet nr 3 type 21 len 12
D, [2015-10-13T15:04:11.271752 #24396] DEBUG -- net.ssh.authentication.session[3fa468414758]: beginning authentication of `vagrant'
D, [2015-10-13T15:04:11.271858 #24396] DEBUG -- tcpsocket[3fa468444868]: queueing packet nr 4 type 5 len 28
D, [2015-10-13T15:04:11.271905 #24396] DEBUG -- tcpsocket[3fa468444868]: sent 52 bytes
D, [2015-10-13T15:04:11.311362 #24396] DEBUG -- tcpsocket[3fa468444868]: read 52 bytes
D, [2015-10-13T15:04:11.311453 #24396] DEBUG -- tcpsocket[3fa468444868]: received packet nr 4 type 6 len 28
D, [2015-10-13T15:04:11.311547 #24396] DEBUG -- net.ssh.authentication.session[3fa468414758]: trying none
D, [2015-10-13T15:04:11.311650 #24396] DEBUG -- tcpsocket[3fa468444868]: queueing packet nr 5 type 50 len 44
D, [2015-10-13T15:04:11.311709 #24396] DEBUG -- tcpsocket[3fa468444868]: sent 68 bytes
D, [2015-10-13T15:04:11.312042 #24396] DEBUG -- tcpsocket[3fa468444868]: read 84 bytes
D, [2015-10-13T15:04:11.312109 #24396] DEBUG -- tcpsocket[3fa468444868]: received packet nr 5 type 51 len 60
D, [2015-10-13T15:04:11.312177 #24396] DEBUG -- net.ssh.authentication.session[3fa468414758]: allowed methods: publickey,gssapi-keyex,gssapi-with-mic,password
D, [2015-10-13T15:04:11.312226 #24396] DEBUG -- net.ssh.authentication.methods.none[3fa46845d0d4]: none failed
D, [2015-10-13T15:04:11.312276 #24396] DEBUG -- net.ssh.authentication.session[3fa468414758]: trying publickey
D, [2015-10-13T15:04:11.312520 #24396] DEBUG -- net.ssh.authentication.agent[3fa46846971c]: connecting to ssh-agent
D, [2015-10-13T15:04:11.312672 #24396] DEBUG -- net.ssh.authentication.agent[3fa46846971c]: sending agent request 1 len 44

DEBUG ssh: == Net-SSH connection debug-level log END ==

如果我使用它尝试 ssh 的 ip 地址,打开一个新终端,ssh -i ~/.vagrant.d/insecure_private_key vagrant@192.168.121.80 它工作得很好。

我如何能够 ssh 到实例而不是这个 vagrant 进程?

这是我的配置文件:

Vagrant.configure("2") do |config|
config.vm.box = "centos/6"
config.ssh.insert_key = false
# Controller node
config.vm.define "vbit00" do |n|
    n.vm.network "private_network", ip: "192.168.122.10", netmask: "255.255.255.0"
    n.vm.provider :libvirt do |libvirt|
        libvirt.driver = "kvm"
        libvirt.connect_via_ssh = false
        libvirt.username = "root"
        libvirt.storage_pool_name = "default"
        libvirt.memory = 2048
    end
end

# Storage nodes
config.vm.define "vbit06" do |n|
    n.vm.network "private_network", ip: "192.168.122.20", netmask: "255.255.255.0"
    n.vm.network "private_network", ip: "192.168.123.20", netmask: "255.255.255.0"
    n.vm.provider :libvirt do |libvirt|
        libvirt.driver = "kvm"
        libvirt.connect_via_ssh = false
        libvirt.username = "root"
        libvirt.storage_pool_name = "default"
        libvirt.storage :file, :size=> '11G'
        libvirt.memory = 1024
    end
end
config.vm.define "vbit07" do |n|
    n.vm.network "private_network", ip: "192.168.122.21", netmask: "255.255.255.0"
    n.vm.network "private_network", ip: "192.168.123.21", netmask: "255.255.255.0"
    n.vm.provider :libvirt do |libvirt|
        libvirt.driver = "kvm"
        libvirt.connect_via_ssh = false
        libvirt.username = "root"
        libvirt.storage_pool_name = "default"
        libvirt.storage :file, :size=> '11G'
        libvirt.memory = 1024
    end
end

# Compute nodes
config.vm.define "vbit10" do |n|
    n.vm.network "private_network", ip: "192.168.122.30", netmask: "255.255.255.0"
    n.vm.network "private_network", ip: "192.168.123.30", netmask: "255.255.255.0"
    n.vm.provider :libvirt do |libvirt|
        libvirt.driver = "kvm"
        libvirt.connect_via_ssh = false
        libvirt.username = "root"
        libvirt.storage_pool_name = "default"
        libvirt.storage :file, :size=>"5G"
        libvirt.memory = 4096
    end
end
config.vm.define "vbit11" do |n|
    n.vm.network "private_network", ip: "192.168.122.31", netmask: "255.255.255.0"
    n.vm.network "private_network", ip: "192.168.123.31", netmask: "255.255.255.0"
    n.vm.provider :libvirt do |libvirt|
        libvirt.driver = "kvm"
        libvirt.connect_via_ssh = false
        libvirt.username = "root"
        libvirt.storage_pool_name = "default"
        libvirt.storage :file, :size=>'5G'
        libvirt.memory = 4096
    end
end
end

【问题讨论】:

    标签: ssh vagrant libvirt


    【解决方案1】:

    我想通了。 vagrant 负责将本地主机的 2222 端口转发到远程主机的 22 端口的任何责任都不起作用。我使用 ssh 设置自己的端口,如下所示:ssh -L 2222:192.168.121.24:22 127.0.0.1

    其中 192.168.121.24 是尝试启动的虚拟机的 IP 地址。我知道 IP 地址是因为我正在查看日志。然而,奇怪的是,在我销毁该 VM 并重新创建它之后,它就起作用了。我不需要使用新 VM 的 IP 地址重新创建端口转发。就像 vagrant 看到它工作一次,它就会停止向前检查端口。

    无论哪种方式,它现在都在工作,但仅在我创建端口转发的终端中。我想可以使用 iptables 或 firewalld 完成更多系统范围的端口转发。

    【讨论】: