Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf ·...

38
Provisioning MongoDB with Vagrant and Chef Nathen Harvey Web Opera=ons, CustomInk [email protected]

Transcript of Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf ·...

Page 1: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Provisioning  MongoDB  with  Vagrant  and  Chef  

Nathen  Harvey  Web  Opera=ons,  CustomInk  

[email protected]  

Page 2: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

CustomInk  

Page 3: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

My  Work  

!  Web  Opera=ons  at  CustomInk  !  Automate  

!  Support  produc=on  !  Develop  Rails  !  Monitor  

!  Deploy  !  20+  applica=ons  in  produc=on  !  Etc.  

Page 4: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Outside  of  work  

!  Coach  Soccer  for  my  kids  !  Enjoy  going  to  concerts  

Page 5: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

How  are  your  produc=on  servers  built?  

!  git  push  heroku  master  !  server.txt  !  Wiki  page  

!  “Gold”  VM  image  /  AMI  

!  Infrastructure  Automa=on  framework  !  Chef  !  Puppet  !  Cfengine  

Page 6: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Problem  

!  Need  to  automate  MongoDB  server  builds  !  Mul=ple  mongo  instances  running  on  one  host  

!  Each  mongo  has  unique  configura=on  seWngs  

Page 7: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Developing  a  Solu=on  

!  Build  out  VM  using  !  Vagrant  (for  development  purposes)  

!  Chef  

Page 8: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Vagrant  

!   Tool  for  building  and  distribu=ng  virtualized  development  environments  

!  Uses  Oracle’s  VirtualBox  !   h^p://vagrantup.com  

Page 9: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Get  Started  with  Vagrant  

!  Install  VirtualBox  !  Install  Vagrant  

!  gem install vagrant!!  Create  a  VirtualBox  image  

!   vagrant box add lucid64 http://files.vagrantup.com/lucid64.box!

!   h^ps://github.com/mitchellh/vagrant/wiki/Available-­‐Vagrant-­‐Boxes  

!   h^p://www.vagrantbox.es/  

Page 10: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Get  Started  with  Vagrant  

!  Ini=alize  the  instance  !  vagrant init!!  Creates  the  Vagranaile  –  configures  the  VM  

!  Start-­‐up  the  VM  !  vagrant up!

!  Login  !  vagrant ssh!

Page 11: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

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 12: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Chef  

!  Chef  is  an  open  source  systems  integra=on  framework  built  to  bring  the  benefits  of  configura=on  management  to  your  en=re  infrastructure.  

Page 13: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Chef  Cookbooks  

!  Cookbooks  -­‐  encapsulate  all  the  resources  you  need  to  automate  your  infrastructure  and  are  easily  sharable  with  other  Chef  users  !  h^p://cookbooks.opscode.com/  

!  h^ps://github.com/opscode/cookbooks  !  h^ps://github.com/37signals/37s_cookbooks  !  h^ps://github.com/customink/cusotmink-­‐cookbooks  

Page 14: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Vagrant  +  Chef  

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

Page 15: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

PuWng  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 16: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Code  walkthrough  

!  Next,  we’ll  walk  through  the  installa=on  and  configura=on  process  

!  15  minutes  to  solu=on  !  With  VirutalBox  already  installed  

Page 17: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Install  Vagrant  

Page 18: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Add  and  Ini=alize  the  Box  

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

Page 19: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Vagranaile  

Page 20: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

On  to  Chef  

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

Page 21: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Set-­‐up  Chef  Recipes  

!  Clone  the  CustomInk  Chef  repo  !  Create  some  addi=onal  directories  

!  mkdir  –p  cookbooks  roles    site-­‐cookbooks/mongodb/recipes  

!  Create  a  role  file  !  Create  a  recipe  for  each  MongoDB  instance  

Page 22: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Wait….what?  

!  Let’s  define  some  of  those  chef  terms  !  Recipe  

!  fundamental  configura=on  unit  in  Chef  !  Install  MongoDB,  Install  Apache,  etc.  

!  Cookbook  !  Fundamental  distribu=on  unit  and  include:  

!  A^ributes,  Recipes,  Files,  Templates,  and  more  

!  Role  !  Group  recipes  and  a^ributes  !  Applied  to  a  node  

Page 23: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Logger  MongoDB  !  Recipe  –  fundamental  configura=on  unit  in  Chef  

Page 24: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Catalog  MongoDB  

Page 25: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Chef  Role  !  Roles  allow  you  to  group  recipes  and  a^ributes  

Page 26: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Ready  to  launch  

!  Chef  configura=on  is  complete  !  We’re  now  ready  to  launch  the  VM  

!  First,  we’ll  need  to  revisit  the  Vagranaile  

Page 27: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Updated  Vagranaile  

Page 28: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Build  and  Provision  the  VM  

Page 29: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Verify  MongoDB  

Page 30: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Connect  to  MongoDB  

Page 31: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Solu=on  

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

Page 32: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

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  Vagranaile  !  vagrant up!!  vagrant ssh!

Page 33: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Developing  Chef  with  Vagrant    

!  Vagrant  is  a  great  way  to  test    your  Chef  recipes  !  vagrant provision!

!  re-­‐run  recipes  !  Point  your  Vagranaile  at  a  Chef  server:  

Page 34: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Chef  is  ready  to  cook  MongoDB  

!  Provision  test  and  produc=on  servers  !  Bootstrap  using  knife  

!  Knife  –  command  line  interface  to  chef  

!  Assign  the  Run  List  !  Assign  using  knife  or  the  web  UI  

!  Ini=alize  the  replica  set    !  Manual  step  at  the  moment  

!  Should  be  built  into  the  chef  recipes  

Page 35: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Cool,  I’m  not  using  MongoDB  

!  No  worries…I  really  want  you  to  consider  Vagrant  and  Chef  

!  How  to  you  get  a  new  developer  working  with  your  app?  !  Include  a  Vagranaile  in  your  repo  !  Provide  access  to  your  chef  repo  !  Checkout  and  vagrant  up  

!  Other  cool  vagrant  features…  

Page 36: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

DC  MongoDB  Meet  Ups  

!  Meet  third  Wednesday  of  every  month  !  Either  in  DC  or  at  CustomInk  in  Tysons  

!  Next  Meet  Up  is  next  Wednesday  !  April  20  –  6:30  PM  !  Library  of  Congress  

Page 37: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Upcoming  Shows  

!  Two  great  shows  during  Rails  Conf  !  Sunday  Funday  at  Pier  6  !  Bonnaroo  Buzz  at  Rams  Head  Live  

Page 38: Provisioning MongoDB)with) Vagrantand)Chef)files.meetup.com/347566/Bmore_On_Rails_Chef.pdf · 2011-04-15 · Provisioning MongoDB)with) Vagrantand)Chef) Nathen)Harvey) Web)Operaons,)

Thank  You!  

!  What  ques=ons  do  you  have?  

Nathen  Harvey  

Web  Opera=ons,  CustomInk  

[email protected]  

Twi^er:    @nathenharvey