SlideShare una empresa de Scribd logo
1 de 42
Automatiser son
              infrastructure avec Chef


                               Olivier Gutknecht
                               Fotonauts, Inc.
                               olg@fotonauts.com - twitter.com/olg


  An impromptu session @
Blockcamp Paris - 28/11/2009
Orage, ô désespoir


 X     X   X   X X
CHEF
http://www.brooklynstreetart.com/theBlog/wp-content/uploads/2008/12/swedish_chef_bork-sleeper-cell.jpg
Mar 06, 2008

Born




       6 mars 2008
Jan 05, 2009

Released
Apr 24, 2009

Funded
Chef en 2 lignes


• Définir un état stable souhaité pour son
  infrastructure
• ... et laisser Chef l’y amener
Vu de loin
Vu de loin


• Un système de gestion de configuration
Vu de loin


• Un système de gestion de configuration
• Une bibliothèque Ruby pour l’implémenter
Vu de loin


• Un système de gestion de configuration
• Une bibliothèque Ruby pour l’implémenter
• Une API REST pour interagir
Principes

• Idempotent
• Extensible
• Introspectable
• Validable
Infrastructure is Code

• Du code, pas des lignes de commandes
• Réutilisable, versionable, commenté
• À un niveau global de l’infrastructure
• “Quasi” déclaratif
Chef
                     Server


                      Polling




           Synchronisation des recettes
         Echange de l’état de configuration



Chef                                         Chef
Client                                       Client
Le Serveur Chef

Chef
Client
                               Search index (solr, ferret)

Chef
Client       Chef Server   Cookbooks repository (filesystem)


                           Nodes status repository (couchdb)
Chef
Client
Chef - Web UI
Chef - Web UI
chef-client

• S’authentifie auprès du Chef Server
• Envoie sa configuration locale (via Ohai)
• Exécute les recettes transmises par le serveur
chef-server

• Garde trace de la configuration des clients
  (dans CouchDB et dans le search index)
• Maintient le livre de recettes (les cookbooks)
• Fournit aux clients leur configuration et leurs
  recettes
Un nœud

• Typiquement un système donné (un serveur)
• ... avec une liste de recettes et d’attributs
• ... qui lance régulièrement chef-client pour
  appliquer les recettes
Cookbooks
activemq         erlang        lvm         postfix        stompserver
apache2          fail2ban      man         postgresql    subversion
apparmor         gems          maradns     python        sudo
apt              git           memcached   quick_start   teamspeak
aws              glassfish      mercurial   radiant       thrift
boost            god           munin       rails         tomcat6
bootstrap        hadoop        mysql       redmine       ubuntu
buildessential   haproxy       nginx       resolver      varnish
capistrano       heartbeat     nscd        rsync         xfs
chef             imagemagick   ntp         rsyslog       zsh
couchdb          iptables      openldap    ruby          ...
django           java          openssh     runit
djbdns           jira          openvpn     screen
drbd             keepalived    packages    solr
dynomite         kickstart     passenger   sqlite
ec2              logrotate     perl        ssh
emacs            logwatch      php         known_hosts
Resources
 Meta                          HTTP Request                    Route
 Cron                          Ifconfig                         Ruby Block
 Deploy                        Link                            SCM
 Directory                     Mount                           Script
 Execute                       Package                         Service
 File                          Remote Directory                Template
 Group                         Remote File                     User



Un provider compare l’état voulu d’une resource
avec l’état du système et prend les actions nécessaires
  Par exemple, il existe des “providers” rpm, apt-get ou gem pour les resources “Package”
Un cookbook
attributes                             Valeurs par défaut, abstractions, customisation
     server.rb
metadata.rb                                 Description, documentation des attributs
metadata.json
recipes
     default.rb                                 Recette par défaut pour le cookbook
     server.rb                                                    Variante spécialisée
     client.rb                                                    Variante spécialisée
templates
      default                       Fichiers génériques de templates de configuration
             my.cfn.erb
      redhat              Fichiers spécifiques à un système remplaçant les génériques
             my.cfn.erb
libraries                                  Bibliothèque de fonctions Ruby arbitraires
     my_specific_code.rb
Un exemple

le cookbook
 memcached
