Vagrant is a Ruby-based tool for automating build and process configuration of virtualized development environments. It is used to manage VirtualBox, VMware virtualization system, and Chef, Salt, Puppet and other environment configuration management software. It is a powerful tool to build a distributed development environment.

One. Install Vagrant

Preface:

1.1 download

The latest version of Vagrant

Wget HTTP: / / https://releases.hashicorp.com/vagrant/2.2.5/vagrant_2.2.5_x86_64.rpmCopy the code

1.2 installation

Yum localinstall vagrant_2. 2.5 _x86_64. RPMCopy the code

1.3 check

vagrant --version
Copy the code

Use Vagrant

preface

  • Ensure that VirtualBox is installed
  • Adds the current user to the vboxUsers user groupsudo usermod -G vboxusers $(whoami)

Official image repository: vagrantCloud.com Other image repositories: www.vagrantbox.es

2.1 Downloading the System Image file

Wget HTTP: / / https://github.com/CommanderK5/packer-centos-template/releases/download/0.7.2/vagrant-centos-7.2.boxCopy the code

2.2 Adding a System Mirror

# vagrant box add ${title} ${path}Vagrant box add centos-7.2 Vagrant -centos-7.2Copy the code

2.3 Initializing the System Mirroring Session

After you run the init command, the Vagrantfile file is automatically generated and you can configure VM attributes

# vagrant init {title}Vagrant init centos - 7.2Copy the code

2.4 Configuring the Vagrantfile file

Vagrant.configure("2") do |config|
  config.vm.box = "Centos - 7.2"
  config.vm.network "public_network", ip: "192.168.2.110"
end
Copy the code

Default remote account password vagrant/vagrant If root permission is required, use the sudo command

2.5 Starting the System Mirroring

vagrant up
Copy the code

A successful startup generates a hidden folder of.vagrant in the current directory

2.6 Logging In to a VM

vagrant ssh
Copy the code

To exit the virtual machine, press Ctrl + D or enter Exit.

2.7 Common Commands

## System image management
$ vagrant box add       # Add a system mirror
$ vagrant box list      View the added system image
$ vagrant box remove    Delete an installed system image


## Vagrant Basic Command
$ vagrant init          Vagrantfile is created when the vm is initialized
$ vagrant up            # Start the VM
$ vagrant halt          # Shut down the VM
$ vagrant reload        # Restart the VM
$ vagrant ssh           SSH to virtual machine
$ vagrant status        # Check the VM running status
$ vagrant destroy [-f]  Destroy (delete) all files, snapshots, and so on related to the current virtual machine, but do not delete the Vagrantfile
$ vagrant suspend       # Suspend the current VM -- Vm memory information is stored locally as a status file and can be used after recovery
$ vagrant resume        # Restore the current VIRTUAL machine -- corresponding to the previous suspension
$ vagrant package       Package the currently running virtual machine environment as a box file for distribution
Copy the code

2.8 Packing VMS

Vagrant package - base = centos - 7.2 - the output = the custom - centos - 7.2 boxCopy the code

The box file is actually an OVF package.

Open source virtualization format OVF file is an open source file specification, which describes an open source, safe, effective and extensible portable virtual packaging and software distribution format. It generally consists of several parts, namely OVF file, MF file, CERT file, VMDK file and ISO file.

If you use private_network in network mode, you need to clear the private_network Settings before packaging to avoid unnecessary errors:

rm -f /etc/udev/rule.d/70-persistent-net.rules
Copy the code

This bash instruction should be executed on the virtual machine, and the file location may vary from operating system to operating system.

Unknown Filesystem type ‘vboxsf’ solution

vagrant plugin install vagrant-vbguest
vagrant destroy && vagrant up
Copy the code

Reference: www.vultr.com/docs/how-to…

Custom box: github.com/jayknoxqu/p…