Your SlideShare is downloading. ×
  • Like
Cooking with Chef
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Cooking with Chef

  • 6,572 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
6,572
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
26
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    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

Transcript

  • 1. Cooking with ChefServer management made easy
  • 2. Me?Ken RobertsonSenior Software Engineer at InvolverInvolver builds a social media marketing platformSpecialize in our platform’s reliability,performance, and scalability
  • 3. Our Chef Usage10 separate environments120+ serversAll managed with ChefOne Operations Engineer, Two Developers
  • 4. What is Chef?Server management and configuration in RubyDeveloped by OpsCodeAdopted by Engine Yard, 37signals, and moreApache License
  • 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. Why use Chef?Repeatable system provisioningManual tweaks are not repeatableEase scalingAvoid vendor lock-in
  • 7. Chef is RepeatableContinuous configuration managementEnsure system complianceRecovery from failures
  • 8. Chef Flavorschef-solo Single instancechef-server Cluster, centrally managed
  • 9. Chef’s ToolkitCookbooks RecipesAttributes
  • 10. Recipes areeverywhere!Open source - Engine Yard, 37signals, OpsCodeOne offs for specific configurationsApproach with caution
  • 11. Recipe ingredients:Sub-recipesResourcesAttributesDefinitionsStatic resourcesTemplates
  • 12. Resources
  • 13. Resources - Examplesexecute "some-descriptive-text" do command "uptime"end
  • 14. Resources - Exampleslink "/usr/local/bin/foo" do to "/usr/src/foo-#{version}/bin/foo"end
  • 15. Resources - Examplesdirectory "/home/foo/apps/bar" do owner "foobar" group "foobar" recursive trueend
  • 16. Resources - Examplespackage "mongodb" version "1.2.3" action :installend
  • 17. Resources - Examplespackage "mongodb" action :install, :upgradeend
  • 18. Resources - Examplesservice "nginx" do supports :status => false, :start => true, :restart => true, :reload => true action [ :enable, :start ]end
  • 19. Resources - Examplescookbook_file "/etc/profile" do owner "root" group "root" mode 644 source "profile"end
  • 20. Resources - Examplescookbook_file "/etc/profile" do owner "root" group "root" mode 644 source "http://safesite.com/files/profile"end
  • 21. Resources - Examplestemplate "/etc/hosts" do owner "root" group "root" mode 644 source "hosts.erb" variables(:one => 1, :two => 2)end
  • 22. Resources - Examplescron "clear_tmp_files_older_than_a_day" do hour 0 minute 0 user "root" command "do_something"end
  • 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. 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. 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. 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. AttributesRuntime configuration valuesDefine defaultsPass in at runtime (as JSON)Available through through the ‘node’ variable
  • 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. 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. Runtime Attributes{ "nginx_user": "www-data", "nginx_port": 80, "nginx": { "user": "www-data", "port": 80 }}
  • 31. Runtime Attributes{ "mysql": { "version": "5.1.47", "config": { "log_slave_updates": true, "auto_increment_increment": "2" } }}
  • 32. DefinitionsMini-recipesRepeatable blocks or sub-functionsDefinitions sub-directory of recipecookbooks/myrecipe/definitions
  • 33. Definitionslink "/usr/local/bin/foo" do to "/usr/src/foo-#{version}/bin/foo"end
  • 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. 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. 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. Recipe GotchasIdempotency
  • 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. 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. Recipe GotchasIdempotencyPackage sources
  • 41. Recipe GotchasIdempotencyPackage sourcesInstall vs upgrade
  • 42. Install vs Upgradepackage “git-core” do action :installendpackage “git-core” do action :install, :upgradeend
  • 43. Recipe GotchasIdempotencyPackage sourcesInstall vs upgradeAttribute abuse
  • 44. Recipe GotchasIdempotencyPackage sourcesInstall vs upgradeAttribute abuseCowboys and Homers
  • 45. Homerpackages.each do |pkg| package pkgendexecute "Nuke existing installs" do command "rm -rf /etc/tinydns /etc/dnscache"end...
  • 46. CowboysOne offsLack of testingManual, undocumented changes
  • 47. DEMO
  • 48. Much more!Chef-serverSearchingTaggingLibraries
  • 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. Me!Twitter: @krobertsonBlog: http://invalidlogic.com/Email: ken@invalidlogic.com
  • 51. Questions?