Meta-data
maintainer         "Opscode, Inc."                             cookbooks/memcached/metadata.rb
maintainer_email   "cookbooks@opscode.com"
license            "Apache 2.0"
description        "Installs memcached and provides a define to set up an instance of
                    memcache via runit"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
version            "0.8"
depends            "runit"
%w{ ubuntu debian }.each do |os|
  supports os
end
attribute "memcached/memory",
  :display_name => "Memcached Memory",
  :description => "Memory allocated for memcached instance",
  :default => "64"
 
attribute "memcached/port",
  :display_name => "Memcached Port",
  :description => "Port to use for memcached instance",
  :default => "11211"
 
attribute "memcached/user",
  :display_name => "Memcached User",
  :description => "User to run memcached instance as",
  :default => "nobody"
Attributes
                                           cookbooks/memcached/attributes/memcached.rb
set_unless[:memcached][:memory] = 64
set_unless[:memcached][:port] = 11211
set_unless[:memcached][:user] = "nobody"
Recipe
package "memcached" do                                    cookbooks/memcached/recipes/default.rb
  action :upgrade
end
 
package "libmemcache-dev" do
  action :upgrade
end
 
service "memcached" do
  action :nothing
end
 
template "/etc/memcached.conf" do
  source "memcached.conf.erb"
  owner "root"
  group "root"
  mode "0644"
  variables(
    :ipaddress => node[:ipaddress],
    :user => node[:memcached][:user],
    :port => node[:memcached][:port],
    :memory => node[:memcached][:memory]
  )
  notifies :restart, resources(:service => "memcached"), :immediately
end
Template
#                                              cookbooks/memcached/templates/default/memcached.conf.erb
# Configured by Chef. Local changes will be lost.
#
# Log memcached's output to /var/log/memcached
logfile /var/log/memcached.log
 
# Start with a cap of 64 megs of memory. It's reasonable, and the daemon default
# Note that the daemon will grow to this size, but does not start out holding this much
# memory
-m <%= @memory %>
 
# Default connection port is 11211
-p <%= @port %>
 
# Run the daemon as root. The start-memcached will default to running as root if no
# -u command is present in this config file
-u <%= @user %>
 
# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.
-l <%= @ipaddress %>
 
Autres exemples
Exemple: le monitoring




                  http://www.flickr.com/photos/jiathwee/2870629436/sizes/l/
Exemple: le monitoring


•   Doit être intégré avec le déploiement/développement




                                                http://www.flickr.com/photos/jiathwee/2870629436/sizes/l/
Exemple: le monitoring


•   Doit être intégré avec le déploiement/développement

•   Utilisation du search index de Chef pour configurer
    dynamiquement le monitoring




                                                http://www.flickr.com/photos/jiathwee/2870629436/sizes/l/
(oui, tout automatiser)

    fotonauts[:admins] = {
      :kali     => { :sms =>   "3360xxxxxx"   },
      :olg      => { :sms =>   "3360xxxxxx"   },
      :ber      => { :sms =>   "3360xxxxxx"   },
      :aymerick => { :sms =>   "3360xxxxxx"   },
      :manu     => { :sms =>   "3360xxxxxx"   },
      :fred     => { :sms =>   "3360xxxxxx"   },
    }
Exemple: Load Balancing

• Simple !
• Chercher quels nœuds ont le rôle de
  backend rails
• Et construire le fichier de configuration en
  fonction
# find all nodes with the "picor" (main app) and "search" recipes                         recipe
client_be_attributes = search(:node, "recipe:picor")
client_sr_attributes = search(:node, "recipe:searchr")
 
backends[:mainapp] = client_be_attributes.map{|cfg| {:hostname=> cfg["hostname"], :fqdn =>
         cfg["fqdn"], :port => cfg["picor_port"], :weight => cfg["picor_backend_weight"]}}

backends[:searchr] = client_sr_attributes.map{|cfg| {:hostname=> cfg["hostname"], :fqdn =>
         cfg["fqdn"], :port => cfg["searchr_port"], :weight => cfg["searchr_backend_weight"]}}



<%                                                                               template varnish.conf
@backends.each do |backend_name, servers|
  next if servers.blank?
  servers.each do |server|
%>
backend <%= backend_name %>_<%= server[:hostname] %> {
  .host = "<%= server[:fqdn] %>";
  .port = "<%= server[:port] %>"; }
