在 Windows 10 的 VirtualBox + Vagrant 环境下,启动 CentOS Stream 8 虚拟机的步骤

前提(Paraphrase options in Chinese):

– 条件
– 先决条件
– 假设
– 入门事项
– 基础条件

以下是对本次步骤进行验证的环境。

    • Windows 10 Pro 20H2

 

    • VirtualBox 6.1.18

 

    Vagrant 2.2.15

操作步骤

启动虚拟机

    1. 安装 VirtualBox 和 Vagrant。

下载 – Oracle VM VirtualBox
下载 | Vagrant by HashiCorp

右击 Windows 开始按钮,点击命令提示符。

创建 vagrant 目录。

> mkdir vagrant

移动工作目录,创建用于 CentOS 的目录。

> cd vagrant
> mkdir centos

移动工作目录,生成 Vagrant 的配置文件。

> cd centos
> vagrant init

使用记事本打开配置文件,将 Box 从 base 更改为 centos/stream8。

> notepad Vagrantfile

Vagrantfile
— Vagrantfile.org 2021-04-02 20:40:20.328164000 +0900
+++ Vagrantfile 2021-04-02 20:41:36.510341300 +0900
@@ -12,7 +12,7 @@

# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
– config.vm.box = “base”
+ config.vm.box = “centos/stream8”

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs

启动虚拟机。如果 Box 下载速度较慢,请参考 Box 下载速度过慢的情况。

> vagrant up

登录, 登出, 关闭

如果提示符为 > ,请在命令提示符中执行操作;如果提示符为 $ ,请在已登录到CentOS的状态下执行操作。

    1. 登录虚拟机(通过SSH连接)。

 

    1. > vagrant ssh

从虚拟机注销。
$ exit

关机虚拟机。
$ sudo systemctl poweroff

确认虚拟机已关机。
> vagrant status

文献资料

如果Box的下载速度非常慢的话

多少好转的措施。

    1. 打开一个网络浏览器,访问CentOS Cloud镜像。

 

    1. 复制VirtualBox的Vagrant Box链接。

这次我选择CentOS-Stream-Vagrant-8-20210210.0.x86_64.vagrant-virtualbox.box。

右键单击Windows的开始按钮,点击命令提示符。

进入下载目录,下载Box。

> cd Downloads
> curl -LO https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-Vagrant-8-20210210.0.x86_64.vagrant-virtualbox.box

添加Box。

> vagrant box add centos/stream8 CentOS-Stream-Vagrant-8-20210210.0.x86_64.vagrant-virtualbox.box

如果想尝试其他虚拟机

在Vagrant Cloud上进行搜索。

    • Discover Vagrant Boxes – Vagrant Cloud

 

    • centos – Vagrant Cloud

 

    ubuntu – Vagrant Cloud

突破!