Vagrant+VirtualBox creates a new virtual machine

1. Download

vagrant download address
PS: After downloading VirtualBox, Windows needs to enter Bios to enable virtualization

2. Installation inspection

#输入命令查看版本,返回版本则说明安装成功
vagrant -v 

3. Install centos7

3.1 Create a folder

Find a place to create a folder to store centos7 and enter it (the directory path cannot have Chinese characters)

3.2 Start the installation

  • Step 1 Init
    opens cmd in the created directory and runs it vagrant init centos/7(note which directory this command is executed in, where its Vagrantfile is generated).
    At this time, one will be generated in this directory Vagrantfile文件, and some parameters can be modified in the Vagrantfile file, such as : virtual machine name, memory size, cpu, etc.; attach a general Vagrantfile file, commonly used as follows:
#指定ip
config.vm.network "private_network", ip: "192.168.33.10"
#登录账号密码
config.ssh.username = 'vagrant'
config.ssh.password = 'vagrant'

init

  • Step 2 Download virtualbox.box
    Link: https://pan.baidu.com/s/1i2_J1xD35SsiYOVsEDE0xw
    Extraction code: yyds
  • Step 3 add image
    run command
#vagrant box add 名称 第3步下载的virtualbox.box文件目录(如:D:\virtualbox.box),如下:
vagrant box add centos/7 D:\virtualbox.box 
  • Step 4 Start the virtual machine
vagrant up
  • Step 5 Connect to the virtual machine
vagrant ssh

At this point, centos7 is installed successfully. The following are the configurations of common commands and responses

4. Vagrant common commands

$vagrant ssh    		#进入刚才创建的centos7中

$vagrant box list 		#查看box列表

$vagrant status  		#查看centos7的状态

$vagrant halt   	 	#停止/关闭centos7

$vagrant destroy		#删除centos7

$vagrant status   		#查看当前vagrant创建的虚拟机

$vagrant halt   		#优雅关闭

$vagrant up   			#正常启动

#Vagrantfile中也可以写脚本命令,使得centos7更加丰富,但是要注意,修改了Vagrantfile,要想使正常运行的centos7生效,必须使用vagrant reload

Guess you like

Origin blog.csdn.net/weixin_44485316/article/details/131316819