38
Vagrant + Chef + MongoDB Nathen Harvey Web Opera9ons, CustomInk [email protected]

Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ [email protected]

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Vagrant  +  Chef  +  MongoDB  

Nathen  Harvey  Web  Opera9ons,  CustomInk  

[email protected]  

Page 2: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Problem  

!  Need  to  automate  MongoDB  server  builds  !  Mul9ple  mongo  instances  running  on  one  host  

!  Each  mongo  has  unique  configura9on  seJngs  

Page 3: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Developing  a  Solu9on  

!  Build  out  VM  using  !  Vagrant  !  Chef  

Page 4: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Vagrant  

Page 5: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Vagrant  

!   Tool  for  building  and  distribu9ng  virtualized  development  environments  

!  Uses  Oracle’s  VirtualBox  

Page 6: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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  

Page 7: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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!

Page 8: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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  

Page 9: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Chef  

!  Chef  is  an  open  source  systems  integra9on  framework  built  to  bring  the  benefits  of  configura9on  management  to  your  en9re  infrastructure.  

Page 10: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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  

Page 11: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Vagrant  +  Chef  

!  Vagrant  supports  provisioning  a  VMs  with:  !  Chef  Solo  !  Chef  Server  !  Puppet  

Page 12: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

MongoDB  

!  Scalable,  high-­‐performance,  open  source,  document-­‐oriented  database  

!  hXp://www.mongodb.org  

!  Replica9on  via  Replica  Sets  

Page 13: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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  

Page 14: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Code  walkthrough  

!  Next,  we’ll  walk  through  the  installa9on  and  configura9on  process  

!  15  minutes  to  solu9on  !  With  VirutalBox  already  installed  and  a  fast  network  

Page 15: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Install  Vagrant  

Page 16: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Add  and  Ini9alize  the  box  

Page 17: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Add  and  Ini9alize  the  Box  

!  We’re  using  lucid64  box  !  Others  are  available  !  Create  your  own  

Page 18: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Vagran`ile  

Page 19: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

On  to  Chef  

!  The  base  VM  is  ready  to  be  launched  !  Next  we’ll  move  on  to  provisioning  MongoDB  with  Chef  

Page 20: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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  

Page 21: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Chef  Role  !  Roles  allow  you  to  group  recipes  and  aXributes  

Page 22: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Logger  MongoDB  !  Recipe  –  fundamental  configura9on  unit  in  Chef  

Page 23: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Catalog  MongoDB  

Page 24: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Ready  to  launch  

!  Chef  configura9on  is  complete  !  We’re  now  ready  to  launch  the  VM  

!  First,  we’ll  need  to  revisit  the  Vagran`ile  

Page 25: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Updated  Vagran`ile  

Page 26: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Build  and  Provision  the  VM  

Page 27: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Verify  MongoDB  

Page 28: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Connect  to  MongoDB  

Page 29: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Solu9on  

!  Use  Vagrant  +  Chef  to  build  and  provision  a  local  VM.  

Page 30: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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!

Page 31: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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:  

Page 32: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Vagrant  –  Mul9ple  VMs  

!  Mul9-­‐VM  Environments  

Page 33: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Other  Vagrant  Op9ons  

!  Host-­‐only  Networking  !  allows  mul9ple  VMs  to  communicate  

!  NFS  Shared  Folders  !  much  faster  than  VirtualBox  shared  folders  

Page 34: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

DC  MongoDB  User  Group  

!  Want  to  learn  more  about  MongoDB  !  Next  Wednesday  –  January  19  at  6:30PM  

!  CustomInk  office  in  McLean  

!  Please  join  us!  

Page 35: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

Thank  You!  

!  What  ques9ons  do  you  have?  

Nathen  Harvey  

Web  Opera9ons,  CustomInk  

[email protected]  

TwiXer:    @nathenharvey  

Page 36: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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  

Page 37: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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!

Page 38: Vagrant + Chef + MongoDB · Vagrant+Chef’+ MongoDB’ Nathen’Harvey’ Web’Operaons,’ CustomInk’ nharvey@customink.com’

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