Brief introduction
This article mainly describes how to use the vagrant
coordination to virtualbox
quickly build an experimental environment.
virtualbox
is an open source cross-platform virtual machine management software that features similar charges forvmware
vagrant
is an open-source virtual machine configuration Orchestration software that allows you to quickly start managing virtual machines at the command line.
Related resources of Baidu cloud download link
Link: https://pan.baidu.com/s/1nt_b96SEOIIWl2gIrabPpg Password: 6c3d
Installation
1. Installationvirtualbox
Official Download virtualbox
package installation for the corresponding platform
2. Installationvagrant
Official download vagrant
of the corresponding platform package installation, due to the official website in foreign countries, may be slow to download.
3. Set up the virtualbox
virtual machine storage Directory
# VirtualBox Startup Virtual opportunity is stored in the user's home directory by default # Windows C disk may be too small to set up a specific directory storage virtual machine vboxmanage setproperty machinefolder d:\ Virtualboxvboxmanage List Systemproperties | grep machine
Building an experimental environment
1. Download the relevant box for import
# It can be slow because you need to pull box from abroad. Recommended to use my store in the Baidu Cloud box# import boxvagrant box add centos-7.4-base centos-7.4-base.boxvagrant box list
2. Start a stand-alone
Mkdir single && cd singlecat >vagrantfile<<eof# -*- mode: ruby -*-# vi: set ft=ruby :env["Lc_all"] = "En_US. UTF-8 "Vagrant.configure (" 2 ") do |config| config.vm.box = " Centos-7.4-base " config.vm.hostname = " would " config.ssh.insert_key = false # specify CPU and memory size config.vm.provider "VirtualBox" do |v| v.memory = 1024 v.cpus = 2 v.customize ["MODIFYVM", :id, "--name", "would"] end # Configure network config.vm.network "Private_network", ip: "11.11.11.111" # config.vm.network "Private_neTwork ", ip: " 192.168.22.10 " # Configure actions after startup config.vm.provision "Shell", inline: <<-shell hostname SHELLendEOF# Start Vagrant up
3. Start multi-host
Mkdir double && cd doublecat >vagrantfile<<eof# -*- mode: ruby -*-# vi: set ft=ruby :env["Lc_all"] = "En_US. UTF-8 "Vagrant.configure (" 2 ") do |config| config.vm.define " Web " do |web| web.vm.provider "VirtualBox" do |v| v.customize ["MODIFYVM", :id , "--name", "web", "--memory", "] end" web.vm.box = "centos-6.9" web.vm.hostname = "Web" web.vm.network "Private_network", ip: "11.11.11.11" end config.vm.define "DB" do |db| db.vm.provider " VirtualBox " do |v| v.customize ["MODIFYVM", :id, "--name", "db", "--memory", "Up"] end db.vm.box = " centos-6.9 " db.vm.hostname = " DB " db.vm.network "Private_network", ip: "11.11.11.22" endendEOF# Start Vagrant up
3. Start the cluster
Mkdir cluster && cd clustercat >vagrantfile<<eof# -*- mode : ruby -*-# vi: set ft=ruby :env["Lc_all"] = "En_US. UTF-8 "Vagrant.configure (" 2 ") do |config| (1..6) .each do |i| config.vm.define "Lab#{i}" do |node| node.vm.box = "CENTOS-7.4-DOCKER-17" node.ssh.insert_key = false node.vm.hostname = "Lab#{i}" node.vm.network " Private_network ", ip: " 11.11.11.11#{i} " node.vm.network "Private_network", ip: "11.11.12.11#{i}" node.vm.provision "Shell", &NBSP;&NBSP;&NBSP;&NBSP;&NBsp; inline: "Echo hello from node #{i}" node.vm.provider "VirtualBox" do |v| v.cpus = 4 v.customize ["MODIFYVM", :id, "--name", "Lab#{i}", "--memory", "2048 "] end end endendEOF# Start Vagrant up
4. Connecting a virtual machine
# In general, the virtual machine SSH connection user name vagrant# generally do not support password logon, you can log in after self-configuration support password Login # connection Sshkey stored in the user's home directory. VAGRANT.D Directory # C:\Users\will\. Vagrant.d\insecure_private_key
Common commands
The following command can be followed by the virtual machine name, only the specified virtual machine operation
Start a virtual machine
Pausing a virtual machine
Shutting down a virtual machine
Deleting a virtual machine
Storage Snapshots
Recovering a Snapshot
Quickly build a Linux lab environment with vagrant