"Develop Environments Made Easy" Vagrant by Hashicorop
A vagrant stereotypically lives in a box. The vagrant tool is built to manage all your "boxes" (VMs/servers). It is a brilliant project name.
Mitchell Hashimoto created Vagrant and can explain it best. Here is a great high level description.
- Your local testing environment will more closely match your shared environments
- No more "works for me" (because I'm running a different version of Java, PHP, etc)
- Quick tear down and setup (aka - provisioning). You can break it, destroy it and start over until you tweak it just right.
- With enough system resources you can replicate an entire distributed app (DB + app server + web server + load balancer)
- Tip: What's going on with my Vagrant box right now?
VMWare is an option with a Vagrant plugin that costs $79. It is highly recommended by Mitchell Hashimoto to use the VMWare option. But the basic steps above are free. Having a VMWare license is not the same as having the Vagrant VMWare plugin license; these are two separate purchases.
Everything to define your Vagrant configuration is done in a
Vagrantfile. This includes
- Which box to use? Ubuntu? CentOS? Windows? Which version?
- Networking configuration
- Syncing local folders to vm
- Basic provisioning: Inline Shell scripts
- Advanced provisioning: Chef || Puppet || Ansible || Salt
Vagrantfileto your project, any project, can be a great gift to the engineers you are supporting.
vagrant up # boots the VM(s) defined in the Vagrantfile vagrant ssh # connects to the VM via ssh. That's it. No IP needed. vagrant suspend # sleeps the server vagrant halt # shuts down the server vagrant destroy # wipes the server away to nothing
Review the example Vagrantfile which you checked out during the Git session.
We are going to complete the following three actions:
One - wreck the test box and recover
- Start up the single Vagrant box with a
vagrant upfrom the
vagrantdirectory in the ATB Git repo.
- Once the box is up log in with a
- Then delete the entire
/etcfolder of the VM.
exitthe VM and get back to your machine's command prompt.
vagrant haltthe server and bring it back
vagrant upagain. I'll wait.
- Now bring up the server the way it was before you destroyed
/etc. We do this with a
vagrant destroyand another
- We can again
vagrant sshin to the VM and see that
/etcis back and we did not really screw anything up.
Two - run one box as a webserver
vagrant upour single Vagrant box. (Which might already be running from the final step above)
- View the VMs default webpage http://localhost:8080.
- Connect via SSH and then stop the Apache server from running
sudo service apache2 stop.
- Reload the web page. Which should no longer load.
- Finish up with an
exitand the VM and
vagrant destroyof the VM.
Three - run three boxes as a small cluster of machines
- From your machine
cd multi-boxso we can work with a different
- Review this directory's Vagrantfile and note the differences (three machines with their own IP addresses).
- Start up the whole cluster of Vagrant VMs in the same manner as if it were just one machine by running
- Login to the box web1 (
vagrant ssh web1) and ping the box web3 on IP address
- View the default Apache page on web1, web2 and web3.
- Finish up with an
exitif necessary and then a
vagrant destroyto bring down all three machines.