$30 off During Our Annual Pro Sale. View Details »

The Joy of Cooking: Deploying MongoDB with Chef #mongochicago

Nathen Harvey
November 13, 2012

The Joy of Cooking: Deploying MongoDB with Chef #mongochicago

A quick primer on Opscode Chef and an introduction to using it to deploy MongoDB.

Nathen Harvey

November 13, 2012
Tweet

More Decks by Nathen Harvey

Other Decks in Technology

Transcript

  1. The Joy of Cooking: Deploying MongoDB with Chef Nathen Harvey

    @nathenharvey #mongochicago
  2. Agenda • Overview of Chef • Building a project in

    Chef • Deploying MongoDB with Chef • Additional resources
  3. Overview of Chef What is this thing again?

  4. Applications http://www.flickr.com/photos/steffenz/337700069/ http://www.flickr.com/photos/kky/704056791/

  5. http://www.flickr.com/photos/sbh/462754460/ Infrastructure

  6. Collection of Resources • Nodes • Networking • Files •

    Directories • Symlinks • Mounts • Routes • Users • Groups • Tasks • Packages • Software • Services • Configurations • Stuff http://www.flickr.com/photos/stevekeys/3123167585/
  7. Acting in concert http://www.flickr.com/photos/glowjangles/4081048126/

  8. http://www.flickr.com/photos/28309157@N08/3743455858/ To provide a Service

  9. http://www.flickr.com/photos/16339684@N00/2681435235/ And it evolves

  10. Configuration Management http://www.flickr.com/photos/philliecasablanca/3354734116/

  11. Golden Images are not the answer • Gold is heavy

    • Hard to transport • Hard to mold • Easy to lose configuration detail http://www.flickr.com/photos/garysoup/2977173063/
  12. http://www.flickr.com/photos/francoforeshock/5716969942/ Configuration Desperation

  13. Chef Solves This Problem • But you already guessed that,

    didn’t you?
  14. Automation Happiness! • MongoDB makes developers happy • MongoDB makes

    operations happy • Chef makes developers & operations happy, too!
  15. • Generate configurations directly on nodes • Reduce management complexity

    • Version control the programs http://www.flickr.com/photos/ssoosay/5126146763/ Programs!
  16. Declarative Interface to Resources • Define policy • Say what,

    not how • Pull not Push http://www.flickr.com/photos/bixentro/2591838509/
  17. Chef is Infrastructure as Code http://www.flickr.com/photos/louisb/4555295187/ • Programmatically provision and

    configure • Treat like any other code base • Reconstruct business from code repository, data backup, and bare metal resources.
  18. Building a Project in Chef OK, so how do I

    build something with Chef?
  19. Building a Chef Project • First, come up with your

    policy / specification • Abstract the resources in your spec
  20. Resources

  21. Building a Chef Project • First, come up with your

    policy / specification • Abstract the resources in your spec • Write recipes
  22. Recipe

  23. Building a Chef Project • First, come up with your

    policy / specification • Abstract the resources in your spec • Write recipes • Package recipes in cookbooks
  24. Cookbooks

  25. Recipes and Cookbooks • Recipes are collections of Resources •

    Cookbooks contain recipes, templates, files, custom resources, etc • Code re-use and modularity http://www.flickr.com/photos/shutterhacks/4474421855/
  26. Building a Chef Project • First, come up with your

    policy / specification • Abstract the resources in your spec • Write recipes • Package recipes in cookbooks • Apply recipes to nodes
  27. Nodes • Representation of a host • runs the Chef

    client • has attributes • has a list of recipes to be applied
  28. Building a Chef Project • First, come up with your

    policy / specification • Abstract the resources in your spec • Write recipes • Package recipes in cookbooks • Apply recipes to nodes • Group things into roles
  29. Roles • mechanism for easily composing sets of functionality •

    have attributes and a list of recipes to be applied
  30. Roles

  31. Run Lists Server Server Server Server chef-server API chef-client recipe[mongodb]

    node mongodb default.rb
  32. Run Lists Server Server Server Server chef-server API chef-client “recipe[mongodb]”,

    “recipe[mongodb::replset]” node mongodb default.rb replset.rb
  33. Run Lists Server Server Server Server chef-server API chef-client “role[base]”,

    “role[mongodb-replset-member]” node ntp default.rb sudo default.rb mongodb default.rb replset.rb
  34. Server Server Server Server chef-server API chef-client “role[webserver]” node ntp

    client.rb openssh server.rb apache default.rb php default.rb Roles chef-client “role[database]” node ntp client.rb openssh server.rb mongodb server.rb
  35. Building a Chef Project • First, come up with your

    policy / specification • Abstract the resources in your spec • Write recipes • Package recipes in cookbooks • Apply recipes to nodes • Group things into roles
  36. Deploying MongoDB with Chef Let’s do this!

  37. Deploying MongoDB • Create Cookbook • Write our recipes •

    Upload Cookbook to Chef Server • Run chef-client on nodes
  38. knife • What is Knife? • Command line tool

  39. Create a Cookbook

  40. MongoDB Recipes • Install MongoDB • Configure MongoDB • Start

    MongoDB • Join the Replica Set
  41. Install MongoDB

  42. Node Attributes

  43. Node Attributes • How does chef client know what platform

    your running?
  44. "memory": { "swap": { "cached": "0kB", "total": "4128760kB", "free": "4128760kB"

    }, "total": "2055676kB", "free": "1646524kB", "buffers": "35032kB", "cached": "210276kB", "active": "125336kB", "inactive": "142884kB", "dirty": "8kB", "writeback": "0kB", "anon_pages": "22976kB", "mapped": "8416kB", "slab": "121512kB", "slab_reclaimable": "41148kB", "slab_unreclaim": "80364kB", "page_tables": "1784kB", "nfs_unstable": "0kB", "bounce": "0kB", "commit_limit": "5156596kB", "committed_as": "74980kB", "vmalloc_total": "34359738367kB", "vmalloc_used": "274512kB", "vmalloc_chunk": "34359449936kB" }, Ohai! "block_device": { "ram0": { "size": "32768", "removable": "0" }, "ram1": { "size": "32768", "removable": "0" }, "ram2": { "size": "32768", "removable": "0" }, "hostname": "server-1", "fqdn": "server-1.example.com", "domain": "example.com", "network": { "interfaces": { "eth0": { "type": "eth", "number": "0", "encapsulation": "Ethernet", "addresses": { "00:0C:29:43:26:C5": { "family": "lladdr" }, "192.168.177.138": { "family": "inet", "broadcast": "192.168.177.255", "netmask": "255.255.255.0" }, "fe80::20c:29ff:fe43:26c5": { "family": "inet6", "prefixlen": "64", "scope": "Link" } },
  45. Node Attributes

  46. Node Attributes

  47. Configure MongoDB

  48. Configure MongoDB

  49. Chef Template

  50. Restart when the configuration chages

  51. Join the Replica Set

  52. Upload Our Cookbook to the Chef Server

  53. Run Chef Client Server Server Server Server chef-server API chef-client

    “role[base]”, “role[mongodb-replset-member]” node ntp default.rb sudo default.rb mongodb default.rb replset.rb
  54. Running the Chef Client • Automatically • cron • daemon

  55. Running the Chef Client • Automatically • Using knife’s ssh

    command • knife ssh "roles:monogdb-replset-member" "sudo chef-client"
  56. Running the Chef Client • Automatically • Using knife’s ssh

    command • Or maybe you’re using Vagrant •vagrant provision
  57. Wait...What is Vagrant?

  58. Vagrantfile

  59. Additional Resources Where to go next

  60. Review • Programmatically provisioned and configured a MongoDB Replica Set

    • Treat like any other code base • Repeat as often as necessary • Use the same code on multiple providers
  61. But wait, there’s more! • Encrypted data bags • Environments

    • Lightweight Resources and Providers • Exception and Report Handlers
  62. Community Site

  63. MongoDB Cookbooks • http://community.opscode.com/ cookbooks/mongodb • https://github.com/miketheman/fullstack • The code

    in this deck • Thanks to Mike Fiedler & Dan Crosta
  64. Want More? • community.opscode.com • wiki.opscode.com • docs.opscode.com • #chef

    on irc.freenode.net
  65. Food Fight Show • The podcast where DevOps Chefs Do

    Battle • foodfightshow.org
  66. Get Involved Locally! • meetup.com/Chicago-Chef-User-Group

  67. Learn More - Tomorrow! • Use discount code ‘mongodb’ to

    save 50%! • opscode.eventbrite.com
  68. Find Me • @nathenharvey • http://nathenharvey.com • nharvey@opscode.com • Thank

    You! • What Questions Do You Have?