• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Cooking up your dev environment with Chef
 

Cooking up your dev environment with Chef

on

  • 20,494 views

In this technical presentation we will cover the use of tools such as Capistrano, Puppet & Chef to script and automate the setup of server environments. We will begin by describing the problems ...

In this technical presentation we will cover the use of tools such as Capistrano, Puppet & Chef to script and automate the setup of server environments. We will begin by describing the problems associated with differing server environments during the development of software written in PHP, explaining how differing software stacks can lead to unexpected defects. Most notably introducing risk to our projects during deployment from development environments, staging and production servers.

Based on real world experiences we will describe how "chef" can be used to reduce the requirement for individual developers to maintain their development environment. We will describe a scenario where the required knowledge to run exact replicas of the production servers during development is reduced. We will describe a solution where the technical architecture of the server and software stack can be defined and deployed to VMs or to physical or cloud based production hardware all using a scripted approach.

Statistics

Views

Total Views
20,494
Views on SlideShare
20,355
Embed Views
139

Actions

Likes
18
Downloads
127
Comments
0

3 Embeds 139

http://www.scoop.it 130
https://twitter.com 8
http://www.slashdocs.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Cooking up your dev environment with Chef Cooking up your dev environment with Chef Presentation Transcript

    • COOKING UP YOUR ENVIRONMENT Scripted InfrastructureFriday, 20 May 2011
    • WHO AM I • Alistair Stead • http://joind.in/talk/view/3227 • Technical Team Lead @ Ibuildings UK • @alistairstead • Lead projects for a number of large European companies • Zend Certified EngineerFriday, 20 May 2011
    • DEVELOPMENT ENVIRONMENT This is were you work you take good care of it?Friday, 20 May 2011
    • YOUR SOFTWARE STACK Does it matter?Friday, 20 May 2011
    • BASE OS OPTIONSFriday, 20 May 2011
    • IS EVERYONE A SYSTEM ADMINISTRATOR Really?Friday, 20 May 2011
    • CAN YOU MAINTAIN THIS? Across the entire team?Friday, 20 May 2011
    • VIRTUALISATION Virtual Machines roll out the bumpsFriday, 20 May 2011
    • VIRTUAL MACHINES Distribution can be just as big a problem!Friday, 20 May 2011
    • EVERYONE IS STILL A SYSTEM ADMINISTRATOR “I’d rather be building the application.”Friday, 20 May 2011
    • THERE MUST BE A BETTER WAY? A scripted solution that can be repeated?Friday, 20 May 2011
    • BASH Kickstart and postinstall.shFriday, 20 May 2011
    • CAPISTRANO Push ssh commands to many nodesFriday, 20 May 2011
    • PLATFORM DIFFERENCES Can we abstract away the differences in the base platforms?Friday, 20 May 2011
    • PUPPET http://www.puppetlabs.com/Friday, 20 May 2011
    • CHEF http://www.opscode.com/Friday, 20 May 2011
    • LIVE DEMO Please let this work!Friday, 20 May 2011
    • CHEF-SOLO Distributed infrastructure managementFriday, 20 May 2011
    • CHEF-SERVER Centralised infrastructure managementFriday, 20 May 2011
    • Friday, 20 May 2011
    • ARCHITECTURE I know it is ruby don’t shoot me!Friday, 20 May 2011
    • Chef Server Chef Client Chef Client Chef Client Nodes converge on the state defined at the serverFriday, 20 May 2011
    • NODE JSON representation of the client server. Details retrieved by Ohai.Friday, 20 May 2011
    • Node JSON { "normal": { "runit": { "chpst_bin": "/usr/bin/chpst", "sv_bin": "/usr/bin/sv", "service_dir": "/etc/service", "sv_dir": "/etc/sv" }, "mysql": { "server_debian_password": "sK_fre0IChPsrf7VRXms", "old_passwords": 0, "server_repl_password": "UeDuoVtga8YJn6iFg0kZ", "pid_file": "/var/run/mysqld/mysqld.pid", "server_root_password": "0NOpDXQbOKpersOZvyZs", "socket": "/var/run/mysqld/mysqld.sock" }, "apache": { "cache_dir": "/var/cache/apache2", "dir": "/etc/apache2", "binary": "/usr/sbin/apache2", "icondir": "/usr/share/apache2/icons", "user": "www-data", "log_dir": "/var/log/apache2" } }, "name": "my-node", "chef_environment": "_default", "run_list": [ "role[development]", "role[webserver]" ] }Friday, 20 May 2011
    • COOKBOOKS A place to store your recipes and then share themFriday, 20 May 2011
    • COOKBOOKS CONTAIN • Attributes - default values to configure the node • Definitions - create custom resources • Files - transferred to the node • Libraries - extend chef functionality with ruby • Recipes - Specify recourses and how they should be managed • LWRP - Allow you to create your own resources & providers • Templates - ERB files that generate dynamic config filesFriday, 20 May 2011
    • RECIPES The ordered procedures that will configure resourcesFriday, 20 May 2011
    • PHP Package Recipe pkgs = value_for_platform( [ "centos", "redhat", "fedora" ] => { "default" => %w{ php53 php53-devel php53-cli php-pear } }, [ "debian", "ubuntu" ] => { "default" => %w{ php5-cgi php5 php5-dev php5-cli php-pear } }, "default" => %w{ php5-cgi php5 php5-dev php5-cli php-pear } ) pkgs.each do |pkg| package pkg do action :install end end template "#{node[php][conf_dir]}/php.ini" do source "php.ini.erb" owner "root" group "root" mode "0644" endFriday, 20 May 2011
    • RESOURCES Platform abstraction for the things you wish to configureFriday, 20 May 2011
    • COMMON RESOURCES • Package • Service • File • Template • DirectoryFriday, 20 May 2011
    • COMMON RESOURCE ACTIONS • Install • Enable • Update • RemoveFriday, 20 May 2011
    • Simple Resource Example package "php5" do action :install end template "#{node[php][conf_dir]}/php.ini" do source "php.ini.erb" owner "root" group "root" mode "0644" endFriday, 20 May 2011
    • LWRP Lightweight Resource ProvidersFriday, 20 May 2011
    • PHP LWRP include_recipe "php::pear" channels = [ "pear.symfony-project.com", "components.ez.no" ] channels.each do |chan| php_pear_channel chan do action :discover end end pu = php_pear_channel "pear.phpunit.de" do action :discover end php_pear "PHPUnit" do preferred_state "beta" channel pu.channel_name action :install endFriday, 20 May 2011
    • ATTRIBUTES Hierarchical configuration values for nodesFriday, 20 May 2011
    • Apache Default.rb Attributes # General settings default[:apache][:listen_ports] = [ "80","443" ] default[:apache][:contact] = "ops@example.com" default[:apache][:timeout] = 300 default[:apache][:keepalive] = "On" default[:apache][:keepaliverequests] = 100 default[:apache][:keepalivetimeout] = 5 # Security default[:apache][:servertokens] = "Prod" default[:apache][:serversignature] = "On" default[:apache][:traceenable] = "On"Friday, 20 May 2011
    • ROLES What will each server be?Friday, 20 May 2011
    • POSSIBLE ROLES • Webserver • Media Server • Database Master • Load-balancer • Database SlaveFriday, 20 May 2011
    • Webserver.rb Role name "webserver" description "PHP Webserver" # List of recipes and roles to apply. Requires Chef 0.8, earlier versions use recipes(). run_list( "php", "memcached", "apache2", "mysql::server", ) # Attributes applied if the node doesnt have it set already. default_attributes() # Attributes applied no matter what the node has set already. override_attributes()Friday, 20 May 2011
    • ENVIRONMENTS Where is each server?Friday, 20 May 2011
    • POSSIBLE ENVIRONMENTS • Development • User Acceptance • Staging • ProductionFriday, 20 May 2011
    • Development.rb Environment name "development" description "The development environment" override_attributes ({ "apache2" => { "listen_ports" => [ "80", "443" ] }, "mysql" => { "server_root_password" => "root" } })Friday, 20 May 2011
    • Environment Development Production Role: Webserver Node: Server#1 Node: Server#4 Node: Server#2 Node: Server#5 Role: Database Node: Server#3 Node Server#6 MasterFriday, 20 May 2011
    • SECURITY Is at the heart of the chef architectureFriday, 20 May 2011
    • KNIFE The only utensil you need to master chef!Friday, 20 May 2011
    • WITH KNIFE YOU CAN • Create cookbooks • Upload cookbooks to your chef-server • List / Edit client nodes • Create / Edit Roles • Create / Edit EnvironmentsFriday, 20 May 2011
    • WORKFLOWS Choose one and stick to it!Friday, 20 May 2011
    • EDIT JSON DIRECTLY $ knife role edit webserver { "name": "webserver", "default_attributes": { }, "json_class": "Chef::Role", "env_run_lists": { }, "run_list": [ "recipe[php]", "recipe[memcached]", "recipe[apache2]", "recipe[mysql::server]" ], "description": "PHP Webserver", "chef_type": "role", "override_attributes": { } }Friday, 20 May 2011
    • UPLOAD .RB FILES name "webserver" description "PHP Webserver" # List of recipes and roles to apply. Requires Chef 0.8, earlier versions use recipes (). run_list( "php", "memcached", "apache2", "mysql::server", "magento" ) # Attributes applied if the node doesnt have it set already. default_attributes() # Attributes applied no matter what the node has set already. override_attributes() $ knife role from file webserver.rbFriday, 20 May 2011
    • CLOUD PROVISION Just got even easier!Friday, 20 May 2011
    • Create a new server and bootstrap chef $ knife rackspace server create --server-name myserver --image 62 --flavor 4Friday, 20 May 2011
    • SIT BACK Your infrastructure is cookedFriday, 20 May 2011
    • VAGRANT Automated VM provisioningFriday, 20 May 2011
    • QUESTIONS? http://joind.in/talk/view/3227Friday, 20 May 2011
    • REFERENCES • http://www.opscode.com/ • http://www.puppetlabs.com/ • https://github.com/capistrano/capistrano/wiki • https://github.com/suitmymind/ubuntu-machine • http://vagrantup.com/Friday, 20 May 2011
    • IMAGE CREDITS http://www.flickr.com/photos/krisvandesande/ http://www.flickr.com/photos/61928261@N00/ http://www.flickr.com/photos/marklarson/Friday, 20 May 2011
    • WE ARE HIRING! http://www.ibuildings.co.uk/about/careers/Friday, 20 May 2011