Vagrant无法连接到虚拟机。

3
EDIT6:提交了一个官方路径错误:https://github.com/mitchellh/vagrant/issues/7512 EDIT5:当我执行vagrant destroyvagrant up时,一切都很容易。但是当我关闭虚拟机并重新打开它(你总有一天需要重启电脑),它就再也无法工作了。不管是创建虚拟机时vagrant up的顺序出现问题还是VirtualBox出现问题,销毁和重建虚拟机都不是选项,因为数据库迁移和其他操作至少需要30分钟。不管怎样,不要在Windows 10上使用Vagrant。 EDIT4:我降级到了Virtual Box 5.0.0.10版本,解决了路径错误的问题,但是这个错误Command not in installer仍然存在。
EDIT3:当我进入vagrant up --debug时,发现它在循环中。它进入了下面这行:
INFO subprocess: Starting process: ["C:/Program Files/Oracle/VirtualBox/VBoxManage.exe", "showvminfo", "8aaee3a3-806f-4
8ad-9928-91e2b7baba5d", "--machinereadable"]

然后它就这样执行

INFO subprocess: Command not in installer, restoring original environment...

VM路径使用正斜杠而不是反斜杠。这是一个错误吗?有没有办法手动设置VM的路径?我已经把 C:\Program Files\Oracle\VirtualBox 放在了我的PATH中。 编辑2: 不要在Windows 10上使用Vagrant,它有很多缺陷,而且VM还没有为win10进行优化,你会遇到无法解决的问题。我也尝试了来自Hashicorp的Otto,但也不起作用。Rip。 编辑:好吧,当我运行vagrant destroyvagrant up后,在安装了10分钟后,它可以完美地工作。但是在我重新启动电脑或以任何方式退出登录后,Vagrant无法连接到VM,无论是用私钥还是登录/密码都不行。这是一个错误吗? 当我运行vagrant up时,VM能够正确启动,但是Vagrant无法连接。它只会显示:Warning: Remote connection disconnect. Retrying...。当我尝试通过vagrant ssh连接时,我只得到ssh_exchange_identification: read: Connection reset by peer。当我检查VM的GUI时,它正在等待登录,当我使用默认的登录名/密码登录时,它按预期工作,所以问题必须是Vagrant无法连接到VM。 我尝试过: 1. 检查我的电脑是否支持虚拟化并检查其是否已开启 2. 尝试使用密码而不是密钥进行连接 3. 配置网络适配器 4. 关闭防火墙 5. 进行干净的重新安装。 我正在Windows 10上使用Vagrant 1.8.1和VirtualBox 5.0.20。这是我的vagrant文件:
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "ubuntu/trusty64"

  config.vm.provider :virtualbox do |vb|
    vb.memory = 2048
    vb.gui = true
    vb.cpus = 2
  end


  config.vm.network :private_network, type: "dhcp"
  config.vbguest.auto_update = false

  config.ssh.insert_key = false

  config.vm.provision :shell, path: "bootstrap.sh"

end

1
很难说,但如果您仍然可以从虚拟机登录,我建议您这样做并检查所有的 sshd 配置,是否可以通过引导程序或任何其他运行的命令进行修改? - Frederic Henri
你可以尝试创建一个名为VBOX_USER_HOME的新环境变量,并将其指向你的虚拟盒安装。 - Frederic Henri
1个回答

1

[编辑于2016年6月17日]
问题应该已经在Virtualbox 5.0.22中得到解决。

https://www.virtualbox.org/wiki/Changelog
https://www.virtualbox.org/ticket/15412

[以下是原始答案]
与我早先的答案相反,我现在不认为我遇到了你在这里描述的同样的问题。然而,我仍然认为你遇到了一个不同的变种问题。

根据从Virtualbox开发团队https://www.virtualbox.org/ticket/15412收到的反馈,我了解到Virtualbox 5.0.20对NAT转发规则进行了更改,以解决其他错误。当虚拟机保存并重新启动时,Virtualbox现在会断开5秒钟的网络电缆。这应该会触发DHCP客户端请求新租约。然后Virtualbox使用此信息推断IP地址和NAT是否正常工作。

就我的特定情况而言,我在Ubuntu 16.04作为guest VM中遇到了这个问题,而在Ubuntu 14.04中可以正常工作。这表明Ubuntu 14.04上的DHClient在Virtualbox断开电缆后确实会请求新租赁,而在Ubuntu 16.04上则不是这种情况。

为了验证你是否遇到了相同的问题,我想知道你是否能运行下面的测试,并让我知道。

  1. Login to the Trusty VM console (i.e. the one that you get displayed when you run the VM in the foreground)
  2. Install 'arping' (sudo apt-get -y install arping)
  3. Create the below script 'sendARP.sh'

    #!/bin/bash
    
    IFACE=$(ifconfig | grep 'Link encap:Ethernet' | awk '{print $1}')
    IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
    
    arping -c 1 -i $IFACE $IP
    
  4. Make it an executable 'chmod +x sendARP.sh'
  5. Save the Trusty VM (vagrant suspend)
  6. Start your Trusty VM from saved state (vagrant up)
  7. Login to the Trusty VM console (i.e. the one that you get displayed when you run the VM in the foreground)
  8. Run the script 'sudo ./sendARP.sh'
  9. Test whether you can connect via SSH from the remote location/ Virtualbox host
错误:

https://github.com/mitchellh/vagrant/issues/7306

https://www.virtualbox.org/ticket/15412


已经安装了VM 5.0.22和Vagrant 1.8.4,问题仍然存在。当我销毁并重新启动vagrant时,一切正常。但是当我使用vagrant halt命令停止虚拟机后再次使用vagrant up命令启动时,问题依旧。 - Miloš Lukačka
@MilošLukačka 当您执行 vagrant suspend 然后执行 vagrant up 时,它是否有效? - quat
是的,因为 vagrant suspendvagrant halt + vagrant destroy 是一样的。我已经将此问题提交为错误路径错误。https://github.com/mitchellh/vagrant/issues/7512 - Miloš Lukačka
1
@MilošLukačka 好的,这个测试是值得的。无论如何,只是为了澄清一下,vagrant suspend 不等同于 vagrant halt + vagrant destroyvagrant suspend 保存了虚拟机的状态。因此,当您执行 vagrant up 时,虚拟机会从上次停止的地方继续运行。虚拟机完全不知道它被停止过。 - quat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接