The most simple and popular Vagrant installation instructions for 2019, with a sample Vagrantfile

This chapter requires you to close Hyper-V. Please close it early to avoid other problems

By the way, there is a sample demo in this article. Please take a look at it at the bottom of the article. I hope you have installed Vagrant + VirtualBox when using the demo.

Vagrant is a Ruby-based tool for creating and deploying virtualized development environments. It uses Oracle’s open source VirtualBox virtualization system and uses Chef to create automated virtual environments.

The old ways, the new ones

VirtualBox installationDownload from official website

  • 10 to install Windows
  • MAC installation

The specific installation process is nothing more than the next step, there is nothing to say

Vagrant installation

  • The website links

Vagrant Windows download

  • 64 download: https://releases.hashicorp.co…
  • 32-bit download: https://releases.hashicorp.co…
  • Baidu Cloud 64-bit download:

    Link: https://pan.baidu.com/s/1oiztOlj0S_h6AfQ6WdUb_w extraction code: aoph

The vagrant MAC download

  • 64 download: https://releases.hashicorp.co…

Vagrant box to download

  • Download website: https://app.vagrantup.com/box…
  • Baidu cloud download: extraction code: AOPH

Vagrant Box added to local image

  • Download the image add
Vagrant Box Add {mirrorName} {mirrorAddress}

Such as:

Vagrant Box Add C:/box/centos7.box --name CentOS /7.5
  • Using remote mirroring
vagrant box add https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-amd64-vagrant.box --name ubuntu/bionic

Vagrant command description

Vagrant Destroy removes the virtual machine

vagrant destroy -f lincms 

Vagrant Up starts/creates the virtual machine

vagrant up  lincms 

Vagrant SSH for virtual machine interaction command line

vagrant ssh lincms 

Vagrant Reload restarts the virtual machine

vagrant reload lincms 

Vagrant up/ Reload –provision Recreate or re-execute scripts

vagrant up --provision
vagrant reload --provision

Vagrant status views the status of the virtual machines in the current directory

vagrant status

Such as:

G:\ Project λ Vagrant Status Current Machine States: lincms running (virtualbox) This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`.

Vagrant uses the sample

Let’s take Lin-CMS-TP as an example. Other directories are the same. Don’t pay too much attention to directories

  • Enter the LIN-CMS-TP household bucket level directory
Lambda ls Lin - CMS - tp
  • Initialize the Vagrantfile
vagrant init

Check the directory changes to see if a VagrantFile is generated

ls

lin-cms-tp  Vagrantfile
  • Add a Box image
vagrant box add https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cloud-images/bionic/current/bionic-server-cloudimg-amd64-vagrant.box --name ubuntu/bionic
  • Then replace the VagrantFile contents
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"

boxes = [
    {
        :name => "lincms",
        :eth1 => "10.10.1.10",
        :mem => "1024",
        :cpu => "1"
    }
]

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/bionic"

  boxes.each do |opts|
      config.vm.define opts[:name] do |config|
        config.vm.hostname = opts[:name]
        config.vm.provider "vmware_fusion" do |v|
          v.vmx["memsize"] = opts[:mem]
          v.vmx["numvcpus"] = opts[:cpu]
        end

        config.vm.provider "virtualbox" do |v|
          v.customize ["modifyvm", :id, "--memory", opts[:mem]]
          v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
        end

        config.vm.network :private_network, ip: opts[:eth1]
      end
  end

  config.vm.synced_folder "./lin-cms-tp", "/home/vagrant/lin-cms-tp"
  config.vm.provision "shell", privileged: true, path: "./setup.sh"

end
  • Create a new script file: setup.sh with the following contents:
# Timezone sudo /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo 'Asia/Shanghai' > /etc/timezone # Set the domestic source sudo/etc/apt/mv sources. List/etc/apt/sources list. Back && \ echo '# default comment the source image in order to improve the apt update speed, If necessary can uncomment \ n \ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse \ n \ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse \n \ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse \n \ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse \n \ deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse \n \ deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse \n \ deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse \n \ deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse \n \ deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse \n \ deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse' >> /etc/apt/sources.list # Libs sudo apt-get update && sudo apt-get install -y wget curl git vim gcc glibc-static telnet bridge-utils # install docker sudo curl -fsSL https://get.docker.com | sudo bash -s docker --mirror Aliyun sudo groupadd Docker sudo gpasswd-a vagrant docker sudo systemctl start docker rm-rf get-docker.sh # Configure the image accelerator sudo mkdir-p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://dt77flbr.mirror.aliyuncs.com"] } EOF sudo systemctl enable docker sudo systemctl daemon-reload sudo systemctl Compose # sudo curl-l: compose # sudo curl-l "Https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s) - $(uname -m)" - o Compose: /usr/local/bin/docker-compose: /usr/local/bin/docker-compose: /usr/local/bin/docker-compose: /usr/local/bin/docker-compose: Compose, docker-compose, docker-compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose, compose PIP install docker-compose # Print IP address information IP A
  • The final step is to create and start the virtual appliance

create

vagrant up lincms

Check the status

vagrant status

Enter the

vagrant ssh lincms

If you make any mistakes in the above process, please go to the search engine to search for solutions, or submit comments and comments

Error collection document【 I 】 something