Vagrant(1)Installation and Try Simple Command
Vagrant(1)Installation and Try Simple Command
1. Introduction and Installation
Vagrant is based on Ruby, calling VirtualBox and etc virtual system API to provide us a virtual system.
VirtualBox Installation
I already have the latest virtual box from oracle website.
Vagrant Installation
Download the right software for me, version 1.6.3 for MAC OS.
http://www.vagrantup.com/downloads.html
Check the Installation
>vagrant version
Installed Version: 1.6.3 Latest Version: 1.6.3 You're running an up-to-date version of Vagrant!
Create a home directory
>mkdir /Users/carl/vagrant
Download the box
We can find the box list from here http://www.vagrantbox.es/
Add the box
>vagrant box add win7 http://vagrantboxes.devopslive.org/windows-7-enterprise-i386.box
win7 is the name of the box, the last URL is the box’s URL from box list. This URL can be a local box file.
or
>vagrant box add local ./local-dev.box
After the command, the box files will be place under this directory. /Users/carl/.vagrant.d/boxes
Init our system
>vagrant init
the default is init the base, if we did not use the default name base. We need to use
>vagrant init local
Start the Server
>vagrant up
SSH to that server
>vagrant ssh
Shutdown the Server
>vagrant halt
2. Vagrantfile Configuration
config.vm.box = “base” // the name of the box
# config.vm.provider "virtualbox" do |vb| # # Don't boot with headless mode # vb.gui = true # # # Use VBoxManage to customize the VM. For example to change memory: # vb.customize ["modifyvm", :id, "--memory", "1024"] # end
Configure the memory and GUI.
Network configuration
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine # using a specific IP. # config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public_network"
Share the directory
# config.vm.synced_folder "../data", "/vagrant_data"
3. Useful Command
vagrant box add URL or FILE
vagrant init
vagrant up
vagrant ssh
vagrant box list // list all the boxes we have
vagrant box remove //remove the box
vagrant destroy //destroy this VM
vagrant halt //turn off the power of that vm
vagrant package //package the current vm
Usually vagrant will use chef and puppet doing the provisioning.
>vagrant provision
vagrant reload //reload the vm
vagrant resume // resume the vm
vagrant status //check the current status
vagrant suspend // save the current state and stop the vm
4. Use Win7
Error Message
The guest operating system of the machine could not be detected!
Solution:
Change the configuration, give more memory, change the network to be public, enable the GUI.
config.vm.network "public_network"
config.vm.synced_folder "../data", "/vagrant_data"
config.vm.provider "virtualbox" do |vb| # Don't boot with headless mode vb.gui = true # Use VBoxManage to customize the VM. For example to change memory: vb.customize ["modifyvm", :id, "--memory", "2048" ] vb.customize ["modifyvm", :id, '--audio', 'coreaudio', '--audiocontroller', 'hda'] vb.customize ["modifyvm", :id, "--vram", "128"] vb.customize ["modifyvm", :id, "--accelerate3d", "on"] end
References:
https://github.com/astaxie/Go-in-Action/blob/master/ebook/zh/01.1.md
https://github.com/astaxie/Go-in-Action/blob/master/ebook/zh/01.3.md
http://blog.segmentfault.com/fenbox/1190000000264347
http://eva0919.github.io/2013/04/26/%E7%94%A8vm%E6%89%8D%E6%98%AF%E5%A5%BD%E7%9A%84%E5%B7%A5%E7%A8%8B%E5%B8%AB-vagrant%E7%AF%87%E5%85%A5%E9%96%80%E7%89%88/
http://www.vagrantup.com/
provisoner
http://docs-v1.vagrantup.com/v1/docs/provisioners.html
vagrant sample
https://github.com/GeoffreyPlitt/vagrant-audio/blob/master/Vagrantfile
https://github.com/michfield/devbox-puppet/blob/master/vagrantfile