Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

NLIT 2011: Chef & Capistrano

5,210 views

Published on

Published in: Technology
  • Be the first to comment

NLIT 2011: Chef & Capistrano

  1. 1. Automated Server Configuration and Web Site Deployments with Chef and Capistrano<br />NLIT Summit 2011<br />Nick Muerdter<br />06/15/2011<br />
  2. 2. 2<br />Photo from National Library NZ<br />http://www.flickr.com/photos/nationallibrarynz_commons/5015573731<br />
  3. 3. 3<br />Bringing Order<br />Photo from U.S. National Archives<br />http://www.flickr.com/photos/usnationalarchives/4011449131<br />
  4. 4. 4<br />Party like it’s 2011!<br />Image © Hanna-Barbera and Warner Bros. Entertainment Inc.<br />
  5. 5. 5<br />Photo by hey skinny<br />http://www.flickr.com/photos/heyskinny/1464641723<br />
  6. 6. 6<br /><ul><li>Web site deployment tool
  7. 7. Automates commands over SSH to multiple servers
  8. 8. Encapsulates deployment best practices
  9. 9. Ruby on Rails based, but easily does more</li></ul>What Is Capistrano?<br />
  10. 10. Getting Started With Capistrano<br />7<br />$sudo gem install capistranocapistrano-ext<br />$cd my_project<br />$capify .<br />[add] writing './Capfile'<br />[add] making directory './config'<br />[add] writing './config/deploy.rb'<br />[done] capified!<br />
  11. 11. Sample config/deploy.rb<br />8<br />require"capistrano/ext/multistage"<br />set :application, "my_project"<br /># Supported: `accurev`, `bzr`, `cvs`, `darcs`, `git`,<br /># `mercurial`, `perforce`, `subversion` or `none`<br />set :scm, :subversion<br />set :repository, "https://svn.nrel.gov/my_project/trunk"<br />set :deploy_to, "/var/www/my_project"<br />
  12. 12. Sample config/deploy/development.rb<br />9<br /># Set the servers for this stage.<br />role :app, "dev.nrel.gov"<br />role :web, "dev.nrel.gov"<br />role :db, "dev-db.nrel.gov"<br /># Reduce the number of copies kept for the<br /># development environment.<br />set :keep_releases, 2<br />
  13. 13. Sample config/deploy/staging.rb<br />10<br /># Set the servers for this stage.<br />role :app, "staging.nrel.gov"<br />role :web, "staging.nrel.gov"<br />role :db, "staging-db.nrel.gov"<br />
  14. 14. Sample config/deploy/production.rb<br />11<br /># Set the servers for this stage.<br />role :app, "nrel.gov"<br />role :web, "nrel.gov"<br />role :db, "db.nrel.gov"<br />
  15. 15. Running Capistrano<br />12<br />$ cap staging deploy<br /> * executing `development'<br /> triggering start callbacks for `deploy'<br /> * executing `multistage:ensure'<br /> * executing `deploy'<br /> triggering before callbacks for `deploy'<br /> * executing `deploy:try_setup'<br /> * executing `deploy:setup'<br /> triggering before callbacks for `deploy:setup'<br /> * executing `deploy:gem_bundler:setup'<br /> * executing "mkdir -p /srv/afdc/staging/common/my_project /srv/afdc/staging/common/my_project/releases /srv/afdc/staging/common/my_project/shared /srv/afdc/staging/common/my_project/shared/log"<br /> servers: ["staging.nrel.gov"]<br />Password: <br /> [staging.nrel.gov] executing command<br /> command finished in 795ms<br /> triggering after callbacks for `deploy:setup'<br /> * executing `deploy:shared_children_file_tasks:setup'<br /> * executing "mkdir -p /srv/afdc/staging/common/my_project/shared/public/linkcheck && chmodg+w /srv/afdc/staging/common/my_project/shared/public/linkcheck"<br /> servers: ["staging.nrel.gov"]<br /> [staging.nrel.gov] executing command<br /> command finished in 62ms<br /> ...<br />
  16. 16. <ul><li>Customize with before/after callbacks
  17. 17. What we’ve done:
  18. 18. Per-developer sandbox creation on development
  19. 19. Per-branch deployment on staging</li></ul>13<br />Where To Next?<br />Photo from NationaalArchief<br />http://www.flickr.com/photos/nationaalarchief/402623048<br />
  20. 20. 14<br />What Is Chef?<br /><ul><li>Automated server configuration tool
  21. 21. Programmatically define:
  22. 22. System requirements
  23. 23. System configuration
  24. 24. Replicate changes between environments.
  25. 25. Easily setup similar servers.</li></ul>Image © Comedy Central<br />
  26. 26. <ul><li>Cookbooks
  27. 27. Recipes
  28. 28. Attributes
  29. 29. Files
  30. 30. Templates
  31. 31. Roles
  32. 32. Nodes
  33. 33. Chef Server
  34. 34. Chef Clients</li></ul>15<br />Chef Terminology<br />Image © Iannucci'sPizzeria & Italian Restaurant<br />
  35. 35. package "apache2"do<br />case node[:platform]<br />when"centos", "redhat", "fedora", "suse"<br />package_name"httpd"<br />when"debian", "ubuntu"<br />package_name"apache2"<br />when"arch"<br />package_name"apache"<br />end<br /> action :install<br />end<br />service "apache2"<br />template "#{node[:apache][:dir]}/envvars"do<br /> source "envvars.erb"<br /> group "root"<br /> owner "root"<br /> mode 0644<br /> notifies :reload, "service[apache2]"<br />end<br /># ...<br />16<br />Sample Recipe<br />
  36. 36. name"ctts_base"<br />description "A base role for ctts.nrel.gov servers."<br />run_list([<br />"role[base]”,<br />"role[apache]",<br />"role[capistrano]",<br />"role[passenger_apache]",<br />"role[ruby]",<br />"role[tomcat]",<br />"recipe[apache2::mod_cgi]",<br />"recipe[apache2::mod_include]",<br />"recipe[apache2::mod_php5]",<br />"recipe[apache2::mod_ssl]",<br />"recipe[awstats]",<br />])<br />default_attributes({<br />:awstats=> {<br />:log_file=>"/srv/afdc/ctts/eere/current/log/access.log-%YYYY-0%MM-0%DD-0",<br />:domain=>"www.afdc.energy.gov",<br /> },<br />:php=> {<br />:module_oci8=> { :version=>"1.4.4" },<br /> },<br />})<br />17<br />Sample Role<br />
  37. 37. 18<br />
  38. 38. $sudo chef-client<br />Run List is [role[developer_development]]<br />Run List expands to [sudo, chef-client::config, etc::environment, opsview::client, iptables, logrotate, screen, ack, vim, nano, zsh, capistrano, subversion, nginx::source, passenger::nginx, rvm::install, rubygems::client, bundler, java, tomcat, db_config, haproxy, jammit, postgresql::client, supervisor, opsview::check_haproxy, opsview::check_nginx, opsview::check_supervisorctl, opsview::server, opsview::apache, chef-server, docs_site::nginx]<br />Starting Chef Run for devdev.nrel.gov<br />Loading cookbooks [ack, apache2, apt, bluepill, build-essential, bundler, capistrano, chef-client, chef-server, couchdb, daemontools, db_config, docs_site, erlang, etc, gecode, git, haproxy, iptables, jammit, java, logrotate, mysql, nano, nginx, openssl, opsview, passenger, perl, php, postgresql, python, rsync, rsyslog, rubygems, runit, rvm, screen, subversion, sudo, supervisor, tomcat, ucspi-tcp, vim, xml, yum, zlib, zsh]<br />Skipping opsview::client recipe because conflicting opsview::server recipe is enabled<br />Could not find previously defined grants.sql resource<br />Processing package[sudo] action upgrade (sudo::default line 20)<br />Processing template[/var/cache/chef/sudoers] action create (sudo::default line 40)<br />Processing template[/etc/sudoers] action create (sudo::default line 48)<br />Processing directory[/var/run/chef] action create (chef-client::config line 30)<br />Processing directory[/var/cache/chef] action create (chef-client::config line 30)<br />Processing directory[/var/lib/chef] action create (chef-client::config line 30)<br />Processing directory[/var/log/chef] action create (chef-client::config line 30)<br />Processing template[/etc/chef/client.rb] action create (chef-client::config line 38)<br />Processing ruby_block[reload_client_config] action nothing (chef-client::config line 47)<br />Processing template[/etc/environment] action create (etc::environment line 10)<br />Processing package[iptables] action install (iptables::default line 20)<br />Processing execute[rebuild-iptables] action nothing (iptables::default line 22)<br />Processing directory[/etc/iptables.d] action create (iptables::default line 27)<br />Processing cookbook_file[/usr/sbin/rebuild-iptables] action create (iptables::default line 31)<br />...<br />19<br />Running Chef<br />
  39. 39. 20<br />Slow Going?<br />Photo from State Library and Archives of Florida<br />http://www.flickr.com/photos/floridamemory/3266993225<br />
  40. 40. 21<br />Payoff?Totally, dude.<br />Photo by Calsidyrose<br />http://www.flickr.com/photos/calsidyrose/3198309214<br />
  41. 41. Capistrano:<br />https://github.com/capistrano/capistrano/wiki<br />Chef:<br />http://www.opscode.com/chef/<br />http://wiki.opscode.com/display/chef/Home<br />Chef Cookbooks:<br />http://community.opscode.com/cookbooks<br />https://github.com/opscode/cookbooks<br />22<br />Resources & Support<br />Photo from Musée McCord Museum<br />http://www.flickr.com/photos/museemccordmuseum/5348751435<br />
  42. 42. 23<br />http://slideshare.net/NickBlah<br />nick.muerdter@nrel.gov<br />Photo by Eleaf<br />http://www.flickr.com/photos/eleaf/2536358399<br />

×