文章目录

一、下载Virtualbox和Vagrant1、下载2、安装

二、安装虚拟机1、新建目录D:\VirtualMachine2、执行`vagrant init centos/7`命令,就会在该目录下创建Vagrantfile文件3、执行`vagrant up`命令4、查看当前主机分给虚拟机的网关网段5、找到D:\VirtualMachine下的Vagrantfile文件6、重启虚拟机7、测试ssh连接

三、 遇到的问题1、VBoxManage.exe: error: VT-x is disabled in the BIOS for all CPU modes2、vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic3、SSH用户身份证验证无法选择password

一般虚拟机安装我们可以通过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 注:需要重启虚拟机!

推荐阅读

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。