Slide 1

Slide 1 text

The Joy of Cooking Deploying MongoDB with Chef Nathen Harvey, CustomInk.com https://github.com/nathenharvey/deploying- mongo-with-chef @nathenharvey @nathenharvey

Slide 2

Slide 2 text

Agenda Infrastructure as Code Introduction to Chef Building a project in Chef Deploying MongoDB with Chef Additional resources @nathenharvey

Slide 3

Slide 3 text

Evolution of Server Provisioning Just build it Keep notes in server.txt Migrate notes to wiki Custom shell scripts (in git) Systems integration framework @nathenharvey

Slide 4

Slide 4 text

Infrastructure as Code Enable the reconstruction of the business from nothing but a source code repository an application data backup and bare metal resources -Jesse Robins, Opscode @nathenharvey

Slide 5

Slide 5 text

Chef Declarative - What, not how Idempotent - Only take action if required Convergent - Takes care of itself @nathenharvey

Slide 6

Slide 6 text

Developer Happiness MongoDB makes developers happy MongoDB makes operations happy Chef makes developers & operations happy, too! @nathenharvey

Slide 7

Slide 7 text

Building a Chef Project First, come up with your policy / specification Abstract the resources in your spec @nathenharvey

Slide 8

Slide 8 text

Resources package "mongodb-10gen" do version node['mongodb']['version'] action :install end user node["mongodb"]["user"] do comment "MongoDB Server" gid node["mongodb"]["group"] supports :manage_home => true home "/home/#{node["mongodb"]["user"]}" action [ :create, :manage ] end More resources... @nathenharvey

Slide 9

Slide 9 text

Building a Chef Project First, come up with your policy / specification Abstract the resources in your spec Write recipes @nathenharvey

Slide 10

Slide 10 text

Recipes include_recipe 'mongodb::users' service node['mongodb']['service_name'] do supports [:start, :stop, :restart] end template node['mongodb']['configfile'] do source "mongodb.conf.erb" cookbook "mongodb" variables( :dbpath => node['mongodb']['dbpath'], :logpath => node['mongodb']['logpath'], :port => node['mongodb']['port'] ) end @nathenharvey

Slide 11

Slide 11 text

Building a Chef Project First, come up with your policy / specification Abstract the resources in your spec Write recipes Package recipes in cookbooks @nathenharvey

Slide 12

Slide 12 text

Cookbooks cookbooks/mongodb |-- README.md |-- attributes | `-- default.rb |-- metadata.rb |-- recipes | |-- 10gen_repo.rb | |-- configure.rb | |-- install.rb | |-- mms.rb | |-- replica_set.rb | `-- users.rb `-- templates `-- default `-- mongodb.conf.erb @nathenharvey

Slide 13

Slide 13 text

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 @nathenharvey

Slide 14

Slide 14 text

Nodes Representation of a host runs the Chef client has attributes has a list of recipes to be applied @nathenharvey

Slide 15

Slide 15 text

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 @nathenharvey

Slide 16

Slide 16 text

Roles mechanism for easily composing sets of functionality have attributes and a list of recipes to be applied @nathenharvey

Slide 17

Slide 17 text

Roles name "mongodc" description "Sample MongoDB Replica Set for Mo default_attributes( "mongodb" => { "replicaset" => "mongodc" } ) run_list( "recipe[mongodb::install]", "recipe[mongodb::configure]", "recipe[mongodb::replica_set]" ) @nathenharvey

Slide 18

Slide 18 text

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 @nathenharvey

Slide 19

Slide 19 text

What is Chef? Server - API, search, Web UI Client - chef-client Command line tool - knife @nathenharvey

Slide 20

Slide 20 text

knife $ knife help list bootstrap client configure cookbook cookbook-site data-bag environment exec index knife node role search shef ssh status tag @nathenharvey

Slide 21

Slide 21 text

What is Chef? Server - API, search, Web UI Client - chef-client Command line tool - knife Inspection library - ohai @nathenharvey

Slide 22

Slide 22 text

ohai Collects detailed, extensible information about a host. { "uptime": "13 days 06 hours 16 minutes 02 se "platform": "ubuntu", "os_version": "2.6.32-38-generic", "cpu": { "total": 3, "real": 0, "2": { "cache_size": "4096 KB", "model": "2", "family": "6", ... @nathenharvey

Slide 23

Slide 23 text

What is Chef? Server - API, search, Web UI Client - chef-client Command line tool - knife Inspection library - ohai REPL - shef @nathenharvey

Slide 24

Slide 24 text

What is Chef? Server - API, search, Web UI Client - chef-client Command line tool - knife Inspection library - ohai REPL - shef Community @nathenharvey

Slide 25

Slide 25 text

community.opscode.com @nathenharvey

Slide 26

Slide 26 text

Community Site Publish and share cookbooks @nathenharvey

Slide 27

Slide 27 text

Community Site Publish and share plugins for Chef, Knife, and Ohai @nathenharvey

Slide 28

Slide 28 text

chef-repo directory chef-repo |-- .chef | |-- knife.rb | |-- rubynation-validator.pem | `-- rubynation.pem |-- README.md |-- Rakefile |-- certificates |-- config | `-- rake.rb |-- cookbooks |-- data_bags |-- environments `-- roles @nathenharvey

