Vagrant

11
Vagrant Virtualbox provider guide

Transcript of Vagrant

Page 1: Vagrant

VagrantVirtualbox provider guide

Page 2: Vagrant

InstallPrerequisites

apt-get -y install virtualbox virtualbox-dkms vagrant

VM image

vagrant box add trusty64 https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box

Page 3: Vagrant

OperateStart image

vagrant init && vagrant up

Connect

vagrant ssh

Suspend or shutdown

vagrant suspend && vagrant halt

Page 4: Vagrant

ProvisioningCreate bootstrap.sh with all the configuration

Modify Vagrantfile

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

Provision

vagrant provision

Page 5: Vagrant

Bootstrap as a regular userBy default script is run as root, to run as a different user do the following.case $(id -u) in

0) # doing root tasks

sudo -u vagrant -i $0

;;

*) # doing user tasks

;;

esac

Page 6: Vagrant

Configure CPU and RAMModify Vagrantfile

config.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--memory", "1024"]

vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]

vb.customize ["modifyvm", :id, "--ioapic", "on"]

vb.customize ["modifyvm", :id, "--cpus", "4"]end

Page 7: Vagrant

Configure networkModify Vagrantfile

config.vm.network "public_network", bridge: "br-1", ip: "192.168.56.2"

config.vm.network "public_network", bridge: "br-2", ip: "192.168.57.2"

config.vm.network "public_network", bridge: "br-3", ip: "192.168.58.2"

Page 8: Vagrant

Copy files to VMVagrant.configure("2") do |config| # ... other configuration

config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"end

Page 9: Vagrant

GUIconfig.vm.provider "virtualbox" do |vb| vb.gui = trueend

Page 10: Vagrant

ReferencesVagrant virtualbox configuration

How to make Vagrant performance not suck

Page 11: Vagrant

My blogLearning Network Programming