Problem
! Need to automate MongoDB server builds ! Mul9ple mongo instances running on one host
! Each mongo has unique configura9on seJngs
Developing a Solu9on
! Build out VM using ! Vagrant ! Chef
Vagrant
Vagrant
! Tool for building and distribu9ng virtualized development environments
! Uses Oracle’s VirtualBox
Get Started with Vagrant
! Install VirtualBox 3.2.x ! Latest VirtualBox release is not supported (yet) ! hXp://www.virtualbox.org/wiki/Download_Old_Builds_3_2 ! See vagrant 0.7.0 notes at the end of the presenta9on
! Install Vagrant ! gem install vagrant!
! Create a VirtualBox image ! vagrant box add lucid64 http://files.vagrantup.com/lucid64.box!
! hXps://github.com/mitchellh/vagrant/wiki/Available-‐Vagrant-‐Boxes
Get Started with Vagrant
! Ini9alize the instance ! vagrant init!! Creates the Vagran`ile – configures the VM
! Start-‐up the VM ! vagrant up!
! Login ! vagrant ssh!
Vagrant
! Six steps to get a VM running with Vagrant: ! Install VirtualBox ! gem install vagrant!! vagrant box add <box name> <box URL>!
! vagrant init <box name>!! vagrant up!! vagrant ssh!
! Next, configure the server with Chef
Chef
! Chef is an open source systems integra9on framework built to bring the benefits of configura9on management to your en9re infrastructure.
Chef Cookbooks
! Cookbooks -‐ encapsulate all the resources you need to automate your infrastructure and are easily sharable with other Chef users ! hXp://cookbooks.opscode.com/
! hXps://github.com/opscode/cookbooks ! hXps://github.com/37signals/37s_cookbooks ! hXps://github.com/customink/cookbooks
Vagrant + Chef
! Vagrant supports provisioning a VMs with: ! Chef Solo ! Chef Server ! Puppet
MongoDB
! Scalable, high-‐performance, open source, document-‐oriented database
! hXp://www.mongodb.org
! Replica9on via Replica Sets
PuJng it all together
! Use Vagrant to launch a VM ! Use Chef to provision MongoDB instances on the VM
! Connect to the MongoDB instances on the VM
Code walkthrough
! Next, we’ll walk through the installa9on and configura9on process
! 15 minutes to solu9on ! With VirutalBox already installed and a fast network
Install Vagrant
Add and Ini9alize the box
Add and Ini9alize the Box
! We’re using lucid64 box ! Others are available ! Create your own
Vagran`ile
On to Chef
! The base VM is ready to be launched ! Next we’ll move on to provisioning MongoDB with Chef
Set-‐up Chef Recipes
! Clone the CustomInk Chef repo ! Create some addi9onal directories
! mkdir –p cookbooks roles site-‐cookbooks/mongodb/recipes
! Create a role file ! Create a recipe for each MongoDB instance
Chef Role ! Roles allow you to group recipes and aXributes
Logger MongoDB ! Recipe – fundamental configura9on unit in Chef
Catalog MongoDB
Ready to launch
! Chef configura9on is complete ! We’re now ready to launch the VM
! First, we’ll need to revisit the Vagran`ile
Updated Vagran`ile
Build and Provision the VM
Verify MongoDB
Connect to MongoDB
Solu9on
! Use Vagrant + Chef to build and provision a local VM.
Quick Review
! Install VirtualBox ! gem install vagrant!! vagrant box add <box name> <box URL>!
! vagrant init <box name>!! Clone chef repo ! Add your own roles & recipes ! Update Vagran`ile ! vagrant up!! vagrant ssh!
Developing Chef with Vagrant
! Vagrant is a great way to test your Chef recipes ! vagrant provision!
! re-‐run recipes ! Point your Vagran`ile at a Chef server:
Vagrant – Mul9ple VMs
! Mul9-‐VM Environments
Other Vagrant Op9ons
! Host-‐only Networking ! allows mul9ple VMs to communicate
! NFS Shared Folders ! much faster than VirtualBox shared folders
DC MongoDB User Group
! Want to learn more about MongoDB ! Next Wednesday – January 19 at 6:30PM
! CustomInk office in McLean
! Please join us!
Thank You!
! What ques9ons do you have?
Nathen Harvey
Web Opera9ons, CustomInk
TwiXer: @nathenharvey
Vagrant 0.7.0
! While giving the presenta9on, Vagrant 0.7.0.beta2 was released ! Vagrant 0.7.0 final will likely be released in a few days
! VirtualBox 4 is required ! Provisioner syntax has changed and is backwards incompa9ble
! Updated base boxes are available
Vagrant 0.7.0 Provisioner Syntax
! Here’s the new syntax: config.vm.provisioner :chef_solo do |chef|! chef.cookbooks_path = 'customink-cookbooks', 'site-cookbooks' !
chef.roles_path = "roles" !
chef.add_recipe("mongodb::logger") ! chef.add_recipe("mongodb::catalog") ! chef.add_role("mongodb_vagrant_server") !end!
Vagrant 0.7.0 Base boxes
! Base boxes are currently available at the URLs below. The “_beta” will be removed once 0.7.0 final is released ! hXp://files.vagrantup.com/lucid32_beta.box
! hXp://files.vagrantup.com/lucid64_beta.box