Vagrant Quick StartCategory: Software test 2012-12-03 15:58 5064 people read comments (0) Collection report
Directory (?) [+] 1. Vagrant function: vagrant usesoracle ' s VirtualBox to build configurable, lightweight, and portable virtual M Achines dynamically.
"Vagrant uses Oracle VM VirtualBox to dynamically create and configure lightweight, reproducible, 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 a 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] The Windows and Mac OS x,vagrant command should be automatically added to the environment variable path. But under other operating systems, you must manually add/opt/vagrant/bin to the environment variable path. 4. Vagrant Command
After the vagrant installation is complete, we can operate from the command line via the Vagrant command. Vagrant commonly used commands 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
Any vagrant project has a vagrantfile, just like makefile, vagrantfile to configure the information of the virtual machine created by the behavior of vagrant, below is a basic vagrantfile:
Vagrant::config.run do |config|
# Setup The box
config.vm.box = "My_box"
End
6. Create the first vagrant virtual environment and engineering:
(1) Create the engineering directory and execute the Vagrant init command, which produces 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 the base image of a virtual machine and builds on it. These image is called box.
Vagrant support for adding boxes from local file system or HTTP URL
$vagrant box Add Basehttp://files.vagrantup.com/lucid32.box
$vagrant Box Add base D:\lucid32.box
(3) Configure Project to use this box: Modify Vagrantfile for the following:
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 an SSH connection to a virtual machine, and only one command is executed:
$vagrant ssh
in a Windows environment, you can use putty to configure the following information to connect to a virtual machine:
Hostname:localhost
port:2222
Connection Type:ssh
User name:vagrant
Password:vagrant
(7) Access to project that you just created.
Vagrant connects your application and virtual machines through VirtualBox shared folder, and the default shared folder is/vagrant, so you want to see the project you just created, just do the following:
vagrant@lucid32:~$ ls/vagrant
Index.html Vagrantfile
(8) Provisioning:
Usually the box only makes the most basic settings, rather than setting up all the environments once in place. Vagrant usually use chef or puppet to build a further environment.
Back to the index.html we just created, we need to install Apache. We use Puppet to complete this setup.
1. Create the folder manifests in the root directory of the project, and then create the puppet profile default.pp in the file's home, which reads as follows:
# Basic Puppet Apache manifest
class Apache {
exec {' apt-get update ':
command => '/usr/bin/apt-get update '
}
Package {"Apache2":
ensure => present,
}
Service {"apache2": Ensure =>
, running
=> package["Apache2"],
include Apache
2. Add support for puppet provisioning in Vagrantfile:
Vagrant::config.rundo|config|
config.vm.box= "Base"
# Enable the Puppet Provisioner
Config.vm.provision:puppet
End
(9) Running project
For the puppet configuration to take effect, you need to execute the vagrant reload command if you do not restart the virtual machine.
$ vagrant Reload
Because port forwarding is not configured, you cannot view the output of project from a local browser. Only SSH to the virtual machine to view the 127.0.0.1 output:
(10) Port mapping
Modify the Vagrantfile, add a mapping relationship between the local port and the virtual machine port, and then execute vagrant Reload, and then you can visit the local browser to ask: http://localhost:4567.
Vagrant :: Config.run do |config|
# Forward Guest port to host Port 4567
config.vm.forward_port-4567
end
7. Packing Packaging
1. Create a new file vagrantfile.pkg, which reads as follows:
Vagrant::config.run do |config|
# Forward Apache
config.vm.forward_port, 8080 end
2. Package Project
Vagrant Package--vagrantfile Vagrantfile.pkg
8. After the package is completed, the Package.box will be generated in the engineering root directory, and others will be able to use this box:
$ vagrant Box Add My_box/path/to/the/package.box
$ vagrant init my_box
$ vagrant up