VirtualBox+Vagrant安装虚拟机


一般虚拟机安装我们可以通过VMWare来安装,但是通过VMWare安装,经常会碰到网络ip连接问题,为了减少额外的环境因素影响,可以通过VirtualBox结合Vagrant来安装虚拟机

一、下载Virtualbox和Vagrant

1、下载

Virtualbox下载地址:https://www.virtualbox.org/wiki/Downloads
Vagrant下载地址:https://developer.hashicorp.com/vagrant/downloads?product_intent=vagrant

本文下载的版本是Virtualbox7.0.12和Vagrant2.4.0

2、安装

1)都是傻瓜式安装,一直点确定即可
特殊选型,需要的话,可以更改下Virtualbox的安装位置
在这里插入图片描述
2)安装后重启电脑即可
在这里插入图片描述
3)验证是否安装成功
打开cmd命令窗口,输入vagrant 命令,弹出如下内容表示 vagrant 安装成功
在这里插入图片描述

二、安装虚拟机

1、新建目录D:\VirtualMachine

切换到该目录
在这里插入图片描述

2、执行vagrant init centos/7命令,就会在该目录下创建Vagrantfile文件

这里其实就是安装了镜像仓库,具体可以查看Vagrant镜像仓库:https://app.vagrantup.com/boxes/search
在这里插入图片描述

3、执行vagrant up命令

第一次执行的时候会去远程下载相关的镜像文件,并启动虚拟机
在这里插入图片描述
默认安装位置如下:
在这里插入图片描述

4、查看当前主机分给虚拟机的网关网段

这里的网段为56
在这里插入图片描述

5、找到D:\VirtualMachine下的Vagrantfile文件

去掉注释,配置ip=192.168.56.100
在这里插入图片描述

6、重启虚拟机

执行vagrant reload命令
在这里插入图片描述

7、测试ssh连接

执行vagrant ssh命令
在这里插入图片描述
登录xshell验证,输入用户名和密钥文件
在这里插入图片描述
在这里插入图片描述
切换到root用户:sudo su root
修改密码:sudo passwd root

[root@localhost vagrant]# sudo passwd root
Changing password for user root.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

三、 遇到的问题

1、VBoxManage.exe: error: VT-x is disabled in the BIOS for all CPU modes

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”设置为启用

2、vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic

网上的方案,找到初始化目录下的 private_key 文件,右键->属性->安全->高级勾上所有权限,我试了没用,大家可以试试;
最终的解决方案,找到D:\VirtualMachine下的Vagrantfile文件配置ip,重启即可

3、SSH用户身份证验证无法选择password

在这里插入图片描述
修改/etc/ssh/sshd_config的PasswordAuthentication,设置为yes
在这里插入图片描述
注:需要重启虚拟机!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员Forlan

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值