<%
  end
end
%>
<% unless @backends[:searchr].empty? %>
  if (req.http.host ~ "search") {
    // search request
    set req.backend = searchr;
  }
<% end %>
...
Pratiques extrêmes


    Installation d’un varnish
  patché depuis le trunk SVN
One more thing
  Casserole
read-only 0.6 - WIP read-write 0.8
http://www.flickr.com/photos/jackol/1766679527/sizes/l/




    Q &A

         +
http://wiki.opscode.com
 irc.freenode.net #chef

Más contenido relacionado

La actualidad más candente

Play Framework - Toulouse JUG - nov 2011
Play Framework - Toulouse JUG - nov 2011Play Framework - Toulouse JUG - nov 2011
Play Framework - Toulouse JUG - nov 2011Sylvain Wallez
 
ZendFramework2 - Présentation
ZendFramework2 - PrésentationZendFramework2 - Présentation
ZendFramework2 - Présentationjulien pauli
 
Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Hugo Hamon
 
Alphorm.com Formation Scripting Bash avancé pour GNU/Linux
Alphorm.com   Formation Scripting Bash avancé pour GNU/LinuxAlphorm.com   Formation Scripting Bash avancé pour GNU/Linux
Alphorm.com Formation Scripting Bash avancé pour GNU/LinuxAlphorm
 
Introductions Aux Servlets
Introductions Aux ServletsIntroductions Aux Servlets
Introductions Aux ServletsFrançois Charoy
 
Rapport openembedded
Rapport openembeddedRapport openembedded
Rapport openembeddedAyoub Rouzi
 
Presentation du gestionnaire de configuration Puppet
Presentation du gestionnaire de configuration PuppetPresentation du gestionnaire de configuration Puppet
Presentation du gestionnaire de configuration PuppetAurélie Henriot
 
EBIZNEXT-RIAK
EBIZNEXT-RIAKEBIZNEXT-RIAK
EBIZNEXT-RIAKebiznext
 
DevOps illustré : la jungle de la configuration d'une application
DevOps illustré : la jungle de la configuration d'une applicationDevOps illustré : la jungle de la configuration d'une application
DevOps illustré : la jungle de la configuration d'une applicationgdigugli
 
les servlets-java EE
les  servlets-java EEles  servlets-java EE
les servlets-java EEYassine Badri
 
Presentation Tomcat Load Balancer
Presentation Tomcat Load BalancerPresentation Tomcat Load Balancer
Presentation Tomcat Load Balancertarkaus
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express jsAbdoulaye Dieng
 

La actualidad más candente (20)

Play Framework - Toulouse JUG - nov 2011
Play Framework - Toulouse JUG - nov 2011Play Framework - Toulouse JUG - nov 2011
Play Framework - Toulouse JUG - nov 2011
 
Python + ansible = ♥
Python + ansible = ♥Python + ansible = ♥
Python + ansible = ♥
 
ZendFramework2 - Présentation
ZendFramework2 - PrésentationZendFramework2 - Présentation
ZendFramework2 - Présentation
 
Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)Développeurs, cachez-moi ça ! (Paris Web 2011)
Développeurs, cachez-moi ça ! (Paris Web 2011)
 
Cours JSP
Cours JSPCours JSP
Cours JSP
 
Alphorm.com Formation Scripting Bash avancé pour GNU/Linux
Alphorm.com   Formation Scripting Bash avancé pour GNU/LinuxAlphorm.com   Formation Scripting Bash avancé pour GNU/Linux
Alphorm.com Formation Scripting Bash avancé pour GNU/Linux
 
Nagios
NagiosNagios
Nagios
 
Jsp
JspJsp
Jsp
 
Introductions Aux Servlets
Introductions Aux ServletsIntroductions Aux Servlets
Introductions Aux Servlets
 
Rapport openembedded
Rapport openembeddedRapport openembedded
Rapport openembedded
 
Serveurs
ServeursServeurs
Serveurs
 
Presentation du gestionnaire de configuration Puppet
Presentation du gestionnaire de configuration PuppetPresentation du gestionnaire de configuration Puppet
Presentation du gestionnaire de configuration Puppet
 
