Vagrant与VirtualBox踩坑记录

一、Vargant是什么?

这里我就不赘述了,附上知乎大佬的详细解答:

超详细的 Vagrant 上手指南:
https://zhuanlan.zhihu.com/p/259833884

题主所使用的环境是:Window10专业版+ Vagrant 2.2.5 + VirtualBox 6.1

二、问题描述

1.在我成功安装好Vagrant和VirtualBox,下载好镜像文件在Vagrant up的时候发现需要开启Hyper-V

在Windos10上开启Hyper-V:
https://docs.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v

装好只后成功且可以Vagrant ssh 但是VirtualBox却不显示我安装的虚拟机为此我重装Vagrant和VirtualBox很多次没有完全解决。

查阅读资料后发现Hyper-V和VirtualBox都是Vagrant的供应商看来是我选择错误导致的

之后我卸载了Hyper-V,这时Vagrant up 和上次一样报错了提示要我重新安装Hyper-V;

PS E:\Program Files (x86)\.vagrant.d> vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
The Hyper-V cmdlets for PowerShell are not available! Vagrant
requires these to control Hyper-V. Please enable them in the
"Windows Features" control panel and try again.

最终定格在 **Bringing machine ‘default’ up with ‘hyperv’ provider…**明显看到我不是通过VirtualBox来启动的而是hyperv…

但是就此问题困惑了我一天,我开始怀疑是不是因为我安装的时候设置了默认Hyper-V?

2.官方文档

https://www.vagrantup.com/
在此强调有什么问题一定要看官方文档!!!

终于找到了解决办法-代码如下:

PS E:\Program Files (x86)\.vagrant.d> vagrant box list 
centos7 (virtualbox, 0) ##我们在使用 Box list的时候会在括号后面显示提供商

 vagrant up --provider=virtualbox ##那么我们就可以通过up时指定virtualBox即可

##新的报错
PS E:\Program Files (x86)\.vagrant.d> vagrant up --provider=virtualbox
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:

Vagrant has detected that you have a version of VirtualBox installed
that is not supported by this version of Vagrant. Please install one of
the supported versions listed below to use Vagrant:

4.0, 4.1, 4.2, 4.3, 5.0, 5.1, 5.2, 6.0

A Vagrant update may also be available that adds support for the version
you specified. Please check www.vagrantup.com/downloads.html to download
the latest version.

此报错一出就已经很好解决了
Vagrant 2.2.6 无法使用VirtualBox 6.1解决办法:
https://blog.csdn.net/daxiang52/article/details/103518589

成功:!!

PS E:\Program Files (x86)\.vagrant.d> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'centos/7' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'centos/7'
    default: URL: https://vagrantcloud.com/centos/7
==> default: Adding box 'centos/7' (v2004.01) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/2004.01/providers/virtualbox.box
    default: Download redirected to host: cloud.centos.org
    default:
    default: Calculating and comparing box checksum...
==> default: Successfully added box 'centos/7' (v2004.01) for 'virtualbox'!
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Setting the name of the VM: vagrantd_default_1625360020354_29009
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> 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
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Rsyncing folder: /cygdrive/e/Program Files (x86)/.vagrant.d/ => /vagrant

同时VirtualBox也识别到了:

然而在我高兴的时候

PS E:\Program Files (x86)\.vagrant.d> vagrant ssh
vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

我使用ssh链接不上

解决办法:https://blog.csdn.net/ai_0922/article/details/106366521

至此:链接成功!!

PS E:\Program Files (x86)\.vagrant.d> vagrant ssh
Last login: Sun Jul  4 01:16:21 2021 from 10.0.2.2
[vagrant@10 ~]$

总结

一点要先看官方文档(泪目~)

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值