Cooking with ChefServer management made easy
Me?Ken RobertsonSenior Software Engineer at InvolverInvolver builds a social media marketing platformSpecialize in our pla...
Our Chef Usage10 separate environments120+ serversAll managed with ChefOne Operations Engineer, Two Developers
What is Chef?Server management and configuration in RubyDeveloped by OpsCodeAdopted by Engine Yard, 37signals, and moreApa...
Chef isn’t aloneCFEngine: http://cfengine.com/Puppet: http://www.puppetlabs.com/http://en.wikipedia.org/wiki/Comparison_of...
Why use Chef?Repeatable system provisioningManual tweaks are not repeatableEase scalingAvoid vendor lock-in
Chef is RepeatableContinuous configuration managementEnsure system complianceRecovery from failures
Chef Flavorschef-solo    Single instancechef-server    Cluster, centrally managed
Chef’s ToolkitCookbooks  RecipesAttributes
Recipes areeverywhere!Open source - Engine Yard, 37signals, OpsCodeOne offs for specific configurationsApproach with caution
Recipe ingredients:Sub-recipesResourcesAttributesDefinitionsStatic resourcesTemplates
Resources
Resources - Examplesexecute "some-descriptive-text" do  command "uptime"end
Resources - Exampleslink "/usr/local/bin/foo" do  to "/usr/src/foo-#{version}/bin/foo"end
Resources - Examplesdirectory "/home/foo/apps/bar" do  owner "foobar"  group "foobar"  recursive trueend
Resources - Examplespackage "mongodb"  version "1.2.3"  action :installend
Resources - Examplespackage "mongodb"  action :install, :upgradeend
Resources - Examplesservice "nginx" do  supports :status => false, :start => true,           :restart => true, :reload => ...
Resources - Examplescookbook_file "/etc/profile" do  owner "root"  group "root"  mode 644  source "profile"end
Resources - Examplescookbook_file "/etc/profile" do  owner "root"  group "root"  mode 644  source "http://safesite.com/fil...
Resources - Examplestemplate "/etc/hosts" do  owner "root"  group "root"  mode 644  source "hosts.erb"  variables(:one => ...
Resources - Examplescron "clear_tmp_files_older_than_a_day" do  hour    0  minute 0  user    "root"  command "do_something...
Resources - Conditionsexecute "install-rubygems-for-jruby" do  command %Q{    curl http://production.cf.rubygems.org/rubyg...
Results/Expectationsexecute install passenger and nginx do  command %Q{       wget -N http://site/file.tar.gz &&       tar...
Triggerstemplate "/etc/nginx/apps/#{params[:name]}.conf" do  source "#{params[:name]}.nginx.erb"  owner node[:user]  group...
Triggersexecute "mysql-create-database" do  ...  action :nothingendtemplate "/tmp/mysql-#{params[:name]}.sql" do  source "...
AttributesRuntime configuration valuesDefine defaultsPass in at runtime (as JSON)Available through through the ‘node’ vari...
Default Attributescookbooks/myrecipe/attributes/*.rb:nginx_user "www-data"nginx_port "80"  => node[:nginx_user]  => node[:...
Merging Attributesdefault.mysql[:bindir] = /usr/local/mysql,default.mysql[:root] = /data/mysql,default.mysql[:uid] = mysql...
Runtime Attributes{    "nginx_user": "www-data",    "nginx_port": 80,    "nginx": {      "user": "www-data",      "port": ...
Runtime Attributes{    "mysql": {      "version": "5.1.47",      "config": {        "log_slave_updates": true,        "aut...
DefinitionsMini-recipesRepeatable blocks or sub-functionsDefinitions sub-directory of recipecookbooks/myrecipe/definitions
Definitionslink "/usr/local/bin/foo" do  to "/usr/src/foo-#{version}/bin/foo"end
Definitionsfor db in node[:mysql][:databases] do  mysql_database db[:name] do    root_user node[:mysql][:root_user] || roo...
Definitionsdefine :mysql_database do  execute "mysql-create-database" do    ...    action :nothing  end  template "/tmp/my...
Definitionsdefine :nginx_site do  include_recipe "nginx"  template "/etc/nginx/apps/#{params[:name]}.conf" do    source "#...
Recipe GotchasIdempotency
Idempotencyexecute "install-jruby" do  command %Q{    curl http://urlto/#{version}/jruby-src-#{version}.tar.gz -O &&    ta...
Idempotency - Fixedexecute "install-jruby" do  command %Q{    curl http://urlto/#{version}/jruby-src-#{version}.tar.gz -O ...
Recipe GotchasIdempotencyPackage sources
Recipe GotchasIdempotencyPackage sourcesInstall vs upgrade
Install vs Upgradepackage “git-core” do  action :installendpackage “git-core” do  action :install, :upgradeend
Recipe GotchasIdempotencyPackage sourcesInstall vs upgradeAttribute abuse
Recipe GotchasIdempotencyPackage sourcesInstall vs upgradeAttribute abuseCowboys and Homers
Homerpackages.each do |pkg|  package pkgendexecute "Nuke existing installs" do  command "rm -rf /etc/tinydns /etc/dnscache...
CowboysOne offsLack of testingManual, undocumented changes
DEMO
Much more!Chef-serverSearchingTaggingLibraries
ResourcesOpsCode: http://www.opscode.com/Chef Wiki: http://wiki.opscode.com/37signals recipes:http://github.com/37signals/...
Me!Twitter: @krobertsonBlog: http://invalidlogic.com/Email: ken@invalidlogic.com
Questions?
Upcoming SlideShare
Loading in...5
×

Cooking with Chef

6,683

Published on

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,683
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
27
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Cooking with Chef

    1. 1. Cooking with ChefServer management made easy
    2. 2. Me?Ken RobertsonSenior Software Engineer at InvolverInvolver builds a social media marketing platformSpecialize in our platform’s reliability,performance, and scalability
    3. 3. Our Chef Usage10 separate environments120+ serversAll managed with ChefOne Operations Engineer, Two Developers
    4. 4. What is Chef?Server management and configuration in RubyDeveloped by OpsCodeAdopted by Engine Yard, 37signals, and moreApache License
    5. 5. Chef isn’t aloneCFEngine: http://cfengine.com/Puppet: http://www.puppetlabs.com/http://en.wikipedia.org/wiki/Comparison_of_open_source_configuration_management_software
    6. 6. Why use Chef?Repeatable system provisioningManual tweaks are not repeatableEase scalingAvoid vendor lock-in
    7. 7. Chef is RepeatableContinuous configuration managementEnsure system complianceRecovery from failures
    8. 8. Chef Flavorschef-solo Single instancechef-server Cluster, centrally managed
    9. 9. Chef’s ToolkitCookbooks RecipesAttributes
    10. 10. Recipes areeverywhere!Open source - Engine Yard, 37signals, OpsCodeOne offs for specific configurationsApproach with caution
    11. 11. Recipe ingredients:Sub-recipesResourcesAttributesDefinitionsStatic resourcesTemplates
    12. 12. Resources
    13. 13. Resources - Examplesexecute "some-descriptive-text" do command "uptime"end
    14. 14. Resources - Exampleslink "/usr/local/bin/foo" do to "/usr/src/foo-#{version}/bin/foo"end
    15. 15. Resources - Examplesdirectory "/home/foo/apps/bar" do owner "foobar" group "foobar" recursive trueend
    16. 16. Resources - Examplespackage "mongodb" version "1.2.3" action :installend
    17. 17. Resources - Examplespackage "mongodb" action :install, :upgradeend
    18. 18. Resources - Examplesservice "nginx" do supports :status => false, :start => true, :restart => true, :reload => true action [ :enable, :start ]end
    19. 19. Resources - Examplescookbook_file "/etc/profile" do owner "root" group "root" mode 644 source "profile"end
    20. 20. Resources - Examplescookbook_file "/etc/profile" do owner "root" group "root" mode 644 source "http://safesite.com/files/profile"end
    21. 21. Resources - Examplestemplate "/etc/hosts" do owner "root" group "root" mode 644 source "hosts.erb" variables(:one => 1, :two => 2)end
    22. 22. Resources - Examplescron "clear_tmp_files_older_than_a_day" do hour 0 minute 0 user "root" command "do_something"end
    23. 23. Resources - Conditionsexecute "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
    24. 24. Results/Expectationsexecute 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/nginxend
    25. 25. Triggerstemplate "/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]", :delayedend
    26. 26. Triggersexecute "mysql-create-database" do ... action :nothingendtemplate "/tmp/mysql-#{params[:name]}.sql" do source "create-database.sql.erb" variables(:params => params) notifies :run, resources(:execute => "mysql-create-database"), :immediatelyend
    27. 27. AttributesRuntime configuration valuesDefine defaultsPass in at runtime (as JSON)Available through through the ‘node’ variable
    28. 28. Default Attributescookbooks/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]
    29. 29. Merging Attributesdefault.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.47node[:mysql][:version]
    30. 30. Runtime Attributes{ "nginx_user": "www-data", "nginx_port": 80, "nginx": { "user": "www-data", "port": 80 }}
    31. 31. Runtime Attributes{ "mysql": { "version": "5.1.47", "config": { "log_slave_updates": true, "auto_increment_increment": "2" } }}
    32. 32. DefinitionsMini-recipesRepeatable blocks or sub-functionsDefinitions sub-directory of recipecookbooks/myrecipe/definitions
    33. 33. Definitionslink "/usr/local/bin/foo" do to "/usr/src/foo-#{version}/bin/foo"end
    34. 34. Definitionsfor 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] endend
    35. 35. Definitionsdefine :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 endend
    36. 36. Definitionsdefine :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 endend
    37. 37. Recipe GotchasIdempotency
    38. 38. Idempotencyexecute "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
    39. 39. Idempotency - Fixedexecute "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"endlink "/usr/local/bin/jruby" do to "/usr/jruby-#{version}/bin/jruby"end
    40. 40. Recipe GotchasIdempotencyPackage sources
    41. 41. Recipe GotchasIdempotencyPackage sourcesInstall vs upgrade
    42. 42. Install vs Upgradepackage “git-core” do action :installendpackage “git-core” do action :install, :upgradeend
    43. 43. Recipe GotchasIdempotencyPackage sourcesInstall vs upgradeAttribute abuse
    44. 44. Recipe GotchasIdempotencyPackage sourcesInstall vs upgradeAttribute abuseCowboys and Homers
    45. 45. Homerpackages.each do |pkg| package pkgendexecute "Nuke existing installs" do command "rm -rf /etc/tinydns /etc/dnscache"end...
    46. 46. CowboysOne offsLack of testingManual, undocumented changes
    47. 47. DEMO
    48. 48. Much more!Chef-serverSearchingTaggingLibraries
    49. 49. ResourcesOpsCode: http://www.opscode.com/Chef Wiki: http://wiki.opscode.com/37signals recipes:http://github.com/37signals/37s_cookbooksEngine Yard recipes:http://github.com/engineyard/ey-cloud-recipes
    50. 50. Me!Twitter: @krobertsonBlog: http://invalidlogic.com/Email: ken@invalidlogic.com
    51. 51. Questions?
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×