EBIZNEXT-RIAK
EBIZNEXT-RIAKEBIZNEXT-RIAK
EBIZNEXT-RIAK
 
DevOps illustré : la jungle de la configuration d'une application
DevOps illustré : la jungle de la configuration d'une applicationDevOps illustré : la jungle de la configuration d'une application
DevOps illustré : la jungle de la configuration d'une application
 
les servlets-java EE
les  servlets-java EEles  servlets-java EE
les servlets-java EE
 
APACHE TOMCAT
APACHE TOMCATAPACHE TOMCAT
APACHE TOMCAT
 
Presentation Tomcat Load Balancer
Presentation Tomcat Load BalancerPresentation Tomcat Load Balancer
Presentation Tomcat Load Balancer
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express js
 
Sudoc plus - Technique
Sudoc plus - TechniqueSudoc plus - Technique
Sudoc plus - Technique
 
Présentation1
Présentation1Présentation1
Présentation1
 

Destacado

Destacado (6)

中國的文化遺產
中國的文化遺產中國的文化遺產
中國的文化遺產
 
Introduction à MacRuby
Introduction à MacRubyIntroduction à MacRuby
Introduction à MacRuby
 
Cuisiner ses infrastructures avec Chef
Cuisiner ses infrastructures avec ChefCuisiner ses infrastructures avec Chef
Cuisiner ses infrastructures avec Chef
 
WebWorkersCamp 2010
WebWorkersCamp 2010WebWorkersCamp 2010
WebWorkersCamp 2010
 
Lib qual+ à l'ubs
Lib qual+ à l'ubsLib qual+ à l'ubs
Lib qual+ à l'ubs
 
MacRuby, an introduction
MacRuby, an introductionMacRuby, an introduction
MacRuby, an introduction
 

Similar a Chef - Paris BlockCamp - Nov 09

08 01 mise en place d'un serveur web
08 01 mise en place d'un serveur web08 01 mise en place d'un serveur web
08 01 mise en place d'un serveur webNoël
 
Codons notre infrastructure
Codons notre infrastructureCodons notre infrastructure
Codons notre infrastructurecontinuousphp
 
Ez18n Annotation Processing Tool in a nutshell
Ez18n Annotation Processing Tool in a nutshellEz18n Annotation Processing Tool in a nutshell
Ez18n Annotation Processing Tool in a nutshellgdigugli
 
Laravel yet another framework
Laravel  yet another frameworkLaravel  yet another framework
Laravel yet another frameworkLAHAXE Arnaud
 
Ops@viadeo : Puppet & Co... 6 mois après par Xavier Krantz
Ops@viadeo : Puppet & Co... 6 mois après par Xavier KrantzOps@viadeo : Puppet & Co... 6 mois après par Xavier Krantz
Ops@viadeo : Puppet & Co... 6 mois après par Xavier KrantzOlivier DASINI
 
Mysql Apche PHP sous linux
Mysql Apche PHP sous linuxMysql Apche PHP sous linux
Mysql Apche PHP sous linuxKhalid ALLILI
 
Play Framework
Play FrameworkPlay Framework
Play FrameworkArmaklan
 
TDD for DevOps with Chef
TDD for DevOps with ChefTDD for DevOps with Chef
TDD for DevOps with ChefOlivier BAZOUD
 
Alphorm.com Formation Apache - Le Guide Complet de l'administrateur
Alphorm.com Formation Apache - Le Guide Complet de l'administrateurAlphorm.com Formation Apache - Le Guide Complet de l'administrateur
Alphorm.com Formation Apache - Le Guide Complet de l'administrateurAlphorm
 
05 - creation-playbook-ansible-stack-lamp.pdf
05 - creation-playbook-ansible-stack-lamp.pdf05 - creation-playbook-ansible-stack-lamp.pdf
05 - creation-playbook-ansible-stack-lamp.pdfbibouechristian
 
05 - creation-playbook-ansible-stack-lamp.pdf
05 - creation-playbook-ansible-stack-lamp.pdf05 - creation-playbook-ansible-stack-lamp.pdf
05 - creation-playbook-ansible-stack-lamp.pdfbibouechristian
 
