El Capitan 上的 Vagrant / Vaprobash 问题

Posted

技术标签:

【中文标题】El Capitan 上的 Vagrant / Vaprobash 问题【英文标题】:Vagrant / Vaprobash problems on El Capitan 【发布时间】:2015-10-20 15:06:39 【问题描述】:

自从升级到 El Cap 后,我一直遇到 Vagrant / Vaprobash 的问题。这发生在两个不同的 Mac 上,并且都使用最新的 Vagrant 和 VirtualBox 版本进行了升级。

VM 确实使用vagrant up 启动(至少,如果您在 VirtualBox 管理员中查看它正在运行的框,即使您无法连接到它),但在启动过程中它会不断超时:

    Bringing machine 'Vaprobash' up with 'virtualbox' provider...
==> Vaprobash: Checking if box 'ubuntu/trusty64' is up to date...
==> Vaprobash: Clearing any previously set forwarded ports...
==> Vaprobash: Clearing any previously set network interfaces...
==> Vaprobash: Preparing network interfaces based on configuration...
    Vaprobash: Adapter 1: nat
    Vaprobash: Adapter 2: hostonly
==> Vaprobash: Forwarding ports...
    Vaprobash: 22 => 2222 (adapter 1)
==> Vaprobash: Running 'pre-boot' VM customizations...
==> Vaprobash: Booting VM...
==> Vaprobash: Waiting for machine to boot. This may take a few minutes...
    Vaprobash: SSH address: 127.0.0.1:2222
    Vaprobash: SSH username: vagrant
    Vaprobash: SSH auth method: private key
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
    Vaprobash: Warning: Connection timeout. Retrying...
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.

当盒子最终“运行”时,我无法连接到它。如果我使用 VirtualBox 打开终端,连接超时似乎是 VM 正在等待登录屏幕输入的提示。但是,这个登录应该由 Vagrant 处理。

关于如何解决这个问题的任何想法?

【问题讨论】:

【参考方案1】:

经过多次撕裂头发和磨牙,重新安装 Vagrant,VirtualBox 并多次删除/安装我所有的盒子图像,我终于能够通过完全删除所有 vagrant 数据(rm -rf ~/.vagrant.d/)来完成这项工作,卸载vagrant app (rm -rf /usr/bin/vagrant) 然后重新安装 vagrant app。

然后我执行了vagrant up,它重新生成了所有的键,这似乎终于成功了。我已经手动删除并重新生成了密钥,以及将我自己的 id_rsa 复制到 .vagrant.d 中的 insecure_private_key 文件上,但没有运气——并且在没有先删除所有数据的情况下重新安装 vagrant 将无法解决问题。

希望这对其他人有所帮助。

【讨论】:

【参考方案2】:

你的流浪文件有 vb.gui = true 吗?如果没有,请添加:

config.vm.provider :virtualbox do |vb|
  vb.gui = true
end

如果没问题,那么您的 ssh 密钥可能有问题。 您可以尝试以下步骤:

从here下载私钥并尝试登录vagrant box。

ssh -i privatekey vagrant@ip

从here 下载私钥并存储在某处并在 vagrant 文件中添加以下行:

config.ssh.private_key_path="full_path_of_ssh_privatekey"

然后尝试使用命令登录:

vagrant ssh vmname

或 可能是您的 vagrant 公钥未存储在 vagrant vm 中。因此您可以创建 shell 脚本 test.sh 并在 test.sh 文件中添加以下行

mkdir /home/vagrant/.ssh
wget --no-check-certificate -O authorized_keys 'https://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub'
mv authorized_keys /home/vagrant/.ssh
chown -R vagrant /home/vagrant/.ssh
chmod -R go-rwsx /home/vagrant/.ssh

并在 Vagrantfile 中使用 shell 配置器,例如:

config.vm.provision :shell, :path => "test.sh"

然后配置该虚拟机

vagrant reload vmname --provision 

或者你可以使用命令重新创建虚拟机

vagrant destroy vmname
vagrant up vmname

【讨论】:

@pl_rock-- 谢谢,但关键是 vagrant 应该能够自己登录 - 我过去从来不需要 GUI 登录。 我也多次遇到同样的问题,但它显示我的 ssh 密钥不在正确位置。 对修复 ssh 密钥问题有何建议? 下载私钥github.com/mitchellh/vagrant/tree/master/keys并尝试使用ssh -i keys vagrant@ip进行ssh

以上是关于El Capitan 上的 Vagrant / Vaprobash 问题的主要内容,如果未能解决你的问题,请参考以下文章

OS X El Capitan 上的 MySQLdb 错误

在 mac el capitan 上的 xampp 上的 xdebug

El Capitan 上的 PHP.ini 位置

由于“链接器命令失败,退出代码为 1(使用 -v 查看调用)”,无法在 El Capitan 上为 Xcode 7 项目构建开发分支

“错误的解释器:不允许操作” El Capitan 上的错误

OS X 10.11 El Capitan 上的蓝牙低功耗延迟/延迟