Slide 29

Slide 29 text

Provision a server knife ec2 server create knife rackspace server create Vagrant @nathenharvey

Slide 30

Slide 30 text

Vagrantfile Vagrant::Config.run do |config| config.vm.define :mongo01 do |mongo01| mongo01.vm.provision :chef_client do |chef chef.add_role("mongodc") chef.node_name = "mongo01" end end config.vm.define :mongo02 do |mongo02| mongo02.vm.provision :chef_client do |chef chef.add_role("mongodc") chef.node_name = "mongo02" end end end @nathenharvey

Slide 31

Slide 31 text

Deploying MongoDB Install Configure Run Backup Monitor @nathenharvey

Slide 32

Slide 32 text

Create a Cookbook $ knife cookbook create mongodb ** Creating cookbook mongodb ** Creating README for cookbook: mongodb ** Creating metadata for cookbook: mongodb @nathenharvey

Slide 33

Slide 33 text

Write our recipes 10gen_repo.rb install.rb configure.rb users.rb replica_set.rb @nathenharvey

Slide 34

Slide 34 text

Get the code https://github.com/nathenharvey/deploying- mongo-with-chef @nathenharvey

Slide 35

Slide 35 text

10gen Repo Recipe include_recipe "apt" execute "apt-get update" do action :nothing end apt_repository "10gen" do keyserver "keyserver.ubuntu.com" key "7F0CEB10" uri "http://downloads-distro.mongodb.org/rep action :add notifies :run, "execute[apt-get update]", end @nathenharvey

Slide 36

Slide 36 text

Install Recipe include_recipe "mongodb::10gen_repo" package node['mongodb']['package_name'] do version node['mongodb']['version'] action :install end @nathenharvey

Slide 37

Slide 37 text

Where does package_name come from? Attributes defined in the cookbook: case platform when 'debian', 'ubuntu' default['mongodb']['package_name'] = 'mongod when 'centos', 'redhat', 'fedora', 'amazon' default['mongodb']['package_name'] = 'mongo- end @nathenharvey

Slide 38

Slide 38 text

Configure Recipe template node['mongodb']['configfile'] do variables( :dbpath => node['mongodb']['dbpath'], :logpath => node['mongodb']['logpath'], :port => node['mongodb']['port'], :journal => node['mongodb']['journal'], :replication_set => node['mongodb']['repli ) owner "root" group "root" mode "0644" notifies :restart, "service[#{node['mongodb' end @nathenharvey

Slide 39

Slide 39 text

Configure Recipe The configuration template dbpath = <%= @dbpath %> logpath = <%= @logpath %>/mongodb.log logappend = true port = <%= @port %> noauth = true <% if @journal %> journal=true <% else -%> nojournal=true <% end -%> @nathenharvey

Slide 40

Slide 40 text

Replication Recipe ruby_block "configure-replica-set" do block do require "rubygems" require "mongo" 10.times do |try| begin conn = Mongo::Connection.new( "localhost", node['mongodb']['port'], :slave_ok => true, :connect_timeout => rescue delay = 2 ** (try + 1) Chef::Log.info("Failed to connect to mongo sleep(delay) end end @nathenharvey

Slide 41

Slide 41 text

Upload cookbooks to Chef server $ knife cookbook upload -a @nathenharvey

Slide 42

Slide 42 text

Run chef-client Automatically knife ssh vagrant provision @nathenharvey

Slide 43

Slide 43 text

Review Servers provisioned and communicating with the Chef API MongoDB running in a replica set @nathenharvey

Slide 44

Slide 44 text

But wait, there's more! Encrypted databags Environments Lightweight Resources and Providers (LWRP) Exception and report handlers @nathenharvey

Slide 45

Slide 45 text

Deploying MongoDB Deployment Preparedness MongoDB on Amazon EC2 Operations Best Practices Production Notes @nathenharvey

Slide 46

Slide 46 text

MongoDB Cookbooks http://community.opscode.com/cookbooks/mong https://github.com/miketheman/fullstack @nathenharvey

Slide 47

Slide 47 text

Want more? http://community.opscode.com http://wiki.opscode.com Opscode Training Materials #chef on irc.freenode.net @nathenharvey

Slide 48

Slide 48 text

Want even more? http://foodfightshow.org Episode 5: Getting Started with Chef @nathenharvey

Slide 49

Slide 49 text

Shameless Plugs DevOpsDC Washington DC MongoDB Users Group @nathenharvey

Slide 50

Slide 50 text

Find Me @nathenharvey http://nathenharvey.com [email protected] @nathenharvey