Rex docker en production meeutp-docker-nantes
Rex docker en production meeutp-docker-nantesRex docker en production meeutp-docker-nantes
Rex docker en production meeutp-docker-nantesChristophe Furmaniak
 
20111220 lyon jug-packaging-natif
20111220 lyon jug-packaging-natif20111220 lyon jug-packaging-natif
20111220 lyon jug-packaging-natifHenri Gomez
 
Share point 2013 distributed cache
Share point 2013 distributed cacheShare point 2013 distributed cache
Share point 2013 distributed cacheMichael Nokhamzon
 
Zabbix, garder un oeil toujours ouvert
Zabbix, garder un oeil toujours ouvertZabbix, garder un oeil toujours ouvert
Zabbix, garder un oeil toujours ouvertLook a box
 
Une gestion efficace du changement de vos structures de données relationnelle...
Une gestion efficace du changement de vos structures de données relationnelle...Une gestion efficace du changement de vos structures de données relationnelle...
Une gestion efficace du changement de vos structures de données relationnelle...Olivier DASINI
 

Similar a Chef - Paris BlockCamp - Nov 09 (20)

08 01 mise en place d'un serveur web
08 01 mise en place d'un serveur web08 01 mise en place d'un serveur web
08 01 mise en place d'un serveur web
 
Codons notre infrastructure
Codons notre infrastructureCodons notre infrastructure
Codons notre infrastructure
 
Codons notre infrastructure
Codons notre infrastructureCodons notre infrastructure
Codons notre infrastructure
 
Ez18n Annotation Processing Tool in a nutshell
Ez18n Annotation Processing Tool in a nutshellEz18n Annotation Processing Tool in a nutshell
Ez18n Annotation Processing Tool in a nutshell
 
Laravel yet another framework
Laravel  yet another frameworkLaravel  yet another framework
Laravel yet another framework
 
Formation Google App Engine
Formation Google App EngineFormation Google App Engine
Formation Google App Engine
 
Ops@viadeo : Puppet & Co... 6 mois après par Xavier Krantz
Ops@viadeo : Puppet & Co... 6 mois après par Xavier KrantzOps@viadeo : Puppet & Co... 6 mois après par Xavier Krantz
Ops@viadeo : Puppet & Co... 6 mois après par Xavier Krantz
 
Mysql Apche PHP sous linux
Mysql Apche PHP sous linuxMysql Apche PHP sous linux
Mysql Apche PHP sous linux
 
Maven et industrialisation du logiciel
Maven et industrialisation du logicielMaven et industrialisation du logiciel
Maven et industrialisation du logiciel
 
Play Framework
Play FrameworkPlay Framework
Play Framework
 
TDD for DevOps with Chef
TDD for DevOps with ChefTDD for DevOps with Chef
TDD for DevOps with Chef
 
Rails 3 au Djangocong
Rails 3 au DjangocongRails 3 au Djangocong
Rails 3 au Djangocong
 
Alphorm.com Formation Apache - Le Guide Complet de l'administrateur
Alphorm.com Formation Apache - Le Guide Complet de l'administrateurAlphorm.com Formation Apache - Le Guide Complet de l'administrateur
Alphorm.com Formation Apache - Le Guide Complet de l'administrateur
 
05 - creation-playbook-ansible-stack-lamp.pdf
05 - creation-playbook-ansible-stack-lamp.pdf05 - creation-playbook-ansible-stack-lamp.pdf
05 - creation-playbook-ansible-stack-lamp.pdf
 
05 - creation-playbook-ansible-stack-lamp.pdf
05 - creation-playbook-ansible-stack-lamp.pdf05 - creation-playbook-ansible-stack-lamp.pdf
05 - creation-playbook-ansible-stack-lamp.pdf
 
Rex docker en production meeutp-docker-nantes
Rex docker en production meeutp-docker-nantesRex docker en production meeutp-docker-nantes
Rex docker en production meeutp-docker-nantes
 
20111220 lyon jug-packaging-natif
20111220 lyon jug-packaging-natif20111220 lyon jug-packaging-natif
20111220 lyon jug-packaging-natif
 
Share point 2013 distributed cache
Share point 2013 distributed cacheShare point 2013 distributed cache
Share point 2013 distributed cache
 
Zabbix, garder un oeil toujours ouvert
Zabbix, garder un oeil toujours ouvertZabbix, garder un oeil toujours ouvert
Zabbix, garder un oeil toujours ouvert
 
