Upload
jan-gehring
View
1.553
Download
3
Embed Size (px)
DESCRIPTION
Vortrag auf den Kieler Linuxtagen 2013
Citation preview
Turnschuh-Administration
● Der unglückliche Umstand, sämtliche Rechner im Netzwerk zu Fuß abklappern zu müssen, um vor Ort administrative Tätigkeiten durchzuführen.
http://www.wikiservice.at
Turnschuh-Administration
● Funktioniert bei wenigen Servern● Kann funktionieren wenn jeder Server
unterschiedlich ist● Skaliert nur durch mehr Mitarbeiter
● Wirklich?● Was ist mit
– ntp
– Benutzer und Gruppen
– ssh
– logrotate
– resolv.conf
– profile
– Apache Security Einstellungen
– ...
Jeder Server ist unterschiedlich
● Mails lesen und beantworten (1-2h)● Mailinglisten verfolgen (1h)● Updates aus der IT Welt (heise, golem, ...)
Zeit ist knapp
● Mails lesen und beantworten (1-2h)● Mailinglisten verfolgen (1h)● Updates aus der IT Welt (1h)
Zeit ist knapp
Infrastruktur als Code
http://jenkins-ci.org/http://travisci.com/
Bild von: https://www.openshift.com
Infrastruktur als Code
http://git-scm.com/
http://mercurial.selenic.com/
http://subversion.tigris.org/
● Das Wissen über die Infrastruktur ist nicht in eurem Kopf sondern in einem Script.
● Wenn ihr mal krank seid kann ein Kollege kucken wie es funktioniert und muss nicht stören.
● Das gilt auch für den Urlaub.● Oder wenn ihr mal die Firma gewechselt habt.
Was bedeutet das?
● Wenn es nur von einem verwendet / upgedatet wird?
● Wenn es nur auf einer Plattform läuft?
Was bringt uns ein Script?
● Dezentrale Versionsverwaltung● Funktioniert auch offline● Schöne Oberflächen
Git – und jeder macht mit
● Dezentrale Versionsverwaltung● Funktioniert auch offline● Schöne Oberflächen● Scripte sind versioniert● Vielleicht machen auch die Entwickler mit● Man lernt dazu
Git – und jeder macht mit
● Unterschiedliche Entwicklungszweige● Für Testsysteme ein Entwicklungszweig
(branch)● Für Livesysteme ein „Production“ Branch
Git – und jeder macht mit
● Standard Aufgaben kann man hier hinterlegen– Testen des Development Branchs
– Automatische Prüfung von Backup/Restore
– Deployment von neuen Software-Releases
– Erstellen von Test-VMs
– …
● Gibt auch eine Android / iPhone App
Jenkins – Ein-Klick Administration
● Keine selbst geschriebenen Scripte– Auf die Arbeit von anderen aufbauen
● Ganz einfaches Perl– Kennt eigentlich jeder
– Lesbar
● Benötigt (fast) nichts auf dem Zielsystem● Kein Agent nötig● Verwendet SSH● Logik läuft auf dem lokalen Rechner
Rex – Remote Execution
● Wird entwickelt seid 2010● Genau für dieses Einsatzgebiet● Bruch der Kompatibilität = Bug● Aktive Community● Professioneller Support verfügbar
Rex – Remote Execution
Bis hier hin Fragen?
Weiter geht’s mit: Rex
● Begrifflichkeiten● Rex Interna● Aus der Praxis
● Installation● 1. Schritte● ...
Infrastruktur als Code
DB Write
DB Read
Middleware
Frontend
Loadbalancer LB01 LB02
FE01 FE03FE02
MW01 MW02
DBS01 DBS02
DBM01
Funktions-Gruppen
LIVE STAGE TEST
Loadbalancer
Frontend
Middleware
DB Read
DB Write
LB01 LB02
FE01 FE03FE02
MW01 MW02
DBS01 DBS02
DBM01
LB01
FE01
MW01
DBS01
DBM01
FE01
MW01
DBM01
environment “live“ => sub { group “frontend“ => “fe01[01..03].live“;};
environment “stage“ => sub { group “frontend“ => “fe01.stage“;};
environment “test“ => sub { group “frontend“ => “fe01.test“;};
Environments
environment “live“ => sub { group “frontend“ => “fe01[01..03].live“;};
environment “stage“ => sub { group “frontend“ => “fe01.stage“;};
environment “test“ => sub { group “frontend“ => “fe01.test“;};
Environments
environment “live“ => sub { group “frontend“ => “fe01[01..03].live“;};
environment “stage“ => sub { group “frontend“ => “fe01.stage“;};
environment “test“ => sub { group “frontend“ => “fe01.test“;};
Environments
Bis hier hin Fragen?
Weiter geht’s mit: Rex
● Begrifflichkeiten● Rex Interna● Aus der Praxis
● Installation● 1. Schritte● ...
Bis hier hin Fragen?
Weiter geht’s mit: Rex
● Begrifflichkeiten● Rex Interna● Aus der Praxis
● Installation● 1. Schritte● ...
echo 'deb http://rex.linux-files.org/ubuntu/ precise rex' >> \ /etc/apt/sources.list
wget -O - \ http://rex.linux-files.org/DPKG-GPG-KEY-REXIFY-REPO \ | apt-key add -
apt-get updateapt-get install rex
Installation / Ubuntu
Installation / CentOS
rpm –import \http://rex.linux-files.org/RPM-GPG-KEY-REXIFY-REPO.CENTOS6
cat >/etc/yum.repos.d/rex.repo <<EOF[rex]name=Fedora \$releasever - \$basearch - Rex Repositorybaseurl=http://rex.linux-files.org/CentOS/\$releasever/rex/\$basearch/enabled=1EOF
yum install rex
Installation / Windows
● Strawberry-Perl (http://strawberryperl.com/)● cmd> cpanm Rex
Bis hier hin Fragen?
Weiter geht’s mit: Rex
● Installation● 1. Schritte● Templates● 1. Modul
● Verzeichnisstruktur● Das Modul● Ein Service
user “root“;password “box“;private_key “/home/jan/.ssh/id_rsa_root“;public_key “/home/jan/.ssh/id_rsa_root.pub“;key_auth;
Das Rexfile
user “root“;password “box“;
group “frontend“ => “fe[01..03]";
task “install_ntpd“, group => “frontend“, make { install “ntpd“;};
Das Rexfile
group “frontend“ => “fe[01..03]";
task “install_ntpd“, group => “frontend“, make { install “ntpd“;
file “/etc/ntp.conf“, source => “files/etc/ntp.conf“, owner => “root“, group => “root“, mode => 644;};
Das Rexfile
group “frontend“ => “fe[01..03]";
task “install_ntpd“, group => “frontend“, make { install “ntpd“;
file “/etc/ntp.conf“, source => “files/etc/ntp.conf“, owner => “root“, group => “root“, mode => 644;
service ntpd => ensure => “started“;};
Das Rexfile
group “frontend“ => “fe[01..03]";
task “install_ntpd“, group => “frontend“, make { install “ntpd“;
file “/etc/ntp.conf“, source => “files/etc/ntp.conf“, owner => “root“, group => “root“, mode => 644, on_change => make { service ntpd => “restart“ };
service ntpd => ensure => “started“;};
Das Rexfile
● Benutzer & Gruppen● Cron● Filesystem Funktionen
– mkdir, rmdir, ls, ln, rm, chown, chgrp, chmod
– is_file, is_dir, mv, cp, mount, umount, ...
● LVM● Kernel● Process-Management● Virtualization (KVM, Xen)● Cloud (Amazon, Jiffybox, OpenNebula, ...)
Mehr Funktionen
Bis hier hin Fragen?
Weiter geht’s mit: Rex
● Installation● 1. Schritte● Templates● 1. Modul
● Verzeichnisstruktur● Das Modul● Ein Service
group “frontend“ => “fe[01..03]";
task “install_ntpd“, group => “frontend“, make { install “ntpd“;
file “/etc/ntp.conf“, source => “files/etc/ntp.conf“, owner => “root“, group => “root“, mode => 644, on_change => make { service ntpd => “restart“ };
service ntpd => ensure => “started“;};
Templates
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstatsfilegen loopstats file loopstats type day enablefilegen peerstats file peerstats type day enablefilegen clockstats file clockstats type day enable
server ntp01.intern.lanserver ntp02.intern.lan
restrict -4 default kod notrap nomodify nopeer noqueryrestrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1restrict ::1
Templates
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstatsfilegen loopstats file loopstats type day enablefilegen peerstats file peerstats type day enablefilegen clockstats file clockstats type day enable
<% for my $server (@{ $servers }) { %>server <%= $server %><% } %>
restrict -4 default kod notrap nomodify nopeer noqueryrestrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1restrict ::1
Templates
group “frontend“ => “fe[01..03]";
my $servers = [“ntp01.company.lan“, “ntp02.company.lan“];
task “install_ntpd“, group => “frontend“, make { install “ntpd“;
file “/etc/ntp.conf“, content => template(“files/etc/ntp.conf.tpl“, servers => $servers), owner => “root“, group => “root“, mode => 644, on_change => make { service ntpd => “restart“ };
service ntpd => ensure => “started“;};
Templates
Bis hier hin Fragen?
Weiter geht’s mit: Rex
● 1. Schritte● Templates● 1. Modul
● Verzeichnisstruktur● Das Modul● Ein Service
> cat lib/NTP/meta.yml Name: NTPDescription: {{ DESCRIPTION }}Author: {{ your name <[email protected]> }}License: {{ THE LICENSE }}
# If you have dependencies to other Rex Modules.Require: - Other::Rex::Module - 2nd::Rex::Module
Verzeichnisstruktur
Bis hier hin Fragen?
Weiter geht’s mit: Rex
● 1. Schritte● Templates● 1. Modul
● Verzeichnisstruktur● Das Modul● Ein Service
group “frontend“ => “fe[01..03]";
my $servers = [“ntp01.company.lan“, “ntp02.company.lan“];
task “install_ntpd“, group => “frontend“, make { install “ntpd“;
file “/etc/ntp.conf“, content => template(“files/etc/ntp.conf.tpl“, servers => $servers), owner => “root“, group => “root“, mode => 644, on_change => make { service ntpd => “restart“ };
service ntpd => ensure => “started“;};
Das Modul
group “frontend“ => “fe[01..03]";
my $servers = [“ntp01.company.lan“, “ntp02.company.lan“];
task “install_ntpd“, group => “frontend“, make { install “ntpd“;
file “/etc/ntp.conf“, content => template(“files/etc/ntp.conf.tpl“, servers => $servers), owner => “root“, group => “root“, mode => 644, on_change => make { service ntpd => “restart“ };
service ntpd => ensure => “started“;};
Das Modul
package Common::NTP;
use Rex -base;
task example => sub { my $output = run "uptime"; say $output;};
1;
Das Modul
package Common::NTP;
use Rex -base;
task “setup“ => make { my $params = shift;
install “ntpd“;
file “/etc/ntp.conf“, content => template(“files/etc/ntp.conf.tpl“, %{ $params }), owner => “root“, group => “root“, mode => 644, on_change => make { service ntpd => “restart“ };
service ntpd => ensure => “started“;};
1;
Das Modul
├── lib│ └── NTP│ ├── files│ │ └── etc│ │ └── ntp.conf.tpl│ ├── meta.yml│ └── __module__.pm└── Rexfile
Das Modul
├── files│ └── etc│ └── ntp.conf.tpl├── lib│ └── NTP│ ├── files│ │ └── etc│ │ └── ntp.conf.tpl│ ├── meta.yml│ └── __module__.pm└── Rexfile
Das Modul
├── files│ └── etc│ └── ntp.conf.tpl├── lib│ └── NTP│ ├── files│ │ └── etc│ │ └── ntp.conf.tpl│ ├── meta.yml│ └── __module__.pm└── Rexfile
Das Modul
├── files│ └── etc│ └── ntp.conf.tpl├── lib│ └── NTP│ ├── files│ │ └── etc│ │ └── ntp.conf.tpl│ ├── meta.yml│ └── __module__.pm└── Rexfile
Das Modul
include “NTP“;
group “frontend“ => “fe[01..03]";
my $servers = [“ntp01.company.lan“, “ntp02.company.lan“];
task “prepare“, group => “frontend“, make { NTP::setup(servers => $servers);};
Das Modul / der Service
include “NTP“;
group “frontend“ => “fe[01..03]";
my $servers = [“ntp01.company.lan“, “ntp02.company.lan“];
task “prepare“, group => “frontend“, make { NTP::setup(servers => $servers);};
Das Modul / der Service
Vielen Dank für Eure Aufmerksamkeit!
Kontakt
Jan GehringSystems Architecture
inovex GmbHOffice PforzheimKarlsruhe Straße 7175179 Pforzheim
+49 (0)173 3181 [email protected]