Virtualbox下载地址:https://www.virtualbox.org/wiki/Downloads
Vagrant下载地址:https://developer.hashicorp.com/vagrant/downloads?product_intent=vagrant
本文下载的版本是Virtualbox7.0.12和Vagrant2.4.0
1)都是傻瓜式安装,一直点确定即可
特殊选型,需要的话,可以更改下Virtualbox的安装位置
2)安装后重启电脑即可
3)验证是否安装成功
打开cmd命令窗口,输入vagrant
命令,弹出如下内容表示 vagrant 安装成功
切换到该目录
vagrant init centos/7
命令,就会在该目录下创建Vagrantfile文件这里其实就是安装了镜像仓库,具体可以查看Vagrant镜像仓库:https://app.vagrantup.com/boxes/search
vagrant up
命令第一次执行的时候会去远程下载相关的镜像文件,并启动虚拟机
这里的网段为56
去掉注释,配置ip=192.168.56.100
执行vagrant reload
命令
执行vagrant ssh
命令
登录xshell验证,输入用户名和密钥文件
D:\VirtualMachine>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> 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: VirtualMachine_default_1698299496463_78949
==> 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...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["startvm", "a70cf490-d998-42ad-b3f0-930bca39ef07", "--type", "headless"]
Stderr: VBoxManage.exe: error: Not in a hypervisor partition (HVP=0) (VERR_NEM_NOT_AVAILABLE).
VBoxManage.exe: error: VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsole
原因:电脑没开启CPU虚拟化,如图
解决:重启电脑进入BIOS界面,进入“CPU Configuration”,找到“Intel Virtual Technology”设置为启用
网上的方案,找到初始化目录下的 private_key 文件,右键->属性->安全->高级勾上所有权限,我试了没用,大家可以试试;
最终的解决方案,找到D:\VirtualMachine下的Vagrantfile文件配置ip,重启即可