Une gestion efficace du changement de vos structures de données relationnelle...
Une gestion efficace du changement de vos structures de données relationnelle...Une gestion efficace du changement de vos structures de données relationnelle...
Une gestion efficace du changement de vos structures de données relationnelle...
 

Chef - Paris BlockCamp - Nov 09

  • 1. Automatiser son infrastructure avec Chef Olivier Gutknecht Fotonauts, Inc. olg@fotonauts.com - twitter.com/olg An impromptu session @ Blockcamp Paris - 28/11/2009
  • 5. Mar 06, 2008 Born 6 mars 2008
  • 8. Chef en 2 lignes • Définir un état stable souhaité pour son infrastructure • ... et laisser Chef l’y amener
  • 10. Vu de loin • Un système de gestion de configuration
  • 11. Vu de loin • Un système de gestion de configuration • Une bibliothèque Ruby pour l’implémenter
  • 12. Vu de loin • Un système de gestion de configuration • Une bibliothèque Ruby pour l’implémenter • Une API REST pour interagir
  • 13. Principes • Idempotent • Extensible • Introspectable • Validable
  • 14. Infrastructure is Code • Du code, pas des lignes de commandes • Réutilisable, versionable, commenté • À un niveau global de l’infrastructure • “Quasi” déclaratif
  • 15. Chef Server Polling Synchronisation des recettes Echange de l’état de configuration Chef Chef Client Client
  • 16. Le Serveur Chef Chef Client Search index (solr, ferret) Chef Client Chef Server Cookbooks repository (filesystem) Nodes status repository (couchdb) Chef Client
  • 19. chef-client • S’authentifie auprès du Chef Server • Envoie sa configuration locale (via Ohai) • Exécute les recettes transmises par le serveur
  • 20. chef-server • Garde trace de la configuration des clients (dans CouchDB et dans le search index) • Maintient le livre de recettes (les cookbooks) • Fournit aux clients leur configuration et leurs recettes
  • 21. Un nœud • Typiquement un système donné (un serveur) • ... avec une liste de recettes et d’attributs • ... qui lance régulièrement chef-client pour appliquer les recettes
  • 22. Cookbooks activemq erlang lvm postfix stompserver apache2 fail2ban man postgresql subversion apparmor gems maradns python sudo apt git memcached quick_start teamspeak aws glassfish mercurial radiant thrift boost god munin rails tomcat6 bootstrap hadoop mysql redmine ubuntu buildessential haproxy nginx resolver varnish capistrano heartbeat nscd rsync xfs chef imagemagick ntp rsyslog zsh couchdb iptables openldap ruby ... django java openssh runit djbdns jira openvpn screen drbd keepalived packages solr dynomite kickstart passenger sqlite ec2 logrotate perl ssh emacs logwatch php known_hosts
  • 23. Resources Meta HTTP Request Route Cron Ifconfig Ruby Block Deploy Link SCM Directory Mount Script Execute Package Service File Remote Directory Template Group Remote File User Un provider compare l’état voulu d’une resource avec l’état du système et prend les actions nécessaires Par exemple, il existe des “providers” rpm, apt-get ou gem pour les resources “Package”
  • 24. Un cookbook attributes Valeurs par défaut, abstractions, customisation server.rb metadata.rb Description, documentation des attributs metadata.json recipes default.rb Recette par défaut pour le cookbook server.rb Variante spécialisée client.rb Variante spécialisée templates default Fichiers génériques de templates de configuration my.cfn.erb redhat Fichiers spécifiques à un système remplaçant les génériques my.cfn.erb libraries Bibliothèque de fonctions Ruby arbitraires my_specific_code.rb
  • 26. Meta-data maintainer "Opscode, Inc." cookbooks/memcached/metadata.rb maintainer_email "cookbooks@opscode.com" license "Apache 2.0" description "Installs memcached and provides a define to set up an instance of memcache via runit" long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc')) version "0.8" depends "runit" %w{ ubuntu debian }.each do |os|   supports os end attribute "memcached/memory",   :display_name => "Memcached Memory",   :description => "Memory allocated for memcached instance",   :default => "64"   attribute "memcached/port",   :display_name => "Memcached Port",   :description => "Port to use for memcached instance",   :default => "11211"   attribute "memcached/user",   :display_name => "Memcached User",   :description => "User to run memcached instance as",   :default => "nobody"
  • 27. Attributes cookbooks/memcached/attributes/memcached.rb set_unless[:memcached][:memory] = 64 set_unless[:memcached][:port] = 11211 set_unless[:memcached][:user] = "nobody"
  • 28. Recipe package "memcached" do cookbooks/memcached/recipes/default.rb   action :upgrade end   package "libmemcache-dev" do   action :upgrade end   service "memcached" do   action :nothing end   template "/etc/memcached.conf" do   source "memcached.conf.erb"   owner "root"   group "root"   mode "0644"   variables(     :ipaddress => node[:ipaddress],     :user => node[:memcached][:user],     :port => node[:memcached][:port],     :memory => node[:memcached][:memory]   )   notifies :restart, resources(:service => "memcached"), :immediately end
  • 29. Template # cookbooks/memcached/templates/default/memcached.conf.erb # Configured by Chef. Local changes will be lost. # # Log memcached's output to /var/log/memcached logfile /var/log/memcached.log   # Start with a cap of 64 megs of memory. It's reasonable, and the daemon default # Note that the daemon will grow to this size, but does not start out holding this much # memory -m <%= @memory %>   # Default connection port is 11211 -p <%= @port %>   # Run the daemon as root. The start-memcached will default to running as root if no # -u command is present in this config file -u <%= @user %>   # Specify which IP address to listen on. The default is to listen on all IP addresses # This parameter is one of the only security measures that memcached has, so make sure # it's listening on a firewalled interface. -l <%= @ipaddress %>  
  • 31. Exemple: le monitoring http://www.flickr.com/photos/jiathwee/2870629436/sizes/l/
  • 32. Exemple: le monitoring • Doit être intégré avec le déploiement/développement http://www.flickr.com/photos/jiathwee/2870629436/sizes/l/
  • 33. Exemple: le monitoring • Doit être intégré avec le déploiement/développement • Utilisation du search index de Chef pour configurer dynamiquement le monitoring http://www.flickr.com/photos/jiathwee/2870629436/sizes/l/
  • 34. (oui, tout automatiser) fotonauts[:admins] = { :kali => { :sms => "3360xxxxxx" }, :olg => { :sms => "3360xxxxxx" }, :ber => { :sms => "3360xxxxxx" }, :aymerick => { :sms => "3360xxxxxx" }, :manu => { :sms => "3360xxxxxx" }, :fred => { :sms => "3360xxxxxx" }, }
  • 35. Exemple: Load Balancing • Simple ! • Chercher quels nœuds ont le rôle de backend rails • Et construire le fichier de configuration en fonction
  • 36. # find all nodes with the "picor" (main app) and "search" recipes recipe client_be_attributes = search(:node, "recipe:picor") client_sr_attributes = search(:node, "recipe:searchr")   backends[:mainapp] = client_be_attributes.map{|cfg| {:hostname=> cfg["hostname"], :fqdn => cfg["fqdn"], :port => cfg["picor_port"], :weight => cfg["picor_backend_weight"]}} backends[:searchr] = client_sr_attributes.map{|cfg| {:hostname=> cfg["hostname"], :fqdn => cfg["fqdn"], :port => cfg["searchr_port"], :weight => cfg["searchr_backend_weight"]}} <% template varnish.conf @backends.each do |backend_name, servers|   next if servers.blank?   servers.each do |server| %> backend <%= backend_name %>_<%= server[:hostname] %> {   .host = "<%= server[:fqdn] %>";   .port = "<%= server[:port] %>"; } <%   end end %> <% unless @backends[:searchr].empty? %>   if (req.http.host ~ "search") {     // search request     set req.backend = searchr;   } <% end %> ...
  • 37. Pratiques extrêmes Installation d’un varnish patché depuis le trunk SVN
  • 38.
  • 39.
  • 40. One more thing Casserole
  • 41. read-only 0.6 - WIP read-write 0.8
  • 42. http://www.flickr.com/photos/jackol/1766679527/sizes/l/ Q &A + http://wiki.opscode.com irc.freenode.net #chef