【问题标题】:Unable to SSH to vagrant Ubuntu 16.04?无法通过 SSH 连接到 vagrant Ubuntu 16.04?
【发布时间】:2017-03-16 01:15:44
【问题描述】:

我创建了非常简单的 Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.box = "boxcutter/ubuntu1604"
  config.vm.hostname = "r1"
  config.vm.network "forwarded_port", guest: 3000, host: 3000

  config.vm.network "private_network", ip: "192.168.50.10"

  config.vm.provider "virtualbox" do |vb|
     vb.memory = "1024"
  end

end

启动 Ubuntu 16.04 服务器的一般用途。一切都很好,除了 SSH 连接的问题。

我的日志:

vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'boxcutter/ubuntu1604' is up to date...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> 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: 3000 (guest) => 3000 (host) (adapter 1)
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    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 the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

我替换 config.vm.box = "boxcutter/ubuntu1604" 使用框名称 "ubuntu/trusty64" 并且效果很好,但是如何使用 16.04 修复?

【问题讨论】:

  • 确保您拥有最新的 vagrant/virtualbox 旧版本和 Ubuntu 16.04 存在很多问题
  • 看来我在atlas.hashicorp.com/boxes/search 找到的“ubuntu/trusty64”是操作系统的桌面版本,而不是服务器版本。我在安装过程中遇到 'upgrade BIOS or use force_addr=0xaddr' 错误问题,但 Vagrant 没有显示错误。我导入并使用 - vagrant box add atlas.hashicorp.com/gbarbieru/boxes/xenial 并且效果很好。希望对某人有所帮助。
  • 所以,我解决了这个问题,将这段代码添加到 vagrantfile:vb.customize ["modifyvm", :id, "--cableconnected1", "on"]

标签: vagrant ubuntu-16.04 vagrantfile ubuntu-server


【解决方案1】:

我遇到了同样的问题,更新到最后一个 VirtualBox 和 vagrant 版本后解决了。试试“bento/ubuntu-16.04” vagrant box。 “ubuntu/xenial64”对我不起作用。

【讨论】:

    【解决方案2】:

    您是否尝试过错误中提到的解决方案? boot_timeout 默认为 300 秒 [1] - 你给 boxcutter 盒子多一点时间吗,例如600秒,看看之后会不会有反应?

    不过,ubuntu/trusty64 旁边还有 ubuntu/xenial64 [2],即 16.04 - 也许你想试试看。

    【讨论】:

    • 我尝试增加超时,并尝试使用 ubuntu/xenial64,如您所见。但结果相同..
    【解决方案3】:
    Vagrant.configure(2) do |config|
      config.vm.box = "ubuntu/xenial64"
      config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--memory", "2048"]
     end    
    

    试试这个可能对你有帮助。

    【讨论】: