vagrant environment configuration

This article is published as: http://www.linuxidc.com/Linux/2014-07/104118.htm

1. Vagrant features:

Vagrant usesOracle’s VirtualBox to build configurable, lightweight, and portable virtual machines dynamically..

[ Vagrant uses Oracle VM VirtualBox to dynamically create and configure lightweight, reproducible, and portable virtual machine environments.

2. Vagrant download:

http://downloads.vagrantup.com/tags/v1.0.5

3. Vagrant installation:

3.1. Download and install Oracle VM VirtualBox: For example, in Windows environment, you need to install VirtualBox-4.2.0-80737-Win.exe

https://www.virtualbox.org/wiki/Downloads

3.2. Download and install the latest version of Vagrant:

http://downloads.vagrantup.com/

[Note] On Windows and Mac OS X, the vagrantcommand should be automatically added to the environment variable PATH. But on other operating systems, you must manually add /opt/vagrant/binit to the environment variablePATH。

How to use vagrant to install a Hadoop cluster in a virtual machine http://www.linuxidc.com/Linux/2013-04/82750.htm

Efficient Puppet Module Management in Vagrant http://www.linuxidc.com/Linux/2014-05/101873.htm

Using Vagrant and Fabric for integration testing http://www.linuxidc.com/Linux/2014-07/104113.htm

Use Vagrant to build a development environmenthttp ://www.linuxidc.com/Linux/2014-07/104116.htm

Configure Vagrant environment under Windowshttp : //www.linuxidc.com/Linux/2014-07/104115.htm

4. Vagrant command

After the Vagrant installation is complete, we can use the vagrant command from the command line to operate. The common commands of vagrant are as follows:

vagrant box add <name> <url>
vagrant box list
vagrant box remove <name>
vagrant box repackage <name>
vagrant init [box-name] [box-url]
vagrant up [vm-name] [--[no-]provision] [-h]
vagrant destroy [vm-name]
vagrant suspend [vm-name]
vagrant reload [vm-name]
vagrant resume [vm-name]
vagrant halt [vm-name]
vagrant status [vm-name]
vagrant package [vm-name] [--base name] [--output name.box][--include one,two,three] [--vagrantfile file]
vagrant provision [vm-name]
vagrant ssh [vm-name] [-c command] [-- extra ssh args]
vagrant ssh-config [vm-name] [--host name]

5. Vagrantfile

任何Vagrant工程下都有一个Vagrantfile, 就像makefile一样,Vagrantfile用来配置vagrant的行为所创建虚拟机的信息,下面是一个基本的Vagrantfile:

       Vagrant::Config.run do |config|
           # Setup the box
           config.vm.box = "my_box"
       end

6. Create the first Vagrant virtual environment and project:

(1) Create a project directory and execute the vagrant init command, which will generate the original Vagrantfile

$ mkdir vagrant_guide
$ cd vagrant_guide
$ vagrant init

(2) Add a Base Box:

Instead of creating a virtual machine from scratch, Vagrant imports a base image of the virtual machine and builds on this basis. These images are called Box.

Vagrant supports adding boxes from the local filesystem or HTTP URL

$vagrant box add basehttp://files.vagrantup.com/lucid32.box

$vagrant box add base D:\lucid32.box

(3) Configure the Project to use this Box: Modify the Vagrantfile as follows:

Vagrant::Config.run do |config|
config.vm.box = "base"
end

(4) Start the virtual machine

$vagrant up

(5) Stop the virtual machine

$vagrant destroy

(6) SSH configuration

Vagrant provides SSH connections to virtual machines with just one command:

$vagrant ssh

In a Windows environment, you can use PUTTY and configure the following information to connect to the virtual machine:

hostname: localhost

port: 2222

Connection Type: SSH

User Name: vagrant

Password: vagrant

(7) Access the Project just created.

Vagrant connects your application and virtual machine through the shared folder of VirtualBox. The default shared folder guard is /vagrant, so to view the project just created, just execute:

vagrant@lucid32:~$ ls /vagrant
index.html Vagrantfile

(8) Provisioning:

Usually Box only does the most basic settings, rather than setting up all the environment at once. Vagrant usually uses chef or Puppet for further environment setup. 

For more details, please continue to read the wonderful content on the next page : http://www.linuxidc.com/Linux/2014-07/104118p2.htm

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326441147&siteId=291194637