Quickly build a Linux lab environment with vagrant

Source: Internet
Author: User

Brief introduction

This article mainly describes how to use the vagrant coordination to virtualbox quickly build an experimental environment.
virtualboxis an open source cross-platform virtual machine management software that features similar charges forvmware
vagrantis 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

      • Vagrant up

    • Pausing a virtual machine

      • Vagrant Suspend

    • Shutting down a virtual machine

      • Vagrant Halt

    • Deleting a virtual machine

      • Vagrant Destroy

    • Storage Snapshots

      • Vagrant Snapshot Save Lab1 Init

    • Recovering a Snapshot

      • Vagrant Snapshot Restore LAB1 init

Quickly build a Linux lab environment with vagrant

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.