Konfigurationsmanagement bei Netzwerkhardware - Eine Evaluation
Konfigurationsmanagement mit Opscode Chef
1. Konfigurationsmanagement mit Chef 1 / 47
Konfigurationsmanagement mit Chef
Konrad F. Heimel
Zentrum für Informations- und Medientechnologie, Universität Siegen
8. September 2014
2. Konfigurationsmanagement mit Chef 2 / 47
Warum eigentlich Konfigurationsmanagment?
Inhalt
1 Warum eigentlich Konfigurationsmanagment?
Das Project Eduprobe
Lösungsmöglichkeiten
2 Welches Konfigurationsmanagmentsystem ist das Beste?
3 Einführung in Opscode Chef
4 Die Begriffswelt von Chef
5 Ein paar unserer Cookbooks
3. Konfigurationsmanagement mit Chef 3 / 47
Warum eigentlich Konfigurationsmanagment?
Das Project Eduprobe
Eduprobes
Ziel
Messung der Verfügbarkeit von Eduroam in den Liegenschaften mit
Raspberry Pi’s
4. Konfigurationsmanagement mit Chef 4 / 47
Warum eigentlich Konfigurationsmanagment?
Das Project Eduprobe
Abbildung: Die Cacti-Graphen der Eduprobe-AR
5. Konfigurationsmanagement mit Chef 5 / 47
Warum eigentlich Konfigurationsmanagment?
Konfigurationsaufwand
Pro Gerät zu konfigurieren
SSH, public keys
NTP, DNS Server
Raspian Repository
SNMPD
fail2ban
Weitere Packete müssen installiert werden:
macchanger
wpasupplicant
syslog-ng
Die Skripte zum messen von Eduroam und zur Bereitstellung
der Messwerte via SNMPD
cronjobs
6. Konfigurationsmanagement mit Chef 6 / 47
Warum eigentlich Konfigurationsmanagment?
Lösungsmöglichkeiten
Warum kein “Golden Image“?
Nachträgliche Änderungen
Veraltet sehr schnell
Black Box
7. Konfigurationsmanagement mit Chef 7 / 47
Warum eigentlich Konfigurationsmanagment?
Lösungsmöglichkeiten
Warum nicht Skripten?
Für andere schwer nachzuvollziehen
Hoher Aufwand
Warum das Rad neu erfinden?
8. Konfigurationsmanagement mit Chef 8 / 47
Warum eigentlich Konfigurationsmanagment?
Lösungsmöglichkeiten
$ knife bootstrap eduprobe-ar -d raspbian -N eduprobe-ar -x pi -r’ role[eduprobe]’ –sudo
Mit einer Zeile
Chef-Client
SSH, public keys
NTP, DNS Server
Raspian Repository
SNMPD
fail2ban
alle notwendigen Pakete werden installiert
Skripte werden kopiert
cronjobs
9. Konfigurationsmanagement mit Chef 9 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Inhalt
1 Warum eigentlich Konfigurationsmanagment?
2 Welches Konfigurationsmanagmentsystem ist das Beste?
Die vier verbreitetesten Konfigurationsmanagementsysteme
Eckdaten
Popularitätsvergleich
3 Einführung in Opscode Chef
4 Die Begriffswelt von Chef
5 Ein paar unserer Cookbooks
10. Konfigurationsmanagement mit Chef 10 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Die vier verbreitetesten Konfigurationsmanagementsysteme
Die vier verbreitetesten Konfigurationsmanagementsysteme
11. Konfigurationsmanagement mit Chef 11 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Eckdaten
Eckdaten
Grundlegendes
basiert auf der Erstes Wechselseitige
Lizenz Sprache Release Auth. Encrypt.
Puppet GPL Ruby 2005-08-30 Ja Ja
Chef Apache Ruby 2009-01-15 Ja Ja
Ansible Apache Python 2012-03-08 Ja Ja
Salt Apache Python 2011-03-17 Ja Ja
Kompatibilität
Linux Mac OS X Windows Solaris *BSD
Puppet Ja Ja Teilweise Ja Ja
Chef Ja Ja Ja Ja Ja
Ansible Ja Ja Ja Ja Ja
Salt Ja Ja Ja Ja Ja
12. Konfigurationsmanagement mit Chef 12 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Popularitätsvergleich
Popularitätsvergleich
Chef ist hier unterrepräsentiert, da die präferierte Installationsmethode sog. ruby-gems
sind
13. Konfigurationsmanagement mit Chef 13 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Popularitätsvergleich
Quelle: http://redmonk.com/sogrady/2013/12/06/configuration-management-2013/
14. Konfigurationsmanagement mit Chef 14 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Popularitätsvergleich
Quelle: http://redmonk.com/sogrady/2013/12/06/configuration-management-2013/
15. Konfigurationsmanagement mit Chef 15 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Popularitätsvergleich
Fazit:
Puppet ist Marktführer, dicht gefolgt von Chef
16. Konfigurationsmanagement mit Chef 15 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Popularitätsvergleich
Fazit:
Puppet ist Marktführer, dicht gefolgt von Chef
Anisble und Salt sind sehr wachstumsstark
17. Konfigurationsmanagement mit Chef 15 / 47
Welches Konfigurationsmanagmentsystem ist das Beste?
Popularitätsvergleich
Fazit:
Puppet ist Marktführer, dicht gefolgt von Chef
Anisble und Salt sind sehr wachstumsstark
Die Entscheidung ist daher vor allem eine Geschmacksfrage
18. Konfigurationsmanagement mit Chef 16 / 47
Einführung in Opscode Chef
Inhalt
1 Warum eigentlich Konfigurationsmanagment?
2 Welches Konfigurationsmanagmentsystem ist das Beste?
3 Einführung in Opscode Chef
Einige Fakten
Prinzipien
4 Die Begriffswelt von Chef
5 Ein paar unserer Cookbooks
20. Konfigurationsmanagement mit Chef 18 / 47
Einführung in Opscode Chef
Einige Fakten
Initial release: 15.1.2009
Basiert auf der Programmiersprache Ruby
Support für Linux, Windows, Mac OS, Solaris und FreeBSD
10,000+ Nodes auf einem Chef-Server managen
Open-Source-Chef ist kostenlos (es gibt aber auch eine
Cloud-Option namens “Hosted Chef“
Chef wird z.B. benutzt von Mozilla, Facebook, HP Public
Cloud
21. Konfigurationsmanagement mit Chef 19 / 47
Einführung in Opscode Chef
Prinzipien
Prinzipien
Idempotent
Reasonability
Sane defaults
Hackability
TMTOWTDI
22. Konfigurationsmanagement mit Chef 20 / 47
Die Begriffswelt von Chef
Inhalt
1 Warum eigentlich Konfigurationsmanagment?
2 Welches Konfigurationsmanagmentsystem ist das Beste?
3 Einführung in Opscode Chef
4 Die Begriffswelt von Chef
Chef-Client
Chef-Server
Chef-Solo
Knife
Attribute
Rolle
Rezept
Ressource
Provider
Cookbook
5 Ein paar unserer Cookbooks
23. Konfigurationsmanagement mit Chef 21 / 47
Die Begriffswelt von Chef
Chef-Client
Chef-Client läuft auf den Clients, also z.B. den
Eduprobes.
Ein Client nennt sich dabei aber Node.
24. Konfigurationsmanagement mit Chef 22 / 47
Die Begriffswelt von Chef
Chef-Server
1 kheimel@vagrantbox:~$ sudo chef-client
2 [sudo] password for kheimel:
3 Starting Chef Client, version 11.8.2
4 resolving cookbooks for run list: ["debian-minimal", "motd"]
5 Synchronizing Cookbooks:
6 - motd
7 - debian-minimal
8 Compiling Cookbooks...
9 Converging 25 resources
10 Recipe: debian-minimal::default
11 * user[assmann] action create (up to date)
12 * directory[/home/assmann/.] action create (up to date)
13 * directory[/root/.ssh/] action create (up to date)
14 * service[ssh] action reload
15 - reload service service[ssh]
16 * service[fail2ban] action reload
17 - reload service service[fail2ban]
18 * cron[chef-client] action create (up to date)
19 ...
20 Recipe: motd::default
21 ...
22 Chef Client finished, 2 resources updated
27. Konfigurationsmanagement mit Chef 24 / 47
Die Begriffswelt von Chef
Chef-Solo
Es funktioniert aber auch ganz ohne Chef-Server
oder Opscodes Hosted Chef mit Chef-Solo
28. Konfigurationsmanagement mit Chef 25 / 47
Die Begriffswelt von Chef
Knife
Dass Command-Line-Tool Knife ist die Schnittstelle
zum Chef-Server
29. Konfigurationsmanagement mit Chef 26 / 47
Die Begriffswelt von Chef
Knife
Mit Knife lassen sich
Nodes und Clients verwalten
Cookbooks und Rezepte erstellen und hochladen
Rollen definieren und anwenden
Chef auf Nodes installieren und konfigurieren
Attribute anzeigen und suchen
uvm.
30. Konfigurationsmanagement mit Chef 27 / 47
Die Begriffswelt von Chef
Knife
Die Nodes haben Attribute
Diese werden automatisch während jedem Chef-Client-Run
mit dem Tools Ohai aktualisiert.
31. Konfigurationsmanagement mit Chef 28 / 47
Die Begriffswelt von Chef
Knife
Abbildung: Nur ein kleiner Ausschnitt der verfügbaren Attribute
33. Konfigurationsmanagement mit Chef 30 / 47
Die Begriffswelt von Chef
Attribute
1 knife search node ’etc_passwd:alex’ -a etc.passwd.alex.uid
2 10 items found
3
4 ah-mon:
5 etc.passwd.alex.uid: 1001
6
7 us-mon:
8 etc.passwd.alex.uid: 1001
9
10 eduprobe-ae:
11 etc.passwd.alex.uid: 1002
12
13 chefserver:
14 etc.passwd.alex.uid: 1002
15
16 eduprobeh:
17 etc.passwd.alex.uid: 1002
18
19 eduprobe-ar:
20 etc.passwd.alex.uid: 1002
21
22 enc-mon:
23 ...
34. Konfigurationsmanagement mit Chef 30 / 47
Die Begriffswelt von Chef
Attribute
Beispiel
knife ssh -x uname
Username
–attribute ipaddress
uname@ipadress statt uname@fqdn
tags:vsphere
Suchparameter
“sudo chef-client“
Das Kommando sudo chef-client wird auf allen Nodes mit dem Tag vsphere
ausgeführt.
35. Konfigurationsmanagement mit Chef 31 / 47
Die Begriffswelt von Chef
Attribute
Nodes haben eine Runlist.
Rollen oder Rezepte werden hier nacheinander angewandt.
36. Konfigurationsmanagement mit Chef 32 / 47
Die Begriffswelt von Chef
Attribute
1 knife node show eduprobe-ar
2 Node Name: eduprobe-ar
3 Environment: _default
4 FQDN: eduprobe-ar
5 IP: 10.5.71.10
6 Run List: role[eduprobe]
7 Roles: eduprobe
8 Recipes: eduprobe, motd, makeusers, eduprobe::default,
9 logrotate::default, motd::default, makeusers::default
10 Platform: raspbian 7.6
11 Tags: ZIMT, RaspberryPi
38. Konfigurationsmanagement mit Chef 33 / 47
Die Begriffswelt von Chef
Rezept
In den Rezepten werden Ressourcen verwaltet
und definiert.
39. Konfigurationsmanagement mit Chef 34 / 47
Die Begriffswelt von Chef
Rezept
Ausschnitt aus einem Rezept
(später mehr zu Rezepten...)
1 package "wpasupplicant"
2 package "macchanger"
3
4 directory "/home/pi/.ssh/" do
5 owner "pi"
6 group "pi"
7 mode 00700
8 action :create
9 end
10
11 cookbook_file "authorized_keys" do
12 path "/home/pi/.ssh/authorized_keys"
13 owner "pi"
14 group "pi"
15 mode 00600
16 action :create
17 end
18
19 cookbook_file "snmpd.conf" do
20 path "/etc/snmp/snmpd.conf"
21 owner "root"
22 group "root"
23 mode 00644
24 action :create
25 end
26
27 service "snmpd" do
28 supports :status => true, :restart => true, :reload => true
40. Konfigurationsmanagement mit Chef 35 / 47
Die Begriffswelt von Chef
Ressource
Eine Ressource hat
einen Typ
einen Namen
Parameter
sogenannte Actions, die
definieren, wie eine
Änderung durchgeführt
werden soll
19 cookbook_file "snmpd.conf" do
20 path "/etc/snmp/snmpd.conf"
21 owner "root"
22 group "root"
23 mode 00644
24 action :create
25 end
27 service "snmpd" do
28 supports :status => true,
29 :restart => true,
30 :reload => true
31 action :reload
32 end
41. Konfigurationsmanagement mit Chef 36 / 47
Die Begriffswelt von Chef
Provider
Ressourcen führen Änderungen mithilfe von so
genannten Providern durch.
42. Konfigurationsmanagement mit Chef 37 / 47
Die Begriffswelt von Chef
Provider
Ressourcen führen Änderungen mithilfe von so
genannten Providern durch.
43. Konfigurationsmanagement mit Chef 38 / 47
Die Begriffswelt von Chef
Provider
Es kann mehrere Provider pro Ressourcentyp geben
Es kann mehrere Provider pro Resourcentyp geben
Z.B. die Ressource Package:
Apt, Yum, Rubygems, Portage, Macports, FreeBSD Ports,
Pacman, etc.
Kann überschrieben werden mit dem Attribut Provider
1 package "sudo" do
2 provider Chef::Provider::Package::Apt
3 action: install
4 end
44. Konfigurationsmanagement mit Chef 39 / 47
Die Begriffswelt von Chef
Cookbook
Cookbooks sind Pakete für Rezepte und alle
zugehörigen Objekte
45. Konfigurationsmanagement mit Chef 40 / 47
Die Begriffswelt von Chef
Cookbook
Ordnerstruktur eines Cookbooks
attributes
definitions
← Definitions sind Code, der in mehereren
Rezepten verwendet werden kann
files ← Dateien
libraries
providers
recipes ← Rezepte
resources
templates
← Ruby-Templates, um z.B. Textdateien
zu generieren
CHANGELOG.md
metadata.rb ← Maintainer, Beschreibung, Versionsnummer
README.md
46. Konfigurationsmanagement mit Chef 41 / 47
Ein paar unserer Cookbooks
Inhalt
1 Warum eigentlich Konfigurationsmanagment?
2 Welches Konfigurationsmanagmentsystem ist das Beste?
3 Einführung in Opscode Chef
4 Die Begriffswelt von Chef
5 Ein paar unserer Cookbooks
makeusers
debian-default
Die Rolle Monitoring
Eine neue Monitoring-Node anlegen
48. Konfigurationsmanagement mit Chef 43 / 47
Ein paar unserer Cookbooks
makeusers
Das Cookbook makeusers
Legt User incl. Passwort an. assmann, alex, kheimel
erstellt /home/(username) Ordner
Kopiert SSH authorized keys
49. Konfigurationsmanagement mit Chef 43 / 47
Ein paar unserer Cookbooks
makeusers
Das Cookbook makeusers
Legt User incl. Passwort an. assmann, alex, kheimel
erstellt /home/(username) Ordner
Kopiert SSH authorized keys
Löschen von Usern auf allen Maschinen
user "kheimel" do
action :delete
end
50. Konfigurationsmanagement mit Chef 44 / 47
Ein paar unserer Cookbooks
motd
Das Cookbook motd
Linux us -mon 3.14-1- amd64 #1 SMP Debian 3.14.12 -1
(2014 -07 -11) x86_64
_ _ ___ _ __ ___ ___ _ __
| | | / __|_____| ’_ ‘ _ / _ | ’_
| |_| __ _____| | | | | | (_) | | | |
__ ,_|___/ |_| |_| |_|___ /|_| |_|
Interface IP -Addresses
(IPv4)
eth0 10.5.56.20
(IPv6)
eth0 fe80 ::21d:9ff:fe6b :913
eth1 fe80 ::21d:9ff:fe6b :915
System information as of: Thu Sep 4 13:25:53 CEST
2014
System load: 0.00 Memory usage: 3.1%
Usage on /: 12% Swap usage: 0.0%
Local users: 0
51. Konfigurationsmanagement mit Chef 45 / 47
Ein paar unserer Cookbooks
debian-default
Das Cookbook debian-default
check-mk-agent-zimt wird installiert
snmpd
fail2ban
dns, ntp → 141.99.2.2
sources.list → 141.99.2.19
52. Konfigurationsmanagement mit Chef 46 / 47
Ein paar unserer Cookbooks
Die Rolle Monitoring
Die Rolle mon
Besteht aus makeusers, motd, debian-default. Zusätzlich
wahlweise das Cookbook smokeping-client oder smokeping
server
Fünf physikalische Maschinen sind derzeit produktiv
ah-mon
ar-mon
enc-mon
pb-mon
us-mon
53. Konfigurationsmanagement mit Chef 47 / 47
Ein paar unserer Cookbooks
Eine neue Monitoring-Node anlegen
Ein neuer Monitoring-Node wird mit der folgenden Zeile angelegt:
knife bootstrap pb-mon -d debian
Bootstrap-
Template
-N pb-mon
Nodename
-x root
SSH-
Username
-r role[mon]
Runlist