Vagrant 快速入门

发布于: 2020 年 07 月 12 日
Vagrant 快速入门

使用 Vagrant 可以管理本地虚拟机。


  • 操作系统:Microsoft Windows 10 企业版 LTSC

  • 版本:10.0.17763


Vagrant - 用于管理虚拟机生命周期的命令行实用程序。

choco install vagrant -y


  • 入门

mkdir vgtest
cd vgtest
# 启动一个 CentOS 7
vagrant init centos/7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`` for more information on using Vagrant.
vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
==> default: Importing a Hyper-V instance
default: Creating and registering the VM...
default: Successfully imported VM
default: Configuring the VM...
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
default: Timeout: 120 seconds
default: IP:
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address:
default: SSH username: vagrant
default: SSH auth method: private key
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
# ssh 连接
vagrant ssh

  • 自动配置 文件内容如下:

#!/usr/bin/env bash
yum update -y
yum install -y vim telnet

Vagrantfile 文件内容如下:

Vagrant.configure("2") do |config| = "centos/7"
config.vm.provision :shell, path: ""

# 校验配置
vagrant validate
Vagrantfile validated successfully.
# 重启并自动配置
vagrant reload --provision

  • 清理环境

# 查看状态
vagrant status
Current machine states:
default running (hyperv)
# 清理
vagrant destroy
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Stopping the machine...
==> default: Deleting the machine...




发布于: 2020 年 07 月 12 日 阅读数: 11



还未添加个人签名 2018.09.17 加入



Vagrant 快速入门