下载添加box镜像
vagrant box add base 远端的box地址或者本地的box文件名
建立box镜像关联
vagrant box add centos72 vagrant-centos-7.2.box
输出结果如下
f:\vagrant\centos7.2>vagrant box add centos72 vagrant-centos-7.2.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'centos72' (v0) for provider: box: Unpacking necessary files from: file://f:/vagrant/centos7.2/vagrant-centos-7.2.box box: The box you're attempting to add already exists. Remove it before adding it again or add it with the `--force` flag. Name: centos72 Provider: virtualbox Version: 0
初始化
vagrant init centos72
输出结果如下
f:\vagrant\centos7.2>vagrant init centos72 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 `vagrantup.com` for more information on using Vagrant.
按需求配置Vagrantfile (生成3台虚拟机)
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.define "vgrant01" do |vb| config.vm.provider "virtualbox" do |v| v.memory = 1024 v.cpus = 1 end vb.vm.host_name = "vagrant01" vb.vm.network :public_network, ip: "10.0.0.15" vb.vm.box = "centos72" end config.vm.define "vgrant02" do |vb| config.vm.provider "virtualbox" do |v| v.memory = 1024 v.cpus = 1 end vb.vm.host_name = "vagrant02" vb.vm.network :public_network, ip: "10.0.0.16" vb.vm.box = "centos72" end config.vm.define "vgrant03" do |vb| config.vm.provider "virtualbox" do |v| v.memory = 1024 v.cpus = 1 end vb.vm.host_name = "vagrant03" vb.vm.network :public_network, ip: "10.0.0.17" vb.vm.box = "centos72" end end
启动虚拟机
vagrant up
显示当前已经添加box列表
vagrant box list
删除相应box列表
vagrant box remove
停止当前正在运行的虚拟机并销毁所有创建的资源
vagrant destory
关闭虚拟机
vagrant halt
将当前运行的虚拟机环境打包
vagrant package
重启虚拟机,主要用于重新载入配置文件
vagrant reload
输出用于连接ssh的一些信息
vagrant ssh-config
挂起当前虚拟机
vagrant suspend
恢复被挂起状态
vagrant resume
获取当前虚拟机状态
vagrant status
来源:博客园
作者:大胡子哥dhzg
链接:https://www.cnblogs.com/dhzg/p/11439120.html