Windows下的Vagrant无法vagrant-up和ssh连接

3

我观看了很多关于Vagrant的视频,看起来非常简单:只要安装VirtualBox和Vargant,然后在Vagrantfile中指定虚拟机名称,运行$ vagrant up,你就可以直接使用$ vagrant ssh 进入虚拟机。

然而,经过一个周末以及许多头痛/键盘损坏,这仍然不起作用。

PS C:\dev\web> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty32' is up to date...
==> default: Setting the name of the VM: web_default_1468168716511_77856
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

同时,如果我打开VirtualBox管理器并打开新安装的虚拟机,我可以使用“vargant”作为用户名和密码完全连接到它,我可以看到它上面没有安装任何东西。但我不能通过PuTTY或Cygwin ssh到它。
执行$vagrant ssh-config命令输出以下内容:
PS C:\dev\web> vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/User/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

我的 Vagrantfile:

Vagrant.configure("2") do |config|

  config.vm.box = "ubuntu/trusty32"

   config.vm.provider "virtualbox" do |vb|

     vb.gui = true

   end

   config.vm.provision "shell", inline: <<-SHELL
     apt-get update
     apt-get install -y apache2
   SHELL
end

我尝试了serverfault和stackoverflow上列出的所有方法,但没有看到任何人遇到这个问题的视频,他们只是运行vagrant,然后一切正常...

编辑:我在Windows Server上尝试过,它可以完美地开箱即用。所以这很可能是与Windows 10或其他相关的问题。


你是否在嵌套虚拟化环境中运行Vagrant?也就是说,你的主机是一个虚拟机吗? - frankgreco
@Frank 当我查看虚拟机时,有一些与网络相关的错误和失败的消息。它太快了,我无法阅读它,尝试在屏幕上录制它,但仍然无法阅读它。也许这是VBox的问题?因为Vagrant无法连接到它,甚至无法运行初始bash。 - TheWalkingPanda
我有同样的问题。 - Nighon
同样的问题,但只出现在使用trusty32而不是trusty64时。 - Maik
有没有解决方案?我在2021年遇到了这个问题。 - Minion
显示剩余2条评论
2个回答

0
今天我遇到了一个非常类似的问题,我正在启动一个与你略有不同的环境(Cent OS 7),但安装VirtualBox Guest Additions可能会有所帮助。命令vagrant plugin install vagrant-vbguest应该可以解决问题。 我找到这个页面上还有其他一些可能有用的信息。

0

我在Windows 10上遇到了同样的问题,安装VirtualBox Oracle VM VirtualBox Extension Pack有所帮助。


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