SlideShare une entreprise Scribd logo
1  sur  51
Cooking with Chef
Server management made easy
Me?

Ken Robertson

Senior Software Engineer at Involver

Involver builds a social media marketing platform

Specialize in our platform’s reliability,
performance, and scalability
Our Chef Usage

10 separate environments

120+ servers

All managed with Chef

One Operations Engineer, Two Developers
What is Chef?

Server management and configuration in Ruby

Developed by OpsCode

Adopted by Engine Yard, 37signals, and more

Apache License
Chef isn’t alone

CFEngine: http://cfengine.com/

Puppet: http://www.puppetlabs.com/

http://en.wikipedia.org/wiki/
Comparison_of_open_source_configuration_man
agement_software
Why use Chef?

Repeatable system provisioning

Manual tweaks are not repeatable

Ease scaling

Avoid vendor lock-in
Chef is Repeatable


Continuous configuration management

Ensure system compliance

Recovery from failures
Chef Flavors

chef-solo

    Single instance

chef-server

    Cluster, centrally managed
Chef’s Toolkit


Cookbooks

  Recipes

Attributes
Recipes are
everywhere!

Open source - Engine Yard, 37signals, OpsCode

One offs for specific configurations

Approach with caution
Recipe ingredients:
Sub-recipes

Resources

Attributes

Definitions

Static resources

Templates
Resources
Resources - Examples


execute "some-descriptive-text" do
  command "uptime"
end
Resources - Examples


link "/usr/local/bin/foo" do
  to "/usr/src/foo-#{version}/bin/foo"
end
Resources - Examples


directory "/home/foo/apps/bar" do
  owner "foobar"
  group "foobar"
  recursive true
end
Resources - Examples


package "mongodb"
  version "1.2.3"
  action :install
end
Resources - Examples


package "mongodb"
  action :install, :upgrade
end
Resources - Examples


service "nginx" do
  supports :status => false, :start => true,
           :restart => true, :reload => true
  action [ :enable, :start ]
end
Resources - Examples


cookbook_file "/etc/profile" do
  owner "root"
  group "root"
  mode 644
  source "profile"
end
Resources - Examples


cookbook_file "/etc/profile" do
  owner "root"
  group "root"
  mode 644
  source "http://safesite.com/files/profile"
end
Resources - Examples

template "/etc/hosts" do
  owner "root"
  group "root"
  mode 644
  source "hosts.erb"
  variables(:one => 1, :two => 2)
end
Resources - Examples


cron "clear_tmp_files_older_than_a_day" do
  hour    0
  minute 0
  user    "root"
  command "do_something"
end
Resources - Conditions
execute "install-rubygems-for-jruby" do
  command %Q{
    curl http://production.cf.rubygems.org/rubygems/
rubygems-1.3.7.tgz -O &&
    tar xvzf rubygems-1.3.7.tgz &&
    pushd rubygems-1.3.7 &&
    jruby ./setup.rb &&
    popd &&
    rm rubygems-1.3.7.tgz &&
    rm -r rubygems-1.3.7
  }

  only_if { %x{jruby -S gem --version}.chomp !=
'1.3.7' }
end
Results/Expectations

execute 'install passenger and nginx' do
  command %Q{
       wget -N http://site/file.tar.gz &&
       tar -xvvf file.tar.gz &&
       passenger-install-nginx-module ...
  }
  creates '/data/nginx/sbin/nginx'
end
Triggers

template "/etc/nginx/apps/#{params[:name]}.conf" do
  source "#{params[:name]}.nginx.erb"
  owner node[:user]
  group node[:user]
  mode   0644
  variables(
    :stage => params[:stage],
    :name => params[:name]
  )

  notifies :reload, "service[nginx]", :delayed
end
Triggers
execute "mysql-create-database" do
  ...
  action :nothing
end

template "/tmp/mysql-#{params[:name]}.sql" do
  source "create-database.sql.erb"
  variables(:params => params)
  notifies :run,
    resources(:execute => "mysql-create-database"),
    :immediately
end
Attributes

Runtime configuration values

Define defaults

Pass in at runtime (as JSON)

Available through through the ‘node’ variable
Default Attributes
cookbooks/myrecipe/attributes/*.rb:

nginx_user "www-data"
nginx_port "80"

  => node[:nginx_user]
  => node[:nginx_port]

nginx { :user => 'www-data', :port => 80 }

  => node[:nginx][:user]
  => node[:nginx][:port]
Merging Attributes

default.mysql[:bindir] = '/usr/local/mysql',
default.mysql[:root] = '/data/mysql',
default.mysql[:uid] = 'mysql',
default.mysql[:gid] = 'mysql',
default.mysql[:group_name] = 'mysql',
default.mysql[:version] = '5.1.47'

node[:mysql][:version]
Runtime Attributes

{
    "nginx_user": "www-data",
    "nginx_port": 80,

    "nginx": {
      "user": "www-data",
      "port": 80
    }
}
Runtime Attributes

{
    "mysql": {
      "version": "5.1.47",
      "config": {
        "log_slave_updates": true,
        "auto_increment_increment": "2"
      }
    }
}
Definitions

Mini-recipes

Repeatable blocks or sub-functions

Definitions sub-directory of recipe

cookbooks/myrecipe/definitions
Definitions


link "/usr/local/bin/foo" do
  to "/usr/src/foo-#{version}/bin/foo"
end
Definitions

for db in node[:mysql][:databases] do
  mysql_database db[:name] do
    root_user node[:mysql][:root_user] || 'root'
    root_password node[:mysql][:root_password]
    dbuser db[:user] || db[:name]
    dbpassword db[:password]
  end
end
Definitions
define :mysql_database do
  execute "mysql-create-database" do
    ...
    action :nothing
  end

  template "/tmp/mysql-#{params[:name]}.sql" do
    source "create-database.sql.erb"
    variables(:params => params)
    notifies :run,
      "execute[mysql-create-database]",
      :immediately
  end
end
Definitions

define :nginx_site do
  include_recipe "nginx"

  template "/etc/nginx/apps/#{params[:name]}.conf" do
    source "#{params[:name]}.nginx.erb"
    owner node[:user]
    group node[:user]
    mode   0644
    variables(
      :stage => params[:stage],
      :name => params[:name]
    )

    notifies :reload, "service[nginx]", :delayed
  end
end
Recipe Gotchas



Idempotency
Idempotency

execute "install-jruby" do
  command %Q{
    curl http://urlto/#{version}/jruby-src-#{version}.tar.gz -O &&
    tar xvzf jruby-src-#{version}.tar.gz &&
    pushd jruby-#{version} &&
    ant &&
    popd &&
    mv jruby-#{version} /usr &&
    rm jruby-src-#{version}.tar.gz &&
    ln -snf /usr/jruby-#{version}/bin/jruby /usr/local/bin/jruby
  }

  creates "/usr/jruby-#{version}"
end
Idempotency - Fixed
execute "install-jruby" do
  command %Q{
    curl http://urlto/#{version}/jruby-src-#{version}.tar.gz -O &&
    tar xvzf jruby-src-#{version}.tar.gz &&
    pushd jruby-#{version} &&
    ant &&
    popd &&
    mv jruby-#{version} /usr &&
    rm jruby-src-#{version}.tar.gz
  }

  creates "/usr/jruby-#{version}/bin/jruby"
end

link "/usr/local/bin/jruby" do
  to "/usr/jruby-#{version}/bin/jruby"
end
Recipe Gotchas


Idempotency

Package sources
Recipe Gotchas


Idempotency

Package sources

Install vs upgrade
Install vs Upgrade

package “git-core” do
  action :install
end


package “git-core” do
  action :install, :upgrade
end
Recipe Gotchas

Idempotency

Package sources

Install vs upgrade

Attribute abuse
Recipe Gotchas

Idempotency

Package sources

Install vs upgrade

Attribute abuse

Cowboys and Homers
Homer

packages.each do |pkg|
  package pkg
end

execute "Nuke existing installs" do
  command "rm -rf /etc/tinydns /etc/dnscache"
end

...
Cowboys


One offs

Lack of testing

Manual, undocumented changes
DEMO
Much more!

Chef-server

Searching

Tagging

Libraries
Resources
OpsCode: http://www.opscode.com/

Chef Wiki: http://wiki.opscode.com/

37signals recipes:

http://github.com/37signals/37s_cookbooks

Engine Yard recipes:

http://github.com/engineyard/ey-cloud-recipes
Me!


Twitter: @krobertson

Blog: http://invalidlogic.com/

Email: ken@invalidlogic.com
Questions?

Contenu connexe

Tendances

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Software, Inc.
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
Chef
 

Tendances (20)

Chef training - Day2
Chef training - Day2Chef training - Day2
Chef training - Day2
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
 
Introduction to chef framework
Introduction to chef frameworkIntroduction to chef framework
Introduction to chef framework
 
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
 
Chef training - Day3
Chef training - Day3Chef training - Day3
Chef training - Day3
 
Chef training Day5
Chef training Day5Chef training Day5
Chef training Day5
 
Chef training Day4
Chef training Day4Chef training Day4
Chef training Day4
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Opscode Webinar: Managing Your VMware Infrastructure with Chef
Opscode Webinar: Managing Your VMware Infrastructure with ChefOpscode Webinar: Managing Your VMware Infrastructure with Chef
Opscode Webinar: Managing Your VMware Infrastructure with Chef
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
 
Chef: Smart infrastructure automation
Chef: Smart infrastructure automationChef: Smart infrastructure automation
Chef: Smart infrastructure automation
 
Chef
ChefChef
Chef
 
Introduction to chef
Introduction to chefIntroduction to chef
Introduction to chef
 
Node object and roles - Fundamentals Webinar Series Part 3
Node object and roles - Fundamentals Webinar Series Part 3Node object and roles - Fundamentals Webinar Series Part 3
Node object and roles - Fundamentals Webinar Series Part 3
 
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
 
Common configuration with Data Bags - Fundamentals Webinar Series Part 4
Common configuration with Data Bags - Fundamentals Webinar Series Part 4Common configuration with Data Bags - Fundamentals Webinar Series Part 4
Common configuration with Data Bags - Fundamentals Webinar Series Part 4
 
Chef in a nutshell
Chef in a nutshellChef in a nutshell
Chef in a nutshell
 
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
 
Compliance as Code
Compliance as CodeCompliance as Code
Compliance as Code
 

En vedette (7)

Mobile app-food-ordering-by-app nrg
Mobile app-food-ordering-by-app nrgMobile app-food-ordering-by-app nrg
Mobile app-food-ordering-by-app nrg
 
Foodprint UX Report
Foodprint UX ReportFoodprint UX Report
Foodprint UX Report
 
Online Food Ordering Mobile APP
Online Food Ordering Mobile APPOnline Food Ordering Mobile APP
Online Food Ordering Mobile APP
 
Module 4 presentation
Module 4 presentationModule 4 presentation
Module 4 presentation
 
Foodie- mobile food app
Foodie- mobile food appFoodie- mobile food app
Foodie- mobile food app
 
Tracxn - FoodTech Startup Landscape
Tracxn - FoodTech Startup LandscapeTracxn - FoodTech Startup Landscape
Tracxn - FoodTech Startup Landscape
 
Business model Canvas
Business model CanvasBusiness model Canvas
Business model Canvas
 

Similaire à Cooking with Chef

Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Carlos Sanchez
 
NLIT 2011: Chef & Capistrano
NLIT 2011: Chef & CapistranoNLIT 2011: Chef & Capistrano
NLIT 2011: Chef & Capistrano
nickblah
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 

Similaire à Cooking with Chef (20)

infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 
Chef or how to make computers do the work for us
Chef or how to make computers do the work for usChef or how to make computers do the work for us
Chef or how to make computers do the work for us
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
NLIT 2011: Chef & Capistrano
NLIT 2011: Chef & CapistranoNLIT 2011: Chef & Capistrano
NLIT 2011: Chef & Capistrano
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Chef solo the beginning
Chef solo the beginning Chef solo the beginning
Chef solo the beginning
 
Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with Capistrano
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
 
Chef - industrialize and automate your infrastructure
Chef - industrialize and automate your infrastructureChef - industrialize and automate your infrastructure
Chef - industrialize and automate your infrastructure
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for Developers
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Puppet
PuppetPuppet
Puppet
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Cooking with Chef

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n