Skip to main content

Vagrant+VirtualBox

Vagrant+VirtualBox

Use vagran to quickly create a linux virtual machine

1. Download and install virtualbox7.0.14

virtualbox official website download address
virtualbox old version download address

2. Download the windows version of vagrant2.4.1

[vagrant official website download address](https://developer.hashicorp.com/vagrant/downloads "vagrant official website download address")

Create the vagrant directory D:\vagrant\centos7

Enter the terminal: D:\vagrant\centos7 and execute

1. vagrant init centos7 [ Initialization (generate configuration file Vagrantfile)]

2. Edit the Vagrantfile file [Set IP Port Mapping Directory Mapping], add the following content and save it

config.vm.network "private_network", ip: "192.168.33.10"

config.vm.network "forwarded_port", guest: 80, host: 8080

config.vm.synced_folder "D:/wwwroot", "/data"

3. Mount centos to VirtualBox

vagrant box add centos7 d:/CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box

4. Vagrant up

5.vagrant ssh into the system

    vi /etc/ssh/sshd_config

ModifyPasswordAuthentication yes

Restart service

    service sshd restart

Directory sharing
vagrant plugin install vagrant-vbguest --local

You can also use NFS

Execute: vagrant plugin install vagrant-winnfsd

Edit the Vagrantfile and add nfs: true

config.vm.synced_folder "D:/wwwroot", "/data", nfs: true

Execution: vagrant reload

After configuring the environment, don’t forget to generate your own BOX package for future reuse.

vagrant package --base cent_default_1708278805575_96754 --output CentOS.box

--base name is the VirtualBox project name, not the vagrant box project name