Build a multi-platform environment using Vagrant

Source: Internet
Author: User

Build a multi-platform environment using Vagrant
Title: Using Vagrant to build a multi-platform environment

[TOC]

Vagrant is a tool for creating and distributing virtualization development environments. It is written in ruby and does not contain Virtual Machine Management Software. Therefore, we need to install a virtual machine software with Vagrant. Vagrant supports VMware, Virtual Box, Hyper-V, and other Virtual machine software. I chose Virtual Box, free of charge, and cross-platform.

Why does Vagrant still need to be used with virtual machine software?
Because simple virtual machines cannot meet our needs, we hope that a new environment will help us solve everything when we start the system, including specific versions of the operating system, customized software environment installation, system settings (Time Zone, input method, etc.) and so on. Using Vagrant can help us easily build a system and automatically manage port ing/software package installation. At the same time, more importantly, Vagrant can also easily set synchronization folders, so that we can modify the program in the host machine and synchronize it to the client conveniently. During program debugging, this is a very good character. In addition, there are some other features, such as automated application deployment, which need to be explored by ourselves.

Install and install virtualbox

Omitted

Install vagrant

Download and install it from the official website.

Initialize and create a working directory

This working directory is used to store Virtual Machine configurations and local shared directory

$ mkdir vagrant$ cd vagrant
Search for basic templates

Vagrant users share a simplified system template (base box) based on various operating systems on the Internet, which can be found on the following two websites.

  • Https://atlas.hashicorp.com/boxes/search
  • Http://www.vagrantbox.es/
Initialize a virtual machine

For example, we selected the box-cutter/https://atlas.hashicorp.com/boxes/search on the Ubuntu1504-desktop, the box file will be stored in%userprofile%/.vagrant.d/The new virtual machine is stored in the Virtual Machine directory of Virtualbox.

$ vagrant init box-cutter/ubuntu1504-desktop

This command will create a Vagrantfile configuration file in the current directory to configure the virtual machine. You can directly load the configuration script to complete the pre-Installation Software and various configuration functions.

  • Define Virtual Machine name

    config.vm.provider "virtualbox" do |v|    v.name = "dev-ubuntu1504-desktop"end
  • Define the startup execution script

NOTE: If provision. sh is not an absolute path, it is relative to the directory where Vagrantfile is located.

config.vm.provision "shell", path: "provision.sh"

The following functions can be implemented:

  1. System update:sudo apt-get update
  2. Install necessary software:sudo apt-get install git 。。。
Start a VM
$ vagrant up

After the system is started, you can enter the graphical interface and log on to the system through SSH.

  • Default shared directory:. <-->/vargant
  • View SSH login information:$ vagrant ssh-config
  • Default SSH: vagrant: vagrant@127.0.0.1 2222
Custom System
  • Customized system as needed

Update the system, set the time zone, install the input method and software, etc.

Others

The packaging system creates a new template:$ vagrant packageTo generate a package. box in the current directory. You can save it to another location as a backup, or distribute it to others as a template.

Template usage steps:

  1. Add this template:$ vagrant box add dev ./package.box
  2. View:$ vagrant box list
  3. Create your own directory and start the VM:
$ mkdir dev; $ cd dev; $ vagrant init dev; $ vagrant up
Common commands:
$ Vagrant init # initialization $ vagrant up # Starting a virtual machine $ vagrant halt # disabling a virtual machine $ vagrant reload # restarting a virtual machine $ vagrant ssh # SSH to virtual machine $ vagrant status # viewing the virtual machine running status $ vag destroy # destroy the current Virtual Machine

You can use$ vagrant helpView

Advanced Applications
  • Multiple virtual machines

Vagrant supports defining multiple virtual machines in a Vagrantfile and is usually used to create a cluster. The following is an example of the Configuration:

Vagrant. configure ("2") do | config | # This configuration item will be inherited by the next two virtual machines # Note provision. if sh is not an absolute path, it is relative to the config. vm. provision "shell", path: "provision. sh "config. vm. define "web" do | web. vm. box = "apache" web. vm. network "private_network", ip: "192.168.50.3" end config. vm. define "db" do | db. vm. box = "mysql" db. vm. network "private_network", ip: "192.168.50.4" endend
Appendix
  • Change the location of the VirtualBox VM Image File

Open the VirtualBox program, click the manage/global settings menu item (Ctrl + G), and change the default virtual computer location (M) in the general column to the path under other disks.
Change the original pathC:\Users\user_name\.VirtualBox\VirtualBox VMsTo the new path.
Restart the VirtualBox program. In the virtual machine list, although the previously created virtual machines are still in use, they are all unavailable and deleted.
Double-click to open the vbox file in each folder in the new path and re-import the created virtual machine.
The VirtualBox virtual machine image file is the largest part of vagrant. The above method should significantly reduce the space occupied by vagrant on the system disk. However, if a large number of vagrant boxes are added, the occupied space is considerable. You can remove them from the System Disk using the following method.

  • Change the location of the vagrant configuration file

SetC:\Users\user_name\.vagrant.dMove to new location
Create an environment variable VAGRANT_HOME and specify the new path

How to Use vagrant to install a Hadoop cluster on a virtual machine

Efficient Puppet module Management in Vagrant

Use Vagrant and Fabric for Integration Testing

Build a development environment using Vagrant

Configure the Vagrant environment in Windows

Build a development environment using Vagrant

Build a virtual machine environment through Vagrant

This article permanently updates the link address:

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.