<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.2.2">Jekyll</generator><link href="https://www.brunsch.me/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.brunsch.me/" rel="alternate" type="text/html" /><updated>2023-10-10T10:15:19+00:00</updated><id>https://www.brunsch.me/feed.xml</id><title type="html">Personal Blog</title><subtitle>&lt;b&gt;Architect&lt;/b&gt; - &lt;b&gt;Automation&lt;/b&gt; - &lt;b&gt;Security&lt;/b&gt; - &lt;b&gt;DevOps&lt;/b&gt; 
</subtitle><author><name>Markus Brunsch</name></author><entry><title type="html">ASN Based DNS Routing</title><link href="https://www.brunsch.me/geodns" rel="alternate" type="text/html" title="ASN Based DNS Routing" /><published>2022-05-26T00:00:00+00:00</published><updated>2022-05-26T00:00:00+00:00</updated><id>https://www.brunsch.me/geodns</id><content type="html" xml:base="https://www.brunsch.me/geodns">&lt;h1 id=&quot;dns-basiertes-routing&quot;&gt;DNS Basiertes Routing&lt;/h1&gt;
&lt;p&gt;Um seine Services und Dienste Carrier und ISP übergreifend mit der best möglichen Performance dem Endkunden anzubieten.
Ist es unerlässlich, seine Server netzwerktechnisch so nah wie möglich an den Kunden heranzubringen.&lt;/p&gt;

&lt;p&gt;Um trotz der vielen verteilten Knoten einen Zentralen anlaufpunkt zu behalten ist hier der Einsatz von DNS unerlässlich.
Um nun herauszufinden, welcher Knoten dem Kunden am nächsten Gelegen ist, entscheidet der DNS Server beim Eingang einer DNS Anfrage aufgrund der Source IP.
Anhand der IP-Adresse lassen sich Informationen wie Netzbetreiber, das Land und die ungefähre Lokation herausfinden.&lt;/p&gt;

&lt;p&gt;Mithilfe diese Kriterien lassen sich Regeln definieren die als Entscheidungsgrundlage für die DNS Antwort dienen.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/asn_geodns.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;konfiguration&quot;&gt;Konfiguration&lt;/h2&gt;

&lt;p&gt;Als DNS Server für diesen Aufbau dient der OpenSource &lt;a href=&quot;https://github.com/abh/geodns&quot;&gt;GeoDNS&lt;/a&gt; Server.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Dieser DNS Server wird auf vom NTP Pool Projekt, für das Load Balancing der NTP Anfragen verwendet.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Für die Installation muss das Repository eingebunden werden:&lt;/p&gt;
&lt;div class=&quot;language-ini highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;err&quot;&gt;deb&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;[trusted=yes]&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;https://repo.fury.io/ntppool/&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Danach kann der GeoDNS Server installiert werden:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apt update &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;geodns
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Im Anschluss kann der GeoDNS Server konfiguriert werden. Die nötigen Konfigurationsdateien müssen manuell angelegt werden:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; /etc/geodns
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Die Konfigurationsdatei mit dem Standardinhalt unter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/geodns/geodns.conf&lt;/code&gt; Anlegen.&lt;/p&gt;

&lt;div class=&quot;language-ini highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;; GeoDNS configuration file
;
; It is recommended to distribute the configuration file globally
; with your .json zone files.
&lt;/span&gt;
&lt;span class=&quot;nn&quot;&gt;[geoip]&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;;; Directory containing the GeoIP2 .mmdb database files; defaults
;; to looking through a list of common directories looking for one
;; of those that exists.
;directory=/usr/local/share/GeoIP/
&lt;/span&gt;
&lt;span class=&quot;nn&quot;&gt;[querylog]&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;;; directory to save query logs; disabled if not specified
&lt;/span&gt;&lt;span class=&quot;py&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;log/queries.log&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;;; max size per file in megabytes before rotating (default 200)
; maxsize = 100
;; keep up to this many rotated log files (default 1)
; keep = 2
&lt;/span&gt;
&lt;span class=&quot;nn&quot;&gt;[http]&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;; require basic HTTP authentication; not encrypted or safe over the public internet
; user = stats
; password = Aeteereun8eoth4
&lt;/span&gt;
&lt;span class=&quot;nn&quot;&gt;[health]&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;; directory = dns/health
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;geoip-datenbanken&quot;&gt;GeoIP Datenbanken&lt;/h3&gt;
&lt;p&gt;Um die eingehenden Source IPs nach Herkunft usw. klassifizieren werden die Datenbanken mit den entsprechenden Informationen benötigt.&lt;/p&gt;

&lt;p&gt;Diese können hier heruntergeladen werden.
&lt;a href=&quot;https://github.com/P3TERX/GeoLite.mmdb/&quot;&gt;https://github.com/P3TERX/GeoLite.mmdb/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Und entsprechend im Ordner &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/local/share/GeoIP/&lt;/code&gt; gespeichert werden.&lt;/p&gt;

&lt;h2 id=&quot;dns-zonen-konfiguration&quot;&gt;DNS Zonen Konfiguration&lt;/h2&gt;
&lt;p&gt;Um eine Trennung nach ASN Nummern durchzuführen, muss die Zonen Datei wie folgt aufgebaut werden.&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;serial&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;ttl&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;max_hosts&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;logging&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{},&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;targeting&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;country continent @ regiongroup region ip asn&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;contact&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;abuse@example.net&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;data&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;ns&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ns1.example.net&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;ns2.example.net&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;www.as3320&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;cname&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;www.fsn1.example.net.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;ttl&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;www&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;cname&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;www.stg.example.net.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;ttl&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;600&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Im obrigen Zonen File bekommen alle Anfragen aus dem DTAG (Deutsche Telekom AG) Netz die CNAME Adresse &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;www.fsn1.example.net&lt;/code&gt; als Antwort zurück.&lt;/p&gt;

&lt;p&gt;Alle übrigen Anfragen aus anderen Netzwerken bekommen die Adresse &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;www.stg.example.net&lt;/code&gt; als Antwort zurück.&lt;/p&gt;

&lt;h2 id=&quot;dns-abstraktion&quot;&gt;DNS Abstraktion&lt;/h2&gt;
&lt;p&gt;Da DNS ein sehr kritischer Dienst ist und durch eine mögliche CMANE Verkettung bei einem Ausfall auch noch andere Services oder Systeme lahnlegen kann.
Empfiehlt es sich hier dem GeoDNS Server nur eine Subdomain zur Verwaltung zu delegierten und nicht gleich die ganze root Domainebene &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Um dem GeoDNS Server eine Subdomain zu delegierten muss im haupt DNS ein &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NS&lt;/code&gt; Record hinzugeführt werden.&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;geodns.example.net.	1	IN	NS	ns1.example.net.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In diesem Record wird die Subdomain &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*.geodns.example.net&lt;/code&gt; ab sofort vom DNS Server &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ns1.example.net&lt;/code&gt; verwaltet.
Somit werden alle DNS Anfragen wie z.B. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;srv1.geodns.example.net&lt;/code&gt; an den Nameserver &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ns1.example.net&lt;/code&gt; weitergeleitet.&lt;/p&gt;

&lt;p&gt;Bei diesem Setup wären durch einen eventuellen Ausfall des NS1 Nameservers nur die &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;geodns&lt;/code&gt; Subdomain betroffen.&lt;/p&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">DNS Basiertes Routing Um seine Services und Dienste Carrier und ISP übergreifend mit der best möglichen Performance dem Endkunden anzubieten. Ist es unerlässlich, seine Server netzwerktechnisch so nah wie möglich an den Kunden heranzubringen.</summary></entry><entry><title type="html">SQL Transactions</title><link href="https://www.brunsch.me/sql-transactions" rel="alternate" type="text/html" title="SQL Transactions" /><published>2022-04-16T00:00:00+00:00</published><updated>2022-04-16T00:00:00+00:00</updated><id>https://www.brunsch.me/sql-transactions</id><content type="html" xml:base="https://www.brunsch.me/sql-transactions">&lt;h1 id=&quot;sql-transaktionen&quot;&gt;SQL Transaktionen&lt;/h1&gt;
&lt;p&gt;SQL Transaktionen bilden einen Verbund aus mehreren SQL-Statements, die in direktem Zusammenhang stehen.
Beispielsweise bei einer Bestellung hier wäre es von Nöten, Einträge in der Tabelle, Bestellungen und Produkte zu erstellen.&lt;/p&gt;

&lt;p&gt;Da dies in separaten SQL Statements passiert, diese aber direkt voneinander abhängig sind, könnte es durch einen
Fehler in einen der SQL-Statements zu einem inkonsistenten Zustand der Datenbank kommen.&lt;/p&gt;

&lt;p&gt;Um dies zu verhindern, werden Transaktionen eingeführt. In Transaktionen werden mehrere voneinander anhängige SQL Statements zusammengefasst.
Sollte die Ausführung eines Statements in einer Transaktion fehlschlagen, werden alle bis dahin durchgeführten Änderungen auf der Datenbank
rückgängig gemacht. Somit wird verhindert, dass es hier zu einem inkonsistenten Zustand in der Datenbank kommen kann.&lt;/p&gt;

&lt;p&gt;Transaktionen sind nach dem &lt;strong&gt;ACID&lt;/strong&gt;-Prinzip aufgebaut.
Dies bedeutet, sie besitzen &lt;strong&gt;Atomarität&lt;/strong&gt;, sollte die Transaktion abgebrochen werden, hinterlässt diese keine Änderungen auf dem System.
Transaktionen sind &lt;strong&gt;konsistent&lt;/strong&gt; nach dem Commit oder Rollback ist die Datenbank in einem Konsistenten zustand ohne Anomalien oder Redundanzen.
Transaktionen sind voneinander &lt;strong&gt;isoliert&lt;/strong&gt;, sie können sich gegenseitig nicht beeinflussen.
Transaktionen sind &lt;strong&gt;dauerhaft&lt;/strong&gt;, sie speichern Daten nach erfolgreicher Ausführung persistent ab.&lt;/p&gt;

&lt;h2 id=&quot;aufbau-einer-transaktion&quot;&gt;Aufbau einer Transaktion&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Start der Transaktion
    &lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &lt;span class=&quot;k&quot;&gt;START&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TRANSACTION&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Ausführen der SQL Statements
    &lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt;
     &lt;span class=&quot;n&quot;&gt;CompanyName&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; 
     &lt;span class=&quot;n&quot;&gt;products&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;suppliers&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; 
     &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SupplierID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SupplierID&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt; 
     &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ProductID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Abschliesen der Transaktion
    &lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &lt;span class=&quot;k&quot;&gt;COMMIT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;rollback&quot;&gt;Rollback&lt;/h2&gt;
&lt;p&gt;Durch einen Rollback, werden die Änderungen, die in der Transaktion ausgeführt wurden, rückgängig gemacht.&lt;/p&gt;

&lt;p&gt;Dies bedeutet, dass die Änderungen, die in einer Transaktion ausgeführt werden, bis zum &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COMMIT&lt;/code&gt; oder &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ROLLBACK&lt;/code&gt; nur in der aktuellen Session bestehen und keine persistenten Auswirkungen auf die Daten haben.&lt;/p&gt;

&lt;p&gt;Zum Rollback wird anstatt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COMMIT&lt;/code&gt; das &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ROLLBACK&lt;/code&gt; Statement ausgeführt.&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;ROLLBACK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;savepoints&quot;&gt;Savepoints&lt;/h3&gt;
&lt;p&gt;Sogenannte Savepoints sind Zwischenergebnisse in einer Transaktion.
Sie legen fest, bis wohin bei einem Rollback Änderungen zurückgesetzt werden sollen.&lt;/p&gt;

&lt;p&gt;Um einen Savepoint anzulegen, genügt es innerhalb einer Transaktion den Befehl und einen Namen für den Savepoint abzusetzen.&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;SAVEPOINT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xyz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Um zu einem solchen Savepoint zurückzuspringen, muss das Rollback Statement mit dem Zusatz des Savepointnamens aufgerufen werden.&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;ROLLBACK&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;xyz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Java JDBC Implementierung&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;executeTransaction&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Connection&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/*
     Create SQL Statement
    */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;Statement&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stmt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;createStatement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setAutoCommit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;stmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;executeUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;INSERT INTO categories(CategoryID, CategoryName, Description) VALUES(3, 'Sweets', 'Desserts and candies')&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;cm&quot;&gt;/*
            Create Savepoint
        */&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;Savepoint&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;save&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setSavepoint&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;stmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;executeUpdate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;INSERT INTO products(ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued) VALUES('Lakritz', 14, 3, 10, 1.2, 100, 0, 10, 0)&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;cm&quot;&gt;/*
            Rollback Changes to Savepoint
        */&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;rollback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;save&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;cm&quot;&gt;/*
            Commit Changes
        */&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;commit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Transaction succeeded.&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SQLException&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;printStackTrace&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nc&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Transaction failed.&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;con&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;rollback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nc&quot;&gt;SQLException&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;se&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;se&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;printStackTrace&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Pure SQL Implementierung&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;START&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TRANSACTION&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;AUTOCOMMIT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;OFF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; 
    &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;categoryID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;MAX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CategoryID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;categories&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;categories&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CategoryID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CategoryName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Description&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;VALUES&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;categoryID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Sweets'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Desserts and candies'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;SAVEPOINT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s_category&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;products&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ProductName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SupplierID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CategoryID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;QuantityPerUnit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UnitPrice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UnitsInStock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UnitsOnOrder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ReorderLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Discontinued&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;VALUES&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Lakritz'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;COMMIT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;optionen&quot;&gt;Optionen&lt;/h2&gt;

&lt;p&gt;Die bei MySQL als Standard gesetzte Option &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AUTOCOMMIT&lt;/code&gt; speichert nach erfolgreicher Ausführung der Transaktion die Daten in der Datenbank persistent ab.&lt;/p&gt;

&lt;p&gt;Um dies abzuschalten, muss in einer Transaktion das folgende Statement enthalten sein, damit wird es nötig, das speichern der Daten manuell zu veranlassen.&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;AUTOCOMMIT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;OFF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;isolations-level&quot;&gt;Isolations Level&lt;/h2&gt;
&lt;p&gt;Das Isolationslevel hat keine Auswirkung auf die Sperrung der Datenbank, die durch die eigene Transaktion verursacht wurde.
Vielmehr legt es das Verhalten fest, wie auf andere laufende Transaktionen reagiert werden soll.&lt;/p&gt;

&lt;p&gt;So ist z. B. bei dem Isolationslevel &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;READ UNCOMMITTED&lt;/code&gt; ganz egal, ob die von einer anderen Transaktion gerade bearbeitete Tabelle noch nicht vollständig beschrieben ist. So wird die Transaktion dennoch ausgeführt es kann hier unter Umständen zu Inkonsistenten kommen.
Dies wird auch als &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dirty read&lt;/code&gt; bezeichnet.&lt;/p&gt;

&lt;p&gt;Im Gegenzug werden aber nicht viele Systemressourcen benötigt, da weder ein Lock noch eine revisionssichere Verarbeitung nötig ist.&lt;/p&gt;

&lt;p&gt;Dieses Isolationslevel sollte daher nicht eingesetzt werden, höchstens bei Daten, deren Konsistenz keine Priorität haben.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;READ COMMITTED&lt;/code&gt; gibt, an das nur Daten verarbeitet werden können, die momentan nicht von anderen Transaktionen verwendet werden.
Dabei versucht die Datenbank nur so wenig Entitäten wie nötig zu sperren.&lt;/p&gt;

&lt;p&gt;Dies geschieht mit einer Mischung aus Index und Row Locks. Hintergrund ist, dass es ansonsten zu Phantom Einträgen in der Datenbank können könnte. Beider neue Datensätze zwischen den in der Transaktion angefragten Datensätze eingeschleust werden könnten.
Somit wären dann in zwei zeitlich voneinander getrennten SELECT Statements jeweils zwei unterschiedliche Datensätze zurückgegeben worden.&lt;/p&gt;

&lt;p&gt;Bei &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UPDATE&lt;/code&gt; und &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DELETE&lt;/code&gt; Statements werden die Locks auf die Datenbank durch die parallele Auswertung der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WHERE&lt;/code&gt; Klausel neben der Ausführung des Queries reduziert indem nicht zu bearbeitende Entitäten werden wieder freigegeben.
Dies hat den Hintergrund, die Wahrscheinlichkeit von Deadlocks zu verringern.&lt;/p&gt;

&lt;p&gt;Deadlocks treten auf, wenn zwei Transaktionen auf den Abschluss der jeweils anderen Transaktion warten. Da dies aber nicht eintreten wird, da sich die beiden Transaktionen gegenseitig sperren, spricht man in diesem Zusammenhang von einem Deadlock.&lt;/p&gt;

&lt;p&gt;Bei &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;REPEATABLE READ&lt;/code&gt; werden nur die Datensätze gesperrt, die durch eine eindeutige Suche dem Statement zugeordnet werden können.&lt;/p&gt;

&lt;p&gt;Bei der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SERIALIZABLE&lt;/code&gt; Isolationsstufe können keine Daten gelesen werden, für die noch ein Commit Statement aussteht, auch können andere Transaktionen erst auf die Daten zugreifen, wenn die aktuelle Transaktion vollständig abgeschlossen ist.&lt;/p&gt;

&lt;p&gt;Eine Übersicht der einzelnen Isolationsstufen und deren Eigenschaften:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Isolationsstufe&lt;/th&gt;
      &lt;th&gt;Dirty Read&lt;/th&gt;
      &lt;th&gt;Non-Repeatable Read&lt;/th&gt;
      &lt;th&gt;Phantom&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Read Uncommitted&lt;/td&gt;
      &lt;td&gt;Ja&lt;/td&gt;
      &lt;td&gt;Ja&lt;/td&gt;
      &lt;td&gt;Ja&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Read Committed&lt;/td&gt;
      &lt;td&gt;Nein&lt;/td&gt;
      &lt;td&gt;Ja&lt;/td&gt;
      &lt;td&gt;Ja&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Repeatable Read&lt;/td&gt;
      &lt;td&gt;Nein&lt;/td&gt;
      &lt;td&gt;Nein&lt;/td&gt;
      &lt;td&gt;Ja&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Serializable&lt;/td&gt;
      &lt;td&gt;Nein&lt;/td&gt;
      &lt;td&gt;Nein&lt;/td&gt;
      &lt;td&gt;Nein&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">SQL Transaktionen SQL Transaktionen bilden einen Verbund aus mehreren SQL-Statements, die in direktem Zusammenhang stehen. Beispielsweise bei einer Bestellung hier wäre es von Nöten, Einträge in der Tabelle, Bestellungen und Produkte zu erstellen.</summary></entry><entry><title type="html">Einführung Docker</title><link href="https://www.brunsch.me/docker-introduction" rel="alternate" type="text/html" title="Einführung Docker" /><published>2022-04-11T00:00:00+00:00</published><updated>2022-04-11T00:00:00+00:00</updated><id>https://www.brunsch.me/docker-introduction</id><content type="html" xml:base="https://www.brunsch.me/docker-introduction">&lt;h1 id=&quot;docker-container-plattform&quot;&gt;Docker Container Plattform&lt;/h1&gt;
&lt;p&gt;Docker ist ein Open Source-Projekt zur Automatisierung der Bereitstellung von Apps als mobile, eigenständige Container, die in der Cloud oder lokal ausgeführt werden können. Docker ist darüber hinaus ein Unternehmen, das diese Technologie fördert und weiterentwickelt und mit Cloud-Anbietern, Linux und Windows kompatibel ist.&lt;/p&gt;

&lt;p&gt;Dabei stellen Container eigenständige und abgeschottete Laufzeitumgebungen für Anwendungen verschiedenster Art dar.
Container und die dazugehörigen Container Images basieren auf dem OCI (Open Container Initiative) Standard und sind somit nicht nur mit Docker kompatiebel.
Docker ist vielmehr nur das zugehörige Verwaltungswerkzeug, um die darunterliegende Container Infrastruktur zu verwalten.
Docker bietet dabei die Möglichkeiten, Container anzulegen, zu starten / stoppen oder zu löschen. Es können neue Images erstellt und bestehende Images verwaltet werden, lokal oder remote in sogenannten Container Registries (z.B. hub.docker.com)&lt;/p&gt;

&lt;h2 id=&quot;containervirtualisierung&quot;&gt;Containervirtualisierung&lt;/h2&gt;
&lt;p&gt;Containervirtualisierung beschriebt eine Form der Virtualisierung beider auf dem Host System mittels PID Namespacing im Linux-Kernel eine eigene Laufzeitumgebung geschaffen wird. Inder Anwendungen abgeschottet vom restlichen System betrieben werden können.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/BackInBash/Technikerschule/master/Jahr%202/CS/pid.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Der Vorteil dieser Virtualisierungesmethode, ist der um ein Vielfaches verringerter Overhead im Vergleich zu KVM.
Da bei einer Container Virtualisierung im direkten Vergleich der Kernel des Host OS verwendet wird und die Ressourcen des Systems nur abstrahiert und nicht virtualisiert werden.&lt;/p&gt;

&lt;p&gt;Somit kann bei Containern auf ein eigenes Betriebssystem im klassischen Sinne verzichtet werden.
Es muss lediglich eine Laufzeitumgebung mitgegeben werden, um die entsprechende Anwendung ausführen zu können.
Somit kann die Hardware optimal ausgenutzt und der Wartungsaufwand deutlich reduziert werden.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/BackInBash/Technikerschule/master/Jahr%202/CS/container.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Technologien, die auf diese Art der Virtualisierung zurückgreifen, sind. &lt;strong&gt;LXC&lt;/strong&gt; und &lt;strong&gt;OCI&lt;/strong&gt; Container.&lt;/p&gt;

&lt;p&gt;Bei &lt;strong&gt;LXC&lt;/strong&gt; Containern wird ein leichtgewichtiges Linuxsystem erzeugt, das über traditionelle Methoden administriert / verwaltet wird z.B. SSH.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OCI&lt;/strong&gt; Container verfolgen einen anderen Weg, hier geht es darum, sehr leichtgewichtige System für die Cloud bereitzustellen. Hier liegt der Fokus auf Sicherheit, Performance und Fehlerminimierung.&lt;/p&gt;

&lt;p&gt;Die Container sind weitergehend dazu auch im Hinblick auf die &lt;a href=&quot;https://12factor.net&quot;&gt;12 Faktoren&lt;/a&gt; im Cloudumfeld designet, sie sind vorzugsweise Stateless, skalierbar und im Fehlerfall schnell austauschbar. Eine manuelle Fehlerbehebung eines einzelnen “bad” Containers ist hier nicht vorgesehen. Vielmehr werden die Container einfach schnell gegen einen neuen funktionsfähigen Container ausgetauscht.&lt;/p&gt;

&lt;p&gt;Gerade im Hinblick auf Kubernetes, ist diese Art der Containerverwaltung die Grundlage eines solchen Konzepts.&lt;/p&gt;

&lt;h2 id=&quot;moby-project&quot;&gt;Moby Project&lt;/h2&gt;
&lt;p&gt;Das Moby Projekt zu finden auf &lt;a href=&quot;https://github.com/moby/moby&quot;&gt;Github&lt;/a&gt;, stellt die Library dar, die von Docker für die Interaktion mit dem System verwendet wird. Hier ist z.B. der Image Build Prozess abgebildet.&lt;/p&gt;

&lt;h2 id=&quot;containerd&quot;&gt;ContainerD&lt;/h2&gt;
&lt;p&gt;ContainerD ist eine OCI standardisierte Container Laufzeitumgebung. Diese ist für den eigentlichen Betrieb der Container verantwortlich und steuert diesen eigenständig.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;containerd is an industry-standard container runtime with an emphasis on simplicity, robustness and portability. It is available as a daemon for Linux and Windows, which can manage the complete container lifecycle of its host system: image transfer and storage, container execution and supervision, low-level storage and network attachments, etc.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Zu finden ist das Projekt bei &lt;a href=&quot;https://github.com/containerd/containerd&quot;&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/BackInBash/Technikerschule/master/Jahr%202/CS/containerd.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;oci---open-container-initiative&quot;&gt;OCI - Open Container Initiative&lt;/h2&gt;
&lt;p&gt;Die Open Container Initiative verabschiedet Standards im Bereich Containering.
Darunter fallen die Spezifikationen der Container und deren Images, damit diese zu den verschiedenen Systemen interkompatibel sind.&lt;/p&gt;

&lt;h2 id=&quot;runc&quot;&gt;runc&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;runc&lt;/code&gt; is a CLI tool for spawning and running containers on Linux according to the OCI specification.
Wird von Docker im Hintergrund verwendet, um Container anzulegen und zu verwalten.
Zu finden auf &lt;a href=&quot;https://github.com/opencontainers/runc&quot;&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;docker-image-erstellen&quot;&gt;Docker Image Erstellen&lt;/h2&gt;
&lt;p&gt;Um ein Docker Image zu erstellen, wird mit sogenannten Dockerfiles das Image definiert.
Dieses Dockerfile wird dann dem Build Agent übergeben,
der dann aus dem übergebenen Dockerfile ein OCI Container Image erstellt.&lt;/p&gt;

&lt;p&gt;In der Regel sind Dockerfiles in 3 Bereiche aufgeteilt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Import&lt;/strong&gt;:
Hier werden OS Images (Debian, Alpine, Ubuntu, …) angegeben bzw. Base Images (Frameworks wie Java, dotNet, NodeJS oder Python) damit wird die
Laufzeitumgebung festgelegt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;:
Hier wird die Installationsroutine der Software angegeben z.B. Download von Artefakten oder Kompilierung der Software.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entrypoint&lt;/strong&gt;:
Hier wird der Startpunkt der Anwendung festgelegt.&lt;/p&gt;

&lt;p&gt;Ein beispielhaftes Dockerfile sieht in etwa so aus:&lt;/p&gt;
&lt;div class=&quot;language-docker highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; alpine:3.4&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;RUN &lt;/span&gt;apk update &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; apk add &lt;span class=&quot;se&quot;&gt;\
&lt;/span&gt;    curl &lt;span class=&quot;se&quot;&gt;\
&lt;/span&gt;    git &lt;span class=&quot;se&quot;&gt;\
&lt;/span&gt;    vim

&lt;span class=&quot;k&quot;&gt;RUN &lt;/span&gt;wget http://myapp.com/run &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;chmod&lt;/span&gt; +x run

&lt;span class=&quot;k&quot;&gt;ENTRYPOINT&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;['run']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Im Anschluss kann dann das Dockerfile zu einem Image gebaut werden &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker build .&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;docker-image-verwaltung&quot;&gt;Docker Image Verwaltung&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Anzeigen der lokal geladenen Images&lt;/p&gt;

    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;root@host ~]&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker image &lt;span class=&quot;nb&quot;&gt;ls
  &lt;/span&gt;REPOSITORY                   TAG       IMAGE ID       CREATED         SIZE
  ngoduykhanh/powerdns-admin   latest    938d8ef921ab   5 months ago    157MB
  psitrax/powerdns             latest    720c44942097   6 months ago    63.7MB
  redis                        latest    08502081bff6   6 months ago    105MB
  mariadb                      latest    104f4e7cbe83   6 months ago    408MB
  ubuntu                       latest    7e0aa2d69a15   8 months ago    72.7MB
  freinet/powerdns             latest    8fdce2cafa4e   12 months ago   55.5MB
  jorgedlcruz/zimbra           latest    79403a039239   4 years ago     302MB
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Löschen eines Images&lt;/p&gt;

    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;root@host ~]&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker image &lt;span class=&quot;nb&quot;&gt;rm &lt;/span&gt;79403a039239
  Untagged: jorgedlcruz/zimbra:latest
  Untagged: jorgedlcruz/zimbra@sha256:5d2548365fd079ba51e87c7a8f54feacfce23d370f49d66311632eb2a422b026
  Deleted: sha256:79403a039239add5f60084f7ff2203fe145b3f8f86e83a925359e06e38cb437f
  Deleted: sha256:c07d6c55520b0908e868f8a85d2b8928616008a8c26d27bd61f425ce1a2058c6
  Deleted: sha256:e2a75e141e320208ce68299d7f72e1fe46a1c9b8a5702256ea45ef94ae80cca0
  Deleted: sha256:1f0250b6692ee176c5e1978ee2aa921d724873b9c5fa8ec19be04c640660393d
  Deleted: sha256:7f6e10c2ecea8d277d1a8c7c618e7dd93e5e0357e68d6e88f1f1ab26de03e59a
  Deleted: sha256:ec1fd849ff0a8f0aa2fd1acc29ad5dabbc79b89f63b74a4f54e31a7b0a100aa1
  Deleted: sha256:e3f6dffa20cf36460d23bfb22e17be6e5339891f8537f32db79887caf832048b
  Deleted: sha256:c213ffdc9f7032702de5a8e9045fcce2353b7221ef6bf4509e02005cfc858f58
  Deleted: sha256:3fddf55a451aa43707518f2d8788c12ee5eb1f1e3075433f5bcf4d445d5c275d
  Deleted: sha256:0f5ff0cf6a1c53f94b15f03536c490040f233bc455f1232f54cc8eb344a3a368
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Herunterladen eines neuen Images&lt;/p&gt;

    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;root@host ~]&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker pull alpine:latest
  latest: Pulling from library/alpine
  59bf1c3509f3: Pull &lt;span class=&quot;nb&quot;&gt;complete 
  &lt;/span&gt;Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
  Status: Downloaded newer image &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;alpine:latest
  docker.io/library/alpine:latest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;docker-container-verwaltung&quot;&gt;Docker Container Verwaltung&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Auflistung der Container in auf dem System&lt;/p&gt;

    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;root@host ~]&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker container &lt;span class=&quot;nb&quot;&gt;ls&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-a&lt;/span&gt;
  CONTAINER ID   IMAGE                               COMMAND                  CREATED        STATUS                      PORTS      NAMES
  5793bbed585b   mariadb:latest                      &lt;span class=&quot;s2&quot;&gt;&quot;docker-entrypoint.s…&quot;&lt;/span&gt;   28 hours ago   Exited &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 21 hours ago                elastic_agnesi
  13102f675ad0   mariadb:latest                      &lt;span class=&quot;s2&quot;&gt;&quot;docker-entrypoint.s…&quot;&lt;/span&gt;   3 months ago   Up 2 hours                  3306/tcp   docker-db-1
  0e98170a7024   ngoduykhanh/powerdns-admin:latest   &lt;span class=&quot;s2&quot;&gt;&quot;entrypoint.sh gunic…&quot;&lt;/span&gt;   3 months ago   Exited &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 3 months ago                powerdns_admin
  a0f8b16bc64a   psitrax/powerdns:latest             &lt;span class=&quot;s2&quot;&gt;&quot;/entrypoint.sh&quot;&lt;/span&gt;         3 months ago   Exited &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;143&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 3 months ago              powerdns
  cc6847b3c8a9   ubuntu                              &lt;span class=&quot;s2&quot;&gt;&quot;bash&quot;&lt;/span&gt;                   6 months ago   Exited &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 6 months ago                recursing_mendeleev
  7fc041db6bc6   redis:latest                        &lt;span class=&quot;s2&quot;&gt;&quot;docker-entrypoint.s…&quot;&lt;/span&gt;   6 months ago   Exited &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 6 months ago                lucid_kepler
  be47035dd9d3   mariadb:latest                      &lt;span class=&quot;s2&quot;&gt;&quot;docker-entrypoint.s…&quot;&lt;/span&gt;   6 months ago   Exited &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 2 months ago                mariadb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Mit dem &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-a&lt;/code&gt; Parameter lassen sich auch die abgeschalteten Container anzeigen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;Starten neuer Container&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Im Beispiel: Startet einen Nginx Container auf Port &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;8080&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;docker run &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; 8080:80/tcp &lt;span class=&quot;nt&quot;&gt;--name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;webserver &lt;span class=&quot;nt&quot;&gt;--restart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;always nginx:latest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Die verwendeten Parameter
Parameter | Funktion |
——– | ——– | 
-d | Container im Hintergrund Starten
-p 8080:80/tcp | TCP Portfreigabe von 8080 extern nach 80 intern
–name | Namen des Containers festlegen
–restart=always | Setzt die Restart Policy auf immer starten&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Genauere Infos und Referenzen in der &lt;a href=&quot;https://docs.docker.com/engine/reference/run/&quot;&gt;Docker Dokumentation&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Löschen eines Containers&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;docker container &lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; 5793bbed585b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Container ID oder Container Name&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Verwendeter Paramerter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-f&lt;/code&gt; (Force) Löscht den Container auch im aktiven Zustand.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Vorhandenen Container Starten / Stoppen / Neustarten&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Starten
        &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  docker container start &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ContainerID]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;Stoppen
        &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  docker container stop &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ContainerID]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;Neustarten
        &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  docker container restart &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ContainerID]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;        &lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;docker-compose&quot;&gt;Docker Compose&lt;/h2&gt;
&lt;p&gt;Docker Compose ermöglicht es, mehrere Container in einem Deployment zusammenzufassen und die Ressource in diesem Deployment gegenüber anderen Containern abzuschirmen, die dafür notwendigen Schritte werden alle automatisch von Docker Compose übernommen.&lt;/p&gt;

&lt;p&gt;Docker Compose benötigt eine sogenannte &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker-compose.yml&lt;/code&gt; Datei, diese Datei enthält die Konfiguration des Deployments.
Durch Docker Compose werden die folgenden Ressourcen verwaltet:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Container&lt;/li&gt;
  &lt;li&gt;Overlaynetzwerke&lt;/li&gt;
  &lt;li&gt;Volumes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ein typisches Usecase für Docker Compose wäre eine Webanwendung, bei der eine Datenbank, ein Webserver und ein Anwendungsserver benötigt werden.
Dabei steuert Docker Compose die Erstellung der Container und deren persistenten Daten, die Erstellung eines Cloudnetzwerks sowie die automatische Zuweisung des Netzwerks an die Container.&lt;/p&gt;

&lt;p&gt;Die &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker-compose.yml&lt;/code&gt; für den oben beschriebenen Usecase sieht wie folgt aus:&lt;/p&gt;

&lt;div class=&quot;language-yaml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;na&quot;&gt;version&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;3.9&quot;&lt;/span&gt;
    
&lt;span class=&quot;na&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;db&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;mysql:5.7&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;container_name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;volumes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db_data:/var/lib/mysql&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;restart&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;always&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;MYSQL_ROOT_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;dbpasswd&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;MYSQL_DATABASE&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;MYSQL_USER&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db&lt;/span&gt;
      &lt;span class=&quot;na&quot;&gt;MYSQL_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db&lt;/span&gt;
    
  &lt;span class=&quot;na&quot;&gt;proxy&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;nginx:latest&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;container_name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;proxy&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;restart&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;always&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;volumes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;./nginx.conf:/etc/nginx/nginx.conf&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;./nginx/error.log:/etc/nginx/error_log.log&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;./nginx/cache/:/etc/nginx/cache&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;./ssl/:/etc/letsencrypt/&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;80:80&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;443:443&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;depends_on&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db&lt;/span&gt;
      &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;proxy&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;image&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;registry/myapp&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;restart&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;always&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;environment&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;DBL_USER&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;DB_PASSWORD&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db&lt;/span&gt;
       &lt;span class=&quot;na&quot;&gt;DB_HOST&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;db&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;container_name&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;app&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;ports&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;pi&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;3000:3000&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;volumes&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;db_data&lt;/span&gt;&lt;span class=&quot;pi&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;pi&quot;&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Die Nginx Konfiguration muss noch entsprechend als Reverse Proxy auf den &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app&lt;/code&gt; Container angepasst werden.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;docker-volumes&quot;&gt;Docker Volumes&lt;/h2&gt;

&lt;p&gt;Docker Volumes bieten die Möglichkeit, anfallende persistente Daten in einem Container zu speichern.
Volumes werden komplett durch Docker verwaltet und sind damit der offiziell empfohlene weg persistente Daten abzuspeichern.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Anzeigen bestehender Volumes
    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  C:&lt;span class=&quot;se&quot;&gt;\U&lt;/span&gt;sers&lt;span class=&quot;se&quot;&gt;\M&lt;/span&gt;arkus&amp;gt;docker volume &lt;span class=&quot;nb&quot;&gt;ls
  &lt;/span&gt;DRIVER    VOLUME NAME
  &lt;span class=&quot;nb&quot;&gt;local     &lt;/span&gt;256895275dee26176790078f8470e124671e3f74abf7fb5f84e36aaa8f8e6a78
  &lt;span class=&quot;nb&quot;&gt;local     &lt;/span&gt;c3687c2c12df99cfcbb6b725d57facf0e678ae776fdd6009009b7571ca1968cb
  &lt;span class=&quot;nb&quot;&gt;local     &lt;/span&gt;telly.config.toml
  &lt;span class=&quot;nb&quot;&gt;local     &lt;/span&gt;vscode
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Anlegen eines neuen Volumes
    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  docker volume create data
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Docker bietet auch die Möglichkeit, andere Storage Driver anzusprechen. Somit ist es möglich, die Volumes auf anderen Storage Medien zu speichern.
Von Haus aus unterstützt Docker die folgenden Storage Drivers:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Eine &lt;a href=&quot;https://docs.docker.com/storage/storagedriver/select-storage-driver/&quot;&gt;Liste&lt;/a&gt; mit eingebauten Storage Drivern&lt;/li&gt;
  &lt;li&gt;Eine &lt;a href=&quot;https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins&quot;&gt;Liste&lt;/a&gt; mit 3rd-party Storage Drivern&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;docker-networking&quot;&gt;Docker Networking&lt;/h2&gt;
&lt;p&gt;Um die Container untereinander zu vernetzen, bietet Docker die Möglichkeit, über Bridges auf dem Hostsystem Container miteinander zu verbinden.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Auflisten aller Netzwerke auf dem Host
    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  C:&lt;span class=&quot;se&quot;&gt;\U&lt;/span&gt;sers&lt;span class=&quot;se&quot;&gt;\M&lt;/span&gt;arkus&amp;gt;docker network &lt;span class=&quot;nb&quot;&gt;ls
  &lt;/span&gt;NETWORK ID     NAME      DRIVER    SCOPE
  fa8c5ca426e1   bridge    bridge    &lt;span class=&quot;nb&quot;&gt;local
  &lt;/span&gt;f9f00956c91d   host      host      &lt;span class=&quot;nb&quot;&gt;local
  &lt;/span&gt;679b81f531b8   none      null      &lt;span class=&quot;nb&quot;&gt;local&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Anlegen eines neues Netzwerks
    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  docker network create &lt;span class=&quot;nt&quot;&gt;--driver&lt;/span&gt; bridge new-network
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;blockquote&gt;
      &lt;p&gt;Mit dem Parameter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--driver | -d&lt;/code&gt; kann der Netzwerk Driver angegeben werden.&lt;/p&gt;
    &lt;/blockquote&gt;
  &lt;/li&gt;
  &lt;li&gt;Konfiguration der Standard Bridge auslesen
    &lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  C:&lt;span class=&quot;se&quot;&gt;\U&lt;/span&gt;sers&lt;span class=&quot;se&quot;&gt;\M&lt;/span&gt;arkus&amp;gt;docker network inspect bridge
  &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;s2&quot;&gt;&quot;Name&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;bridge&quot;&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Id&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;fa8c5ca426e18372730c1dce298ddf97862c8574cf2e71e58ed9f5a584948158&quot;&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Created&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;2022-01-12T14:58:18.607125133Z&quot;&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Scope&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;local&quot;&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Driver&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;bridge&quot;&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;EnableIPv6&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;IPAM&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
              &lt;span class=&quot;s2&quot;&gt;&quot;Driver&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;default&quot;&lt;/span&gt;,
              &lt;span class=&quot;s2&quot;&gt;&quot;Options&quot;&lt;/span&gt;: null,
              &lt;span class=&quot;s2&quot;&gt;&quot;Config&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;
                  &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                      &lt;span class=&quot;s2&quot;&gt;&quot;Subnet&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;172.17.0.0/16&quot;&lt;/span&gt;,
                      &lt;span class=&quot;s2&quot;&gt;&quot;Gateway&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;172.17.0.1&quot;&lt;/span&gt;
                  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
              &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
          &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Internal&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Attachable&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Ingress&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;ConfigFrom&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
              &lt;span class=&quot;s2&quot;&gt;&quot;Network&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;&quot;&lt;/span&gt;
          &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;ConfigOnly&quot;&lt;/span&gt;: &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Containers&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Options&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
              &lt;span class=&quot;s2&quot;&gt;&quot;com.docker.network.bridge.default_bridge&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;true&quot;&lt;/span&gt;,
              &lt;span class=&quot;s2&quot;&gt;&quot;com.docker.network.bridge.enable_icc&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;true&quot;&lt;/span&gt;,
              &lt;span class=&quot;s2&quot;&gt;&quot;com.docker.network.bridge.enable_ip_masquerade&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;true&quot;&lt;/span&gt;,
              &lt;span class=&quot;s2&quot;&gt;&quot;com.docker.network.bridge.host_binding_ipv4&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;0.0.0.0&quot;&lt;/span&gt;,
              &lt;span class=&quot;s2&quot;&gt;&quot;com.docker.network.bridge.name&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;docker0&quot;&lt;/span&gt;,
              &lt;span class=&quot;s2&quot;&gt;&quot;com.docker.network.driver.mtu&quot;&lt;/span&gt;: &lt;span class=&quot;s2&quot;&gt;&quot;1500&quot;&lt;/span&gt;
          &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;,
          &lt;span class=&quot;s2&quot;&gt;&quot;Labels&quot;&lt;/span&gt;: &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bei einem durch Docker verwalteten Netzwerk erfolgt die IP-Adressvergabe eigenständig durch Docker. Ebenso wie eine DNS Namensvergabe jeder Name eines Containers ist im Docker Netzwerk per DNS auflösbar. Somit ist es möglich, Container nach ihrem Namen im Netzwerk aufzurufen.&lt;/p&gt;

&lt;p&gt;Es existieren auch noch einige andere Netzwermodelle, diese können &lt;a href=&quot;https://docs.docker.com/network/#network-drivers&quot;&gt;hier&lt;/a&gt; eingesehen werden.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Mit Docker Swarm, lassen sich mehrere Docker Dienste zu einem Verbund zusammenschalten und somit können die Container auch Hostübergreifend miteinander kommunizieren.&lt;/p&gt;

  &lt;p&gt;Übersicht Overlay Netzwerke: https://docs.docker.com/network/overlay/&lt;/p&gt;

  &lt;p&gt;Beispielkonfiguration: https://docs.docker.com/network/network-tutorial-overlay/&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;container-orchestrierung&quot;&gt;Container Orchestrierung&lt;/h2&gt;
&lt;p&gt;Mit Container Orchistration lassen sich die Container in Clustern organisieren. In diesem Modus wird ein Cluster aus mehreren Containern einer Anwendung erstellt.
Dieses Cluster ist dank Hostübergreifenden Netzwerk und Speicher in der lage eine Hochverfügbare Clusterumgebung zu schaffen.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/BackInBash/Technikerschule/master/Jahr%202/CS/container_orchestration.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In dieser konstelation ist der einzelne Container nicht mehr von großer bedeutung, dieser kann durch die Beachtung der &lt;a href=&quot;https://12factor.net&quot;&gt;12 Faktoren&lt;/a&gt; einer Cloud Anwendung.
Im Laufenden betrieb ohne störungen zu verursachen ausgetauscht werden.&lt;/p&gt;

&lt;p&gt;Ein kleiner Überklich über die wichtigesten Eigenschaften einer Cloud Nativen Anwendung.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Die Anwendung selbst darf keinen Status im Arbeitsspeicher halten.&lt;/li&gt;
  &lt;li&gt;Persistente Daten dürfen nicht im Container gespeichert werden.&lt;/li&gt;
  &lt;li&gt;Die Konfguration der Anwendung erfolgt über Umgebungsvariablen oder zentralisiertem Konfigurationsmanagenemt.&lt;/li&gt;
  &lt;li&gt;Persistente Daten werden nur in Datenbanken gespeichert.&lt;/li&gt;
  &lt;li&gt;Container mit Persistenten Daten speichern diese in Volumes.&lt;/li&gt;
  &lt;li&gt;Volumes werden nicht auf dem Pod gespeichert sondern auf zentralisierten Storage Systemen z.B. S3 oder Ceph&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Somit lassen sich im Live Betrieb wartungen und aktualisierungen durchführen, die die Verfübgarkeit der Anwendung in keinster weise beeinträchtigen.&lt;/p&gt;

&lt;p&gt;Vielmehr lassen sich in einem solchen Cluster auch ganze Update oder Change Prozesse einbinden.
Durch die eingebaute Versionierung in die Container Images ist es möglich. Das Cluster in Production, Staging, Test und Development zu unterteilen und entsprechend den eingehenden Traffic an die gewünschten stellen zu Routen.
Hierdurch lässt sich der Grundgedanke von continuous deployment sehr gut umsetzen.&lt;/p&gt;

&lt;p&gt;Verbreitete Container Orchestration Tools:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Kubernetes&lt;/li&gt;
  &lt;li&gt;RedHad OpenShift&lt;/li&gt;
  &lt;li&gt;Apache Mesos&lt;/li&gt;
  &lt;li&gt;HashiCorp Nomad&lt;/li&gt;
  &lt;li&gt;Docker Swarm&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">Docker Container Plattform Docker ist ein Open Source-Projekt zur Automatisierung der Bereitstellung von Apps als mobile, eigenständige Container, die in der Cloud oder lokal ausgeführt werden können. Docker ist darüber hinaus ein Unternehmen, das diese Technologie fördert und weiterentwickelt und mit Cloud-Anbietern, Linux und Windows kompatibel ist.</summary></entry><entry><title type="html">SQL Views</title><link href="https://www.brunsch.me/sql-views" rel="alternate" type="text/html" title="SQL Views" /><published>2022-04-10T00:00:00+00:00</published><updated>2022-04-10T00:00:00+00:00</updated><id>https://www.brunsch.me/sql-views</id><content type="html" xml:base="https://www.brunsch.me/sql-views">&lt;h1 id=&quot;database-views&quot;&gt;Database Views&lt;/h1&gt;

&lt;p&gt;Views sind SQL Queries die in auf dem DB Server gespeichert werden und somit mit einem einfachen Aufruf der View wiederverwendet werden können.&lt;/p&gt;

&lt;p&gt;Beispiel View:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VIEW&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerPayments&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;checkNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;paymentDate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;amount&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;customers&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;JOIN&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;payments&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;USING&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;customerNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;vor-und-nachteile-von-views&quot;&gt;Vor und Nachteile von Views&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Pro:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Komplexe SQL Queries können in Views gespeichert werden somit kann der erneute Aufruf vereinfacht werden.&lt;/li&gt;
  &lt;li&gt;Business Logik zentralisieren, greifen mehrere Programme auf die gleiche Datenbank zu und benötigen die selben Daten. So kann eine View dabei helfen die Queries Programmübergreifend konsistent zu halten.&lt;/li&gt;
  &lt;li&gt;Zugriffsbeschränkung man kann einem Benutzer gestatten nur die View ausführen zu können, somit ist dieser nicht in der Lage andere Informationen aus der Datenbank zu extrahieren.&lt;/li&gt;
  &lt;li&gt;Bei Schemaänderungen kann eine View mit dem alten Namen der Tabelle erstellt werden, somit funktionieren Queries die auf das alte Schema referenzieren noch.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Con:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Auf Views können keine Indexes erstellt werden.&lt;/li&gt;
  &lt;li&gt;Views mit Sub-Queries, Joins oder Aggregatsfunktionen können nicht angepasst werden.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;views-verwalten&quot;&gt;Views Verwalten&lt;/h2&gt;

&lt;h3 id=&quot;views-erstellen&quot;&gt;Views Erstellen&lt;/h3&gt;
&lt;p&gt;Syntax:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;OR&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;REPLACE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VIEW&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;db_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.]&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;view_name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Beispiel:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VIEW&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;salePerOrder&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Mit dem &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WITH CHECK OPTION&lt;/code&gt; Parameter wird der Scope der View auf die Daten die die View (dessen WHERE Klausel) ausgibt beschränkt.
Somit können keine Datensätze außerhab diese Scopes ausgegeben, gelöscht oder bearbeitet werden.&lt;/p&gt;

&lt;p&gt;Da Views auch verschachtelt werden können, gibt es die Möglichkeit die &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WITH CHECK OPTION&lt;/code&gt; weiter zu Bearbeiten mit den Parametern &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LOCAL&lt;/code&gt; und &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CASCADED&lt;/code&gt; ist es Möglich den Scope der Checks einzuschränken.&lt;/p&gt;

&lt;p&gt;Mit der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WITH LOCAL CHECK OPTION&lt;/code&gt; Option werden nur Bedingungen in der Aufgerufenen View beachtet. Mit der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WITH CASCADED CHECK OPTION&lt;/code&gt; Option dagegen werden alle Bedingungen aller verschachtelten Views beachtet.&lt;/p&gt;

&lt;h3 id=&quot;algorithm&quot;&gt;Algorithm&lt;/h3&gt;
&lt;p&gt;Der Algorithmus Parameter bestimmt wie die View beim Aufruf durch MySQL verarbeitet werden soll.
Zur Auswahl stehen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MERGE&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TEMPTABLE&lt;/code&gt; und &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UNDEFINDE&lt;/code&gt;.
Syntax:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;OR&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;REPLACE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ALGORITHM&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MERGE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TEMPTABLE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UNDEFINED&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VIEW&lt;/span&gt; 
   &lt;span class=&quot;n&quot;&gt;view_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; 
   &lt;span class=&quot;k&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;statement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Bei einem &lt;strong&gt;Merge&lt;/strong&gt; Aufruf wird der Query String vor dem Ausführen auf der Datenbank vereinfacht.&lt;/p&gt;

&lt;p&gt;Aus der View&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ALGORITHM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MERGE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VIEW&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contactPersons&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;firstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;lastName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;contactFirstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;contactLastName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;mit dem SQL Query Aufruf&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contactPersons&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;LIKE&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'%Co%'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;werden die Parameter und der Tabellenname angepasst und eine &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WHERE&lt;/code&gt; Klausel angefügt (falls vorhanden).
Das follständige Query sieht dann so aus:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;contactFirstName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;contactLastName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;customers&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;LIKE&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'%Co%'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Der &lt;strong&gt;Temptable&lt;/strong&gt; Algorithmus erstellt eine temporäre Tabelle auf der der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SELECT&lt;/code&gt; Query dann aufgeführt wird.
Dies ist weniger effizient. Auf solch eine View kann auch kein &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UPDATE&lt;/code&gt; Query angewendet werden.
Einziger Vorteil ist, dass sich durch die temporäre Tabelle die Lock Dauer auf die Datenbank verringert.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Undefined&lt;/strong&gt; Beschreibt die Standardauswahl von MySQL, sollte kein Alorithmus angegeben werden.
Dabei verwendet MySQL den bevorzugten &lt;strong&gt;Merge&lt;/strong&gt; Algorithmus.&lt;/p&gt;

&lt;h3 id=&quot;views-entfernen&quot;&gt;Views Entfernen&lt;/h3&gt;
&lt;p&gt;Syntax:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VIEW&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;view_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Beispiel:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;DROP&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VIEW&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;EXISTS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerPayments&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;auflisten-aller-views&quot;&gt;Auflisten aller Views&lt;/h3&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;SHOW&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FULL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TABLES&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;table_type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'VIEW'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;blockquote&gt;
  &lt;p&gt;Da &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SHOW FULL Tables&lt;/code&gt; alle Tabellen der Datenbank zurückgibt wird die &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WHERE&lt;/code&gt; Klausel benötigt um die Views zu Filtern.&lt;/p&gt;
  &lt;h3 id=&quot;views-umbenennen&quot;&gt;Views Umbenennen&lt;/h3&gt;
  &lt;p&gt;Syntax:&lt;/p&gt;
  &lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;RENAME&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;original_view_name&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;TO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;new_view_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Beispiel:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;RENAME&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;productLineSales&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;TO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;productLineQtySales&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;view-update-queries&quot;&gt;View Update Queries&lt;/h3&gt;
&lt;p&gt;Um ein &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UPDATE&lt;/code&gt; Query auf einer View auszuführen, darf die View keine Sub-Queries, Joins oder Aggregatsfunktionen enthalten. Sollte die der Fall sein kann ein &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UPDATE&lt;/code&gt; Query auf der View ausgeführt werden.&lt;/p&gt;

&lt;p&gt;Beispiel:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;UPDATE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;officeInfo&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;phone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'+33 14 723 5555'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;officeCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">Database Views</summary></entry><entry><title type="html">Nextcloud Skalierung</title><link href="https://www.brunsch.me/scale-nextcloud" rel="alternate" type="text/html" title="Nextcloud Skalierung" /><published>2022-02-15T00:00:00+00:00</published><updated>2022-02-15T00:00:00+00:00</updated><id>https://www.brunsch.me/scale-nextcloud</id><content type="html" xml:base="https://www.brunsch.me/scale-nextcloud">&lt;h1 id=&quot;nextcloud-skalierungsoptionen&quot;&gt;Nextcloud Skalierungsoptionen&lt;/h1&gt;
&lt;p&gt;In diesem Beitrag halte ich meine Erfahrungen und Erkentnisse im Zusammenhang mit der Skalierung einer Nextcloud Instanz fest.&lt;/p&gt;

&lt;p&gt;Mit einer Standardmäßigen Nextcloud Installation ist man in der ausgangsposition eines Webservers mit PHP-FPM Integration (Nginx/Apache2) einer Datenbank (MariaDB/MySQL/PostgresSQL) und einem Caching Layer (RedisDB).&lt;/p&gt;

&lt;h2 id=&quot;worker-skalierung&quot;&gt;Worker Skalierung&lt;/h2&gt;
&lt;p&gt;Die eine Möglichkeit der Skalierung ist die Ebene der PHP-FPM Prozesse zu replizieren.
Dazu ist es nötig einen Reverse Proxy / Load Balancer aufzuspannen und vor die PHP Worker zu plazieren.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/BackInBash/nextcloud-done-right/worker-scale/arch.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Dabei teilen sich die PHP Worker die darunterliegenden Ressourcen wie WWW Root und die Datenbank.&lt;/p&gt;

&lt;p&gt;Durch die Skalierung auf 3 PHP Worker, wurde die Performance im vergleich zu einem single Worker setup etwas gesteigert.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/BackInBash/nextcloud-done-right/worker-scale/default.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Für den Benchmark wurde ein eigenes Tool erstellt, welches über WebDAV auf dem Nextcloud Server eine Menge X an Dateien erstellt.&lt;/p&gt;

&lt;p&gt;Das Projekt zum Benchmarktool ist &lt;a href=&quot;https://github.com/BackInBash/nextcloud-benchmark&quot;&gt;hier&lt;/a&gt; zu finden.&lt;/p&gt;

&lt;p&gt;Der Benchmark ist in der hinsicht sehr syntetisch, da hier nur die Auslastung eines Benutzers in betracht gezogen wird.
Die Worker Skalierung spielt ihre Vorteile aber erst richtig in einer multi User umgebung aus.&lt;/p&gt;

&lt;h2 id=&quot;datenbank-skalierung&quot;&gt;Datenbank Skalierung&lt;/h2&gt;
&lt;p&gt;Eine weitere Möglichkeit der Skalierung wäre es die Datenbank zu Skalieren.&lt;/p&gt;

&lt;p&gt;Hierbei gibt es zum einen die Möglichkeit die Datenbank in mehrere Instanzen zu Skalieren. Dies lässt sich mit MariaDB oder MySQL aber nicht umsetzen. Hier müsste auf eine Distributed Databases umgestiegen werden.&lt;/p&gt;

&lt;p&gt;Beispiele hierfür wären &lt;a href=&quot;https://github.com/cockroachdb/cockroach&quot;&gt;CockroachDB&lt;/a&gt; oder eine MySQL kompatibel akternative &lt;a href=&quot;https://github.com/pingcap/tidb&quot;&gt;TIDB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Eine weitere Möglichkeit der Datenbankskalierung ist das Sharding der Datenbank entwerder durch Datenbankproxies wie &lt;a href=&quot;https://github.com/apache/shardingsphere&quot;&gt;Apache 
Shardingsphere&lt;/a&gt; oder Datenbankintegrationen wie &lt;a href=&quot;https://github.com/citusdata/citus&quot;&gt;Postgres Extension Citus&lt;/a&gt;.&lt;/p&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">Nextcloud Skalierungsoptionen In diesem Beitrag halte ich meine Erfahrungen und Erkentnisse im Zusammenhang mit der Skalierung einer Nextcloud Instanz fest.</summary></entry><entry><title type="html">SQL Stored Procedures</title><link href="https://www.brunsch.me/stored-procedures" rel="alternate" type="text/html" title="SQL Stored Procedures" /><published>2022-01-10T00:00:00+00:00</published><updated>2022-01-10T00:00:00+00:00</updated><id>https://www.brunsch.me/stored-procedures</id><content type="html" xml:base="https://www.brunsch.me/stored-procedures">&lt;h1 id=&quot;stored-procedures&quot;&gt;Stored Procedures&lt;/h1&gt;
&lt;p&gt;Stored Procedures sind SQL Queries die auf dem Server abgespeichert sind. Vorteile und Funktionalitäten von Stored Procedures sind:&lt;/p&gt;
&lt;h3 id=&quot;funktionalitäten&quot;&gt;Funktionalitäten&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Es können Übergabeparamter übergeben werden&lt;/li&gt;
  &lt;li&gt;Es können Statements eingebaut werden wie &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IF&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CASE&lt;/code&gt; oder &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LOOP&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Es können andere Stored Procedures aufberufen werden. (Modularität)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;vorteile&quot;&gt;Vorteile&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Schnellere Ausführung, da das Query Kompiled im Cache gehalten wird&lt;/li&gt;
  &lt;li&gt;Weniger Traffic zum SQL Server, da nur der Name der Funktion und nicht das Query selbst übertragen werden muss&lt;/li&gt;
  &lt;li&gt;Business Logik zentral im SQL Server&lt;/li&gt;
  &lt;li&gt;Security, es können nur festgelegte Queries auf der Datenbank ausgeführt werden.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;nachteile&quot;&gt;Nachteile&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Erhöhter Ressourcenverbrauch auf dem Server, durch die Verarbeitung der Queries.&lt;/li&gt;
  &lt;li&gt;Schlechte Debugging Möglichkeiten&lt;/li&gt;
  &lt;li&gt;Der Betrieb und die Wartung der Queries erfordert geschultes Personal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;aufbau&quot;&gt;Aufbau&lt;/h3&gt;

&lt;p&gt;In der Datenbank:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetCustomers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; 
		&lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
		&lt;span class=&quot;n&quot;&gt;city&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
		&lt;span class=&quot;k&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
		&lt;span class=&quot;n&quot;&gt;postalCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
		&lt;span class=&quot;n&quot;&gt;country&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;customers&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;ORDER&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;BY&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;    
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Im Client:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CALL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetCustomers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;parameter&quot;&gt;Parameter&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;IN&lt;/strong&gt;
Der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IN&lt;/code&gt; Parameter ist der Standardparameter, dabei werden den Procedure Parameter die in das Query eingebau werden übergeben.&lt;/p&gt;

&lt;p&gt;Wird im Stored Procedure der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IN&lt;/code&gt; Parameter verändert, geschiet dies nur zur Laufzeit die eventuellen Änderungen werden nicht zum Anfrager zurückübertragen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Statement&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetOfficeByCountry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;IN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;countryName&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; 
 	&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offices&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;country&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;countryName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Call&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CALL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetOfficeByCountry&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'USA'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;OUT&lt;/strong&gt;
Der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OUT&lt;/code&gt; Parameter kann zur Laufzeit im Stored Procedure abgeändert werden, dabei werden die Änderungen auch an den Client zurückgemeldet.
Der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OUT&lt;/code&gt; Parameter kann nicht im Query verwendet werden, er dient lediglich zum extrahieren von Daten.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Statement&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetOrderCountByStatus&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;IN&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;orderStatus&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;OUT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;COUNT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;orderNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;total&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;orders&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;orderStatus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Call&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CALL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetOrderCountByStatus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Shipped'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;total&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;total&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;total_in_process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;INOUT&lt;/strong&gt;
Der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INOUT&lt;/code&gt; Parameter bietet zum einen die Möglichkeit Übergabeparameter an das Query zu übergeben und zum anderen lässt sich der veränderte Parameter nach ausführung des Queries mit den veränderten Werten an den Client zurückügertragen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Statement&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SetCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;INOUT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;IN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inc&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Call&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;CALL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SetCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;-- 2&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;CALL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SetCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;-- 3&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;CALL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SetCounter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;-- 8&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;-- 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;statements&quot;&gt;Statements&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;IF&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;IF Statements haben einen Bash ähnlichen Syntax&lt;/p&gt;
  &lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetCustomerLevel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;IN&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;pCustomerNumber&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;k&quot;&gt;OUT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pCustomerLevel&lt;/span&gt;  &lt;span class=&quot;nb&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;credit&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;DECIMAL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;creditLimit&lt;/span&gt; 
    &lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;credit&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customers&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerNumber&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pCustomerNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;credit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50000&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pCustomerLevel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'PLATINUM'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;END&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;Erweiterungen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ELSE&lt;/code&gt; und &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ELSEIF&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CASE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SQL Switch Case Statement&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;CASE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customerCountry&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;WHEN&lt;/span&gt;  &lt;span class=&quot;s1&quot;&gt;'USA'&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt;
		   &lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pShipping&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'2-day Shipping'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;WHEN&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Canada'&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt;
		   &lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pShipping&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'3-day Shipping'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;ELSE&lt;/span&gt;
		   &lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pShipping&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'5-day Shipping'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Es können auch vergleiche als CASE Statment verwendert werden.&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CASE&lt;/span&gt; 
		&lt;span class=&quot;k&quot;&gt;WHEN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;waitingDay&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt; 
			&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pDeliveryStatus&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'On Time'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;WHEN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;waitingDay&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;waitingDay&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pDeliveryStatus&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Late'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;WHEN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;waitingDay&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pDeliveryStatus&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'Very Late'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;ELSE&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pDeliveryStatus&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'No Information'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;CASE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;LOOP&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Endlosschlefe mit Austiegsbedingung&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LoopDemo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;  &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;  &lt;span class=&quot;nb&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        
	&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;s1&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        
	&lt;span class=&quot;n&quot;&gt;loop_label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;LOOP&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-- Start Loop&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt; 
			&lt;span class=&quot;n&quot;&gt;LEAVE&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;loop_label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-- Break&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            
		&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;mod&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;ITERATE&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;loop_label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;ELSE&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CONCAT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;','&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LOOP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-- End Loop&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;WHILE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While Loop in SQL&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LoadCalendars&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;startDate&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;DATE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;k&quot;&gt;day&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dt&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;DATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;startDate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;WHILE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;day&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DO&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-- While loop mit Bedingung&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;CALL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;InsertCalendar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DATE_ADD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;INTERVAL&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;day&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;END&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WHILE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-- End Loop&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;LEAVE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SQL equivalent zu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Break&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sp_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;condition&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;LEAVE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;-- Leave sp Label&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;END&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;-- other statement&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Error Handling&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PROCEDURE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;InsertSupplierProduct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;IN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inSupplierId&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
    &lt;span class=&quot;k&quot;&gt;IN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inProductId&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INT&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;-- exit if the duplicate key occurs&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EXIT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;HANDLER&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FOR&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1062&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;BEGIN&lt;/span&gt;
 	&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CONCAT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'Duplicate key ('&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inSupplierId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;','&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inProductId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;') occurred'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;-- insert a new row into the SupplierProducts&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SupplierProducts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;supplierId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;productId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;VALUES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inSupplierId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inProductId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;-- return the products supplied by the supplier id&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;COUNT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
    &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SupplierProducts&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;supplierId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inSupplierId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;aufbau--ablauf&quot;&gt;Aufbau &amp;amp; Ablauf&lt;/h2&gt;

&lt;p&gt;Exemplarischer Aufbau eines Stored Procedures.&lt;/p&gt;

&lt;h2 id=&quot;variablen-deklaration&quot;&gt;Variablen Deklaration&lt;/h2&gt;
&lt;p&gt;Die Variablendeklaration leitet den gebinn eines Stored Procedures ein.
Variablen sollten zu allererst deklariert werden.&lt;/p&gt;

&lt;p&gt;Beispielhafte Variablendeklaraion:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;test1&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;INTEGER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;test2&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;BOOLEAN&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;DEFAULT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Datentypen:
Datentyp|Initialisierung
–|–|
INTEGER|-|
VARCHAR|1-265
BOOLEAN|True, False&lt;/p&gt;

&lt;h2 id=&quot;cursor&quot;&gt;Cursor&lt;/h2&gt;
&lt;p&gt;Unter die Variablendeklaration fält auch die &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CURSOSR&lt;/code&gt; Deklaration.
Diese ist für den Loop eine Liste an werden die iteriert werden kann.&lt;/p&gt;

&lt;p&gt;Beispieldeklaration:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iterator&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;CURSOR&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FOR&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tabelle&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;WHERE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wert1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;wert2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Um den &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CURSOR&lt;/code&gt; später verwenden zu können, muss dieser erst geöffnet werden:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;OPEN&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iterator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Im Anschluss kann dieser in einer Schleife verwendet werden.&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testVar&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;VARCHAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;schleife&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LOOP&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;FETCH&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iterator&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;testVar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LOOP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;continue-handler&quot;&gt;Continue Handler&lt;/h2&gt;
&lt;p&gt;Handler sind Ereignese / Fehler die abgefangen werden.
Für eine Schleife ist es nötige einen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NOT FOUND&lt;/code&gt; Handler zu erstellen, damit das ende einer Schleife detektiert werden kann.&lt;/p&gt;

&lt;p&gt;Beispiel einer Handlerdeklaration:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;DECLARE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;CONTINUE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;HANDLER&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;FOR&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;NOT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FOUND&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;weitermachen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Beispiel einer Handlerabfrage:&lt;/p&gt;
&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;weitermachen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FALSE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;THEN&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;LEAVE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;schleife&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;END&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">Stored Procedures Stored Procedures sind SQL Queries die auf dem Server abgespeichert sind. Vorteile und Funktionalitäten von Stored Procedures sind: Funktionalitäten Es können Übergabeparamter übergeben werden Es können Statements eingebaut werden wie IF CASE oder LOOP Es können andere Stored Procedures aufberufen werden. (Modularität)</summary></entry><entry><title type="html">Umsetzung einer Cloud HA Infrastruktur mit Keepalived</title><link href="https://www.brunsch.me/keepalived" rel="alternate" type="text/html" title="Umsetzung einer Cloud HA Infrastruktur mit Keepalived" /><published>2021-05-19T00:00:00+00:00</published><updated>2021-05-19T00:00:00+00:00</updated><id>https://www.brunsch.me/keepalived</id><content type="html" xml:base="https://www.brunsch.me/keepalived">&lt;h2 id=&quot;konfiguration-einer-ha-struktur-in-der-cloud-mithilfe-von-floating-ips-und-keepalived&quot;&gt;Konfiguration einer HA Struktur in der Cloud mithilfe von Floating-IPs und Keepalived&lt;/h2&gt;

&lt;p&gt;In diesem Tutorial wird die Einrichtung eines Cloud HA Clusters mithilfe von Keepalived und Floating-IPs beschrieben.&lt;/p&gt;

&lt;p&gt;Zu beachten ist das diese form der Hochverfügbarkeit nicht von allen Anwendungen unterstützt wird. Dies sollte im ersten Schritt geprüft werden.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Voraussetzungen&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;min. 2 Cloud Server&lt;/li&gt;
  &lt;li&gt;Eine Floating-IP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Empfehlung&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Für den HA Service sollte ein eigenes Cloud Projekt angelegt werden, da auf den Servern &lt;strong&gt;kritische&lt;/strong&gt; Zugangsdaten im &lt;strong&gt;klartext&lt;/strong&gt; abgelegt werden müssen.
Mit einem seperaten Projekt kann bei einer möglichen kompromitierung der Schaden minimiert werden.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;schritt-1---einrichtung-des-automatischen-ip-rerouting&quot;&gt;Schritt 1 - Einrichtung des automatischen IP Rerouting&lt;/h2&gt;

&lt;p&gt;In diesem Schritt geht es um das automatische Failover, dabei soll die Floating-IP automatisch dem anderen Server zugewiesen werden. Damit dieser unter der gleichen Adresse den ausgefallenen Dienst wieder aufnehmen stellen kann.&lt;/p&gt;

&lt;h3 id=&quot;schritt-11---erstellung-eines-cloud-api-tokens&quot;&gt;Schritt 1.1 - Erstellung eines Cloud API Tokens&lt;/h3&gt;

&lt;p&gt;Dieser Token wird benötigt um später vom Server aus die Floating-IP zuordnung zu steuern.&lt;/p&gt;

&lt;p&gt;In der Cloud Console muss unter &lt;strong&gt;“Sicherheit”&lt;/strong&gt; –&amp;gt; &lt;strong&gt;“API-Tokens”&lt;/strong&gt; ein &lt;strong&gt;Lese/Schreib&lt;/strong&gt; API Token angelegt werden.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/api.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hinweis: Da der Token nur einmal ausgelesen werden kann empfiehlt es sich diesen zwischenzuspeichern.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;schritt-12---anlegen-eines-cloud-netzwerks&quot;&gt;Schritt 1.2 - Anlegen eines Cloud Netzwerks&lt;/h3&gt;

&lt;p&gt;Für den &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VRRP&lt;/code&gt; Heartbeat wird ein privater Netzwerkkanal benötigt dieser wird über die Funktion der Cloud Netzwerke realisiert.&lt;/p&gt;

&lt;p&gt;Solche ein Cloud Netzwerk kann in der Cloud Console unter “Netzwerke” angelegt werden.&lt;/p&gt;

&lt;p&gt;Hier kann ein Netzwerk mit beliebiger größe (größer 32) angelegt und den beiden Server auch gleich zugewiesen werden.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/network.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;schritt-13---installation-der-ip-failover-software&quot;&gt;Schritt 1.3 - Installation der IP Failover Software&lt;/h3&gt;

&lt;p&gt;In diesm Schritt wird die Software installiert, die für die Provisionierung der Floating-IP zuständig ist.&lt;/p&gt;

&lt;p&gt;Dabei handelt es sich um die Open Source Software &lt;a href=&quot;https://github.com/FootprintDev/hcloud-ip&quot;&gt;hcloud-ip&lt;/a&gt; um die Software zu installieren kann entweder auf die prebuilt-Binaries zurückgegriffen werden oder man kompiliert die Software selbst.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Für eine installation mit den prebuilt-Binaries sind folgende Schritte notwendig&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;wget &lt;span class=&quot;nt&quot;&gt;-O&lt;/span&gt; /opt/hcloud-ip https://github.com/FootprintDev/hcloud-ip/releases/download/v0.0.1/hcloud-ip-linux64
&lt;span class=&quot;nb&quot;&gt;chmod&lt;/span&gt; +x /opt/hcloud
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Um die Software selbst zu kompiliert sind folgende Schritte notwendig&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Installation der Abhängigkeiten&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ubuntu / Debian:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;git wget
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;CentOS / RHEL:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;yum &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;git wget
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Fedora:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dnf instal git wget
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;openSUSE / SLES:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;zypper &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;git wget
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;Golang Installation&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;wget https://golang.org/dl/go1.16.2.linux-amd64.tar.gz
&lt;span class=&quot;nb&quot;&gt;tar &lt;/span&gt;xfvz go1.16.2.linux-amd64.tar.gz
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pwd&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;/go/bin:&lt;span class=&quot;nv&quot;&gt;$PATH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;Clonen des Repositories&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/FootprintDev/hcloud-ip /tmp/hcloud-ip &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /tmp/hcloud-ip
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;Projekt Bauen&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;go build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nun sollte sich im aktuellen Ordner ein Programm mit dem Namen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hcloud-ip&lt;/code&gt; befinden, dies kann entsprechend ausführbar gemacht und abgespeichert werden.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;chmod&lt;/span&gt; +x hcloud-ip
&lt;span class=&quot;nb&quot;&gt;mv &lt;/span&gt;hcloud-ip /opt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;schritt-14---konfiguration-der-floating-ip&quot;&gt;Schritt 1.4 - Konfiguration der Floating-IP&lt;/h3&gt;

&lt;p&gt;Damit die Floating-IP bei einem Failover auf allen Servern funktioniert, muss diese in die Netzwerkkonfiguration aufgenommen werden.
Eine Anleitung hierfür befindet sich auf &lt;a href=&quot;https://docs.hetzner.com/cloud/floating-ips/persistent-configuration&quot;&gt;docs.hetzner.com&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;schritt-2---einrichtung-von-keepalived&quot;&gt;Schritt 2 - Einrichtung von Keepalived&lt;/h2&gt;

&lt;p&gt;Keepalived ist ein Linux Daemon der Systeme oder Dienste überwacht und im Fehlerfall ein Failover anstößt.&lt;/p&gt;

&lt;h3 id=&quot;schritt-21---installation-von-keepalived&quot;&gt;Schritt 2.1 - Installation von Keepalived&lt;/h3&gt;

&lt;p&gt;Ubuntu / Debian:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;keepalived
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;CentOS / RHEL:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;yum &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;keepalived
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Fedora:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;dnf instal keepalived
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;openSUSE / SLES:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;zypper &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;keepalived
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;schritt-22---keepalived-autostart-aktivieren&quot;&gt;Schritt 2.2 - Keepalived autostart aktivieren&lt;/h3&gt;

&lt;p&gt;Systemd basierte Systeme:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl &lt;span class=&quot;nb&quot;&gt;enable &lt;/span&gt;keepalived
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;CentOS / RHEL&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;chkconfig keepalived on
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;schritt-23---konfiguration-von-keepalived&quot;&gt;Schritt 2.3 - Konfiguration von Keepalived&lt;/h3&gt;

&lt;p&gt;Die hier gezeigte Konfiguration entspricht einem Beispiel anhand eines HA Webservers (nginx).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Konfiguration des Master Servers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/keepalived/keepalived.conf&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-Console&quot;&gt;vrrp_script chk_nginx {
    script &quot;/usr/bin/pgrep nginx&quot;
    interval 2
}

vrrp_instance VI_1 {
    interface [cloud_network_adapter]
    state MASTER
    priority 200

    virtual_router_id 30
    unicast_src_ip [master_private_IP]
    unicast_peer {
        [slave_private_IP]
    }

    authentication {
        auth_type PASS
        auth_pass [password]
    }

    track_script {
        chk_nginx
    }

    notify_master /etc/keepalived/failover.sh
}
&lt;/code&gt;&lt;/pre&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hinweis: Die umrandeten Werte &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[]&lt;/code&gt; sind durch eigene Angaben auszutauschen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Konfiguration des Slave Servers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/keepalived/keepalived.conf&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-Console&quot;&gt;vrrp_script chk_nginx {
    script &quot;/usr/bin/pgrep nginx&quot;
    interval 2
}

vrrp_instance VI_1 {
    interface [cloud_network_adapter]
    state SLAVE
    priority 100

    virtual_router_id 30
    unicast_src_ip [slave_private_IP]
    unicast_peer {
        [master_private_IP]
    }

    authentication {
        auth_type PASS
        auth_pass [password]
    }

    track_script {
        chk_nginx
    }

    notify_master /etc/keepalived/failover.sh
}
&lt;/code&gt;&lt;/pre&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hinweis: Die umrandeten Werte &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[]&lt;/code&gt; sind durch eigene Angaben auszutauschen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Inhalt der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;failover.sh&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Das Script beinhaltet die Aktionen die bei einem Failover ausgeführt werden sollen.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;IP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'[Floating-IP-Name]'&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;TOKEN&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'[CloudToken]'&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0
&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$n&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-lt&lt;/span&gt; 10 &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;do
    if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;/opt/hcloud-ip &lt;span class=&quot;nt&quot;&gt;-ip&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$IP&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-key&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$TOKEN&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Server called &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$HOSTNAME&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; was found&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then
        &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;break
    &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;fi
    &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$((&lt;/span&gt;n+1&lt;span class=&quot;k&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;sleep &lt;/span&gt;3
&lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hinweis: Die umrandeten Werte &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[]&lt;/code&gt; sind durch eigene Angaben auszutauschen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;schritt-3---testen-der-konfiguration&quot;&gt;Schritt 3 - Testen der Konfiguration&lt;/h2&gt;

&lt;p&gt;Im Normalbetrieb übernimmt der Master Webserver alle Anfragen.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/master.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Sobald dieser ausfällt gibt es ein Failover auf den Slave Webserver.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/slave.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Sobald der Master Webserver wieder erreichbar ist wird wieder auf diesen gewechselt.&lt;/p&gt;

&lt;h2 id=&quot;fazit&quot;&gt;Fazit&lt;/h2&gt;

&lt;p&gt;In diesem Beitrag wird beschreiben wie man eine High Availability Cloud Umgebung mithilfe von keepalived erstellt.&lt;/p&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">Konfiguration einer HA Struktur in der Cloud mithilfe von Floating-IPs und Keepalived</summary></entry><entry><title type="html">UNIX Berechtigungen</title><link href="https://www.brunsch.me/unix-permissions" rel="alternate" type="text/html" title="UNIX Berechtigungen" /><published>2020-10-26T00:00:00+00:00</published><updated>2020-10-26T00:00:00+00:00</updated><id>https://www.brunsch.me/unix-permissions</id><content type="html" xml:base="https://www.brunsch.me/unix-permissions">&lt;h1 id=&quot;datei-berechtigungen&quot;&gt;Datei Berechtigungen&lt;/h1&gt;

&lt;h2 id=&quot;allgemeines&quot;&gt;Allgemeines&lt;/h2&gt;
&lt;p&gt;In Linux: einfaches Rechtekonzept &amp;gt; 50 Jahre alt,
Benutzernamen und Gruppen basiert.&lt;/p&gt;

&lt;p&gt;Jede Datei (auch Geräte - „everything is a file“) und jedes Verzeichnis gehört genau einem Nutzer (user: u) und einer Gruppe (group g).&lt;/p&gt;

&lt;p&gt;Der Besitzer gilt als &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u&lt;/code&gt;, andere Mitglieder der Besitzergruppe gelten als &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt;.
Alle anderen gelten als sonstige Nutzer (others: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;o&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Beim Anlegen einer Datei gehört sie zunächst der primären Gruppe des Anlegenden.
Will man mehr Berechtigungen? ACL (Access Control List): erlauben die Vergabe komplexer Rechtestrukturen ähnlich zu NTFS-Berechtigungen.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@PCITBMR:/tmp/tmp.tP7iSWSie9# &lt;span class=&quot;nb&quot;&gt;ls&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-ltsa&lt;/span&gt;
total 0
0 drwxrwxrwt 1 root root     512 Oct 26 11:42 ..
0 drwx------ 1 root root     512 Oct 26 11:41 &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
0 &lt;span class=&quot;nt&quot;&gt;-rw-------&lt;/span&gt; 1 root www-data   0 Oct 26 11:41 tmp.c4x2xSSTNk
0 &lt;span class=&quot;nt&quot;&gt;-rw-------&lt;/span&gt; 1 root www-data   0 Oct 26 11:41 tmp.RR1cd1Rzz0
0 &lt;span class=&quot;nt&quot;&gt;-rw-------&lt;/span&gt; 1 root www-data   0 Oct 26 11:41 tmp.ffCLHbTpoh
0 &lt;span class=&quot;nt&quot;&gt;-rw-------&lt;/span&gt; 1 root www-data   0 Oct 26 11:41 tmp.2ykfAZO1O3
0 &lt;span class=&quot;nt&quot;&gt;-rw-------&lt;/span&gt; 1 root www-data   0 Oct 26 11:41 tmp.LsAW89CTtO
0 &lt;span class=&quot;nt&quot;&gt;-rw-------&lt;/span&gt; 1 root www-data   0 Oct 26 11:41 tmp.lHaxyGeRJQ
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;programme-zum-ändern-der-berechtigungen&quot;&gt;Programme zum Ändern der Berechtigungen&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chgrp&lt;/code&gt; ändert Besitzergruppe
Aber: Nur Besitzer und root können &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chgrp&lt;/code&gt; ausführen&lt;/p&gt;

&lt;p&gt;Parameter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-R&lt;/code&gt; ändert Gruppe rekursiv (in allen Dateien und Unterverzeichnissen des Ziels)
chown (“change owner”) kann Besitzer, aber auch die Besitzergruppe ändern.
Nur Besitzer: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chown&lt;/code&gt; neuuser datei
Besitzer und Gruppe: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chown&lt;/code&gt; neuuser:neugruppe datei
Nur Gruppe: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chown&lt;/code&gt; :neugruppe datei&lt;/p&gt;

&lt;h2 id=&quot;berechtigungs-kategoriern&quot;&gt;Berechtigungs Kategoriern&lt;/h2&gt;

&lt;p&gt;Für jede der drei Kategorien &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; und &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;o&lt;/code&gt; lassen sich folgende drei Dateirechte vergeben:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Leserecht (read &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Schreibrecht (write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Ausführungsrecht (execute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;)
Bei Verzeichnissen gilt:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt;: Dateinamen im Verzeichnis (aber keine Details) anschauen
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt; (nur in Kombination mit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;) Dateien löschen / anlegen
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt; mit cd “betreten”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Die Rechtesuche geht von links nach rechts:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u&lt;/code&gt;-Eigenschaft sticht &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; (selbst wenn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt; höhere Rechte hat)
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;g&lt;/code&gt;-Eigenschaft sticht &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;o&lt;/code&gt; (selbst wenn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;o&lt;/code&gt; höhere Rechte hat)&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;----r--rw-&lt;/span&gt; 1 go go 0 Okt 10 15:52 datei1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;User &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go&lt;/code&gt; hat gar keine Rechte auf die Datei &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;datei1&lt;/code&gt;, selbst wenn er Mitglied der Gruppe &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go&lt;/code&gt; ist.&lt;/p&gt;

&lt;p&gt;Ungeachtet dessen ist &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go&lt;/code&gt; als Eigentümer der Einzige, der diese Berechtigungen ändern darf (außer &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt; natürlich).
Alle Mitglieder von &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go&lt;/code&gt; (außer &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go&lt;/code&gt;) haben Leserechte. Alle anderen (nicht &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go&lt;/code&gt;, nicht Mitglied von &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;go&lt;/code&gt;) haben Lese- und Schreibrechte.&lt;/p&gt;

&lt;h2 id=&quot;beispiel&quot;&gt;Beispiel&lt;/h2&gt;

&lt;p&gt;Gegeben sind folgende Rechte:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;drwxr-xr-x 9 root  root  4096 Okt 10 16:09 /
drwxr-xr-- 3 root  root  4096 Okt 10 16:01 /a
&lt;span class=&quot;nt&quot;&gt;-rwxrwxrwx&lt;/span&gt; 1 user1 user1 254  Okt 10 15:52 /a/y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Welche Rechte hat &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user1&lt;/code&gt; auf &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/a/y&lt;/code&gt; in der Praxis?&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Gar keine, denn es fehlt das &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;-Recht für &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/a&lt;/code&gt; – somit kommt der User gar nicht in das nötige Verzeichnis hinein!
Wer darf sich den Inhalt von &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/a&lt;/code&gt; mit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ls /a&lt;/code&gt; anzeigen lassen?&lt;/li&gt;
  &lt;li&gt;Alle, denn dazu reicht das &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt;-Bit auf &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/a&lt;/code&gt; in Kombination mit dem &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;-Bit auf &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt; - allerdings sehen nur Mitglieder der &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt;-Gruppe Details zu den Inhalten wegen des &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;-Bit auf &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/a&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">Datei Berechtigungen</summary></entry><entry><title type="html">Einführung IPTables</title><link href="https://www.brunsch.me/iptables" rel="alternate" type="text/html" title="Einführung IPTables" /><published>2020-06-17T00:00:00+00:00</published><updated>2020-06-17T00:00:00+00:00</updated><id>https://www.brunsch.me/iptables</id><content type="html" xml:base="https://www.brunsch.me/iptables">&lt;h2 id=&quot;einrichtung-eines-paketfilters-auf-linux&quot;&gt;Einrichtung eines Paketfilters auf Linux&lt;/h2&gt;

&lt;p&gt;In diesem Beitrag geht es um die Einführung in iptables um die Funktionen zu verstehen und anwenden zu können.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Achtung&lt;/strong&gt;: Vorsicht ist geboten, durch unüberlegte Änderungen an der Firewall kann man sich schnell aus dem System aussperren.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Voraussetzungen&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt; Zugriff auf eine Linux Shell mit installiertem &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;iptables&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;abschnitt-1---was-ist-iptables&quot;&gt;Abschnitt 1 - Was ist iptables?&lt;/h2&gt;

&lt;p&gt;iptables ist ein Userspace Programm das zur Konfiguration der Netfilter Firewall im Linux Kernel verwendet wird.
Somit ist iptables nur ein Werkzeug um die im Linux Kernel integrierte Firewall zu konfigurieren.&lt;/p&gt;

&lt;p&gt;iptables teilt sich in zwei bereiche auf jeweils für IPv4 und IPv6 gibt es eigene Tools.
Für IPv4 verwendet man &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;iptables&lt;/code&gt; und für IPv6 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ip6tables&lt;/code&gt; alle nachfolgenden Befehle können aber mit beiden Tools gleich verwendet werden.&lt;/p&gt;

&lt;p&gt;Durch den Netfilter ist es Möglich:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Eingehende Pakete zu Filtern bevor diese an die Zielanwendung geleitet werden.&lt;/li&gt;
  &lt;li&gt;Ausgehende Pakete zu Filtern bevor diese den Rechner verlassen.&lt;/li&gt;
  &lt;li&gt;Durch den Rechner geleitete (Router) Pakete zu prüften.&lt;/li&gt;
  &lt;li&gt;Paketmanipulation durchzuführen.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;abschnitt-11---funktionsweise&quot;&gt;Abschnitt 1.1 - Funktionsweise&lt;/h3&gt;

&lt;p&gt;Die Paketprüfung mit iptables ist dreistufig aufgebaut (von oben nach unten):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Tabellen&lt;/li&gt;
  &lt;li&gt;“Chains” (Ketten)&lt;/li&gt;
  &lt;li&gt;Filterregeln&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Trifft eine der definierten Filterregeln in den Tabellen / Chains zu wird diese ausgeführt, sollte keine Regel hinterlegt sein oder keine der definierten Regeln zutreffen wird auf die hinterlegte Policy angewendet (Später mehr dazu).&lt;/p&gt;

&lt;h3 id=&quot;tabellen&quot;&gt;Tabellen&lt;/h3&gt;

&lt;p&gt;In den Tabellen sind verschiedene Chains zu Gruppen nach der grundsätzlichen Aufgabe zusammengefasst.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Tabelle&lt;/th&gt;
      &lt;th&gt;Beschreibung&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;filter&lt;/td&gt;
      &lt;td&gt;Die Standardtabelle hier werden alle Filterregeln hinterlegt&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;nat&lt;/td&gt;
      &lt;td&gt;Diese Tabelle wird für NAT (Network Address Translation) und Port Forwarding verwendet.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;mangle&lt;/td&gt;
      &lt;td&gt;Diese Tabelle wird bei Paketmanipulationen verwendet.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;raw&lt;/td&gt;
      &lt;td&gt;Diese Tabelle wird eingesetzt um Ausnahmen vom Connection Tracking zu definieren.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;chains&quot;&gt;Chains&lt;/h3&gt;

&lt;p&gt;Die Chains legen fest, wann ein Paket geprüft wird z.B. bevor es versendet wird.
Eine Chain kann dabei in mehreren Tabellen vorkommen.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Chain&lt;/th&gt;
      &lt;th&gt;Tabelle&lt;/th&gt;
      &lt;th&gt;Beschreibung&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;INPUT&lt;/td&gt;
      &lt;td&gt;filter, mangle&lt;/td&gt;
      &lt;td&gt;Wird auf alle Pakete angewendet, die an die lokalen Adresse gerichtet sind.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;OUTPUT&lt;/td&gt;
      &lt;td&gt;filter, nat, mangle, raw&lt;/td&gt;
      &lt;td&gt;Wird auf alle Pakete angewendet, die von der lokalen Adresse stammen.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FORWARD&lt;/td&gt;
      &lt;td&gt;filter, mangle&lt;/td&gt;
      &lt;td&gt;Wird auf alle Pakete angewendet, die geroutet werden.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;PREROUTING&lt;/td&gt;
      &lt;td&gt;nat, mangle, raw&lt;/td&gt;
      &lt;td&gt;Wird auf alle Pakete angewendet, bevor diese geroutet werden.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;POSTROUTING&lt;/td&gt;
      &lt;td&gt;nat, mangle&lt;/td&gt;
      &lt;td&gt;Wird auf alle Pakete angewendet, nachdem diese geroutet wurden.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;abschnitt-2---definition-von-filterregel&quot;&gt;Abschnitt 2 - Definition von Filterregel&lt;/h2&gt;

&lt;p&gt;Hier sind die gängigsten CLI Parameter für das erstellen der Filterregeln aufgelistet.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Option&lt;/th&gt;
      &lt;th&gt;Beschreibung&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;-t Tabelle&lt;/td&gt;
      &lt;td&gt;Diese Filterregel gilt für die genannte Tabelle.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-I Chain (Position)&lt;/td&gt;
      &lt;td&gt;Regel wird an gewählte Position der Chain hinzugefügt. Standardmäßig wird die Regel am Anfang der Chain eingefügt.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-A Chain&lt;/td&gt;
      &lt;td&gt;Regel wird an die Chain angehängt.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-D Chain&lt;/td&gt;
      &lt;td&gt;Regel wird aus der Chain gelöscht.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-F Chain&lt;/td&gt;
      &lt;td&gt;Alle Regeln der Chain löschen.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-L Chain&lt;/td&gt;
      &lt;td&gt;Liste alle Regeln der Chain.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-p Protokoll&lt;/td&gt;
      &lt;td&gt;Das Paket wird nur geprüft, wenn es dem Protokoll entspricht (z.B. TCP, UDP, ICMP).&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-s IP-Adresse&lt;/td&gt;
      &lt;td&gt;Das Paket wird nur geprüft, wenn es von der definierten IP-Adresse / IP-Netz stammt.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-d IP-Adresse&lt;/td&gt;
      &lt;td&gt;Das Paket wird nur geprüft, wenn es an die definierte IP-Adresse gesendet wird.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-i Netzwerkschnittstelle&lt;/td&gt;
      &lt;td&gt;Das Paket wird nur geprüft, wenn es über die entsprechende Netzwerkschnittstelle eingegangen ist.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-o Netzwerkschnittstelle&lt;/td&gt;
      &lt;td&gt;Das Paket wird nur geprüft, wenn es über die entsprechende Netzwerkschnittstelle versendet wird.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;–sport (Port) oder –source-port (Port)&lt;/td&gt;
      &lt;td&gt;Das Paket wird nur geprüft, wenn es von dem definierten Port stammt. Muss zwingend in Verbindung mit -p benutzt werden!&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;–dport (Port) oder –destination-port (Port)&lt;/td&gt;
      &lt;td&gt;Das Paket wird nur geprüft, wenn es an den definierte Port gesendet wird. Muss zwingend in Verbindung mit -p benutzt werden!&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-j Aktion&lt;/td&gt;
      &lt;td&gt;Legt fest, welche Aktion auf das Paket angewendet werden soll.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;abschnitt-21---definition-von-aktionen&quot;&gt;Abschnitt 2.1 - Definition von Aktionen&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Aktion&lt;/th&gt;
      &lt;th&gt;Beschreibung&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;ACCEPT&lt;/td&gt;
      &lt;td&gt;Das Paket wird akzeptiert und angenommen.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DROP&lt;/td&gt;
      &lt;td&gt;Das Paket wird nicht angenommen, der Sender erhält keine Nachricht.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;REJECT&lt;/td&gt;
      &lt;td&gt;Das Paket wird nicht angenommen, der Sender wird benachrichtigt.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;LOG&lt;/td&gt;
      &lt;td&gt;Die Paketdaten werden im System-Log festgehalten, anschließend wird die nächste Regel der Chain geprüft und ggf. angewendet.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;abschnitt-22---definition-von-policies&quot;&gt;Abschnitt 2.2 - Definition von Policies&lt;/h2&gt;

&lt;p&gt;Eine Policy ist wie eine Grundsatzregel zu sehen sie greift also immer, wenn keine andere Filterregel zutrifft.&lt;/p&gt;

&lt;p&gt;Eine Policy setzt sich aus der Chain und einer Aktion zusammen:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -P INPUT DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Achtung&lt;/strong&gt;: Diese Policy Blockiert den eingehenden Traffic soweit keine Regeln definiert wurden.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hier im Beispiel werden alle eingehenden Pakete in in der Filter Tabelle durch die Policy verworfen.&lt;/p&gt;

&lt;h2 id=&quot;abschnitt-3---loopback-interface-127001&quot;&gt;Abschnitt 3 - Loopback Interface (127.0.0.1)&lt;/h2&gt;

&lt;p&gt;Auf jedem Linux System befindet sich ein Lokaler Netzwerkadapter dieser trägt den Namen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lo&lt;/code&gt;
Hierrüber laufen interne Host anwendungen, diese Kommunizieren mitunter per IPC (Inter Process Communication) über diesen Adapter.
Daher ist es ratsam auf diesen Adapter keinerlei Filterregeln anzuwenden, da dies zu Kommunikationsproblemen führen kann.&lt;/p&gt;

&lt;p&gt;Diesem Adapter sollte die Kommunikation ohne Einschränkungen erlaubt werden:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;abschnitt-4---praktische-beispiele&quot;&gt;Abschnitt 4 - Praktische Beispiele&lt;/h2&gt;

&lt;h3 id=&quot;erstellen-einer-paket-filterregel&quot;&gt;Erstellen einer Paket Filterregel&lt;/h3&gt;

&lt;p&gt;Diese Regel erlaubt eingehenden HTTPS Traffic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -A INPUT -p tcp --dport 443 -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;erstellen-einer-host-filterregel&quot;&gt;Erstellen einer Host Filterregel&lt;/h3&gt;

&lt;p&gt;Diese Regel erlaubt eingehenden Traffic vom angegebenen Host:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -A INPUT -s 10.0.0.1 -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Diese Regel verbietet eingehenden Traffic vom angegebenen Host.:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -A INPUT -s 10.0.0.1 -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Regeln können auch an einer bestimmten Stelle hinzugefügt werden:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -I INPUT 2 -s 10.0.0.1 -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Diese Regel steht z.B. an zweiter Stelle.&lt;/p&gt;

&lt;h3 id=&quot;löschen-aller-regeln&quot;&gt;Löschen aller Regeln&lt;/h3&gt;

&lt;p&gt;Löscht alle Regeln in allen Chains:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -F
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Löscht alle Regeln in der INPUT Chain:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -F INPUT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;löschen-einer-regel&quot;&gt;Löschen einer Regel&lt;/h3&gt;

&lt;p&gt;Hiermit werden die Regeln mitsamt den entsprechenden Nummern angegeben:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -L --line-numbers
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
2    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Mithilfe dieser Nummer kann nun die gewünschte Regel gelöscht werden:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -D INPUT 1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;connection-state&quot;&gt;Connection State&lt;/h3&gt;

&lt;p&gt;Damit bei bereits hergestellten Verbindungen nicht jedes Paket durch den Filter muss, können Connection State Filter eingesetzt werden.&lt;/p&gt;

&lt;p&gt;Eingehende Pakete für existierende Verbindungen zulassen:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ausgehende Pakete für existierende Verbindungen zulassen:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -A OUTPUT -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hinweis:
Die Connection State Regeln sollten weit oben in der Firewall Liste stehen da diese sonst ihren nutzen verlieren.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;verwerfen-von-invaliden-paketen&quot;&gt;Verwerfen von invaliden Paketen&lt;/h3&gt;

&lt;p&gt;Mit diesem Befehl werden alle eingehende Pakete die nicht dem TCP / IP Format entsprechen verworfen:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -A INPUT --ctstate INVALID -j DROP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;syn-flood-protection&quot;&gt;Syn-Flood Protection&lt;/h3&gt;

&lt;p&gt;Mit diesen Einträgen wird der Überlastung des Servers durch zu viele Anfragen vorgebeugt:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables -N syn_floodiptables -A INPUT -p tcp --syn -j syn_floodiptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
iptables -A syn_flood -j DROP
iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
iptables -A INPUT -p icmp -j DROP
iptables -A OUTPUT -p icmp -j ACCEPT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;abschnitt-5---persistenz&quot;&gt;Abschnitt 5 - Persistenz&lt;/h2&gt;

&lt;p&gt;Die konfigurierten Firewall Regeln sind nicht automatisch persisten gespeichert um dies zu ändern muss das Paket &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;iptables-persistent&lt;/code&gt; nachinstalliert werden.&lt;/p&gt;

&lt;p&gt;Danach kann mit dem Befehl:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;iptables-save &amp;gt; /etc/iptables/rules.v4   # Für IPv4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ip6tables-save &amp;gt; /etc/iptables/rules.v4   # Für IPv6
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Die aktuelle Konfiguration gespeichert werden.&lt;/p&gt;

&lt;h2 id=&quot;abschnitt-6---länder-blockierung&quot;&gt;Abschnitt 6 - Länder Blockierung&lt;/h2&gt;

&lt;p&gt;Mit dem beigefügten Script lassen sich IP Drop Regeln für ganze Länder erstellen.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Hinweis: Die Blockierung beschränkt sich auf IPv4 Adressen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;###PUT HERE SEPARATED LIST OF COUNTRY CODE###&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;COUNTRIES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=(&lt;/span&gt;de at&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;WORKDIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mktemp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#######################################&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;i &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;COUNTRIES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[@]&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;do
&lt;/span&gt;curl http://www.ipdeny.com/ipblocks/data/countries/&lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt;.zone &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$WORKDIR&lt;/span&gt;/iptables-blocklist.txt&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;done
if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$WORKDIR&lt;/span&gt;/iptables-blocklist.txt &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;then
  &lt;/span&gt;iptables &lt;span class=&quot;nt&quot;&gt;-F&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;BLOCKDB&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$WORKDIR&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/iptables-blocklist.txt&quot;&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;IPS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;grep&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-Ev&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;^#&quot;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$BLOCKDB&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;i &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$IPS&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;do
    &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;iptables &lt;span class=&quot;nt&quot;&gt;-A&lt;/span&gt; INPUT &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; DROP &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; input.sh
    &lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;iptables &lt;span class=&quot;nt&quot;&gt;-A&lt;/span&gt; OUTPUT &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; DROP &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; output.sh
  &lt;span class=&quot;k&quot;&gt;done
fi
&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$WORKDIR&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Im oben aufgeführten Script lassen sich die Variablen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COUNTRIES&lt;/code&gt; entsprechend der Länder kürzel abändern. Bei ausführung des Scripts erstellt dieses zwei Dateien &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input.sh&lt;/code&gt; und &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output.sh&lt;/code&gt; darin enthalten sind die benötigen iptables Befehle um die IP Adressen der Länder zu blockieren.&lt;/p&gt;

&lt;h2 id=&quot;zusammenfassung&quot;&gt;Zusammenfassung&lt;/h2&gt;

&lt;p&gt;In diesem Beitrag wurde die Funktionsweise von iptables erläutert. Auserdem wurde mit praktischen Beispielen auf die verschiedenen Möglichkeiten eingegangen um iptables optimal zu nutzen.&lt;/p&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">Einrichtung eines Paketfilters auf Linux</summary></entry><entry><title type="html">Installieren von Windows ohne KVM</title><link href="https://www.brunsch.me/windows-cloud-install" rel="alternate" type="text/html" title="Installieren von Windows ohne KVM" /><published>2020-06-07T00:00:00+00:00</published><updated>2020-06-07T00:00:00+00:00</updated><id>https://www.brunsch.me/windows-cloud-install</id><content type="html" xml:base="https://www.brunsch.me/windows-cloud-install">&lt;h2 id=&quot;installieren-von-windows-auf-dediziertem-server-ohne-kvm-konsole&quot;&gt;Installieren von Windows auf Dediziertem Server ohne KVM Konsole&lt;/h2&gt;

&lt;p&gt;In diesem Tutorial geht es um die Installation eines Windows Betriebssystems auf dedizierter Hardware ohne den gebrauch einer KVM Konsole.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Voraussetzungen&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Einen Dedizierten Server im Rescue System&lt;/li&gt;
  &lt;li&gt;Mehr als 8 GB RAM im Server&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;schritt-1---server-vorbereiten&quot;&gt;Schritt 1 - Server Vorbereiten&lt;/h2&gt;

&lt;p&gt;Sobald sich der Server im Rescue System befindet (Linux x64), muss folgende Software installiert werden.&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;apt update &amp;amp;&amp;amp; apt install qemu-kvm
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Als nächstes muss eine Windows ISO auf den Server übertragen werden. Mögliche Optionen wären:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hochladen per sFTP&lt;/li&gt;
  &lt;li&gt;Einbinden eines SMB / NFS Speichers (Storage Box)&lt;/li&gt;
  &lt;li&gt;Das Herunterladen der ISO von Microsoft / Hetzner&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Auf dem Hetzner Mirror befinden sich auch Windows ISOs (diese können nur vom Hetzner Netz aus heruntergeladen werden):
Windows Server 2019 (ENG): http://mirror.hetzner.de/bootimages/windows/SW_DVD9_Win_Server_STD_CORE_2019_64Bit_English_DC_STD_MLF_X21-96581.ISO&lt;/p&gt;

&lt;p&gt;Windows Server 2016 (ENG): http://mirror.hetzner.de/bootimages/windows/SW_DVD9&lt;em&gt;Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_English&lt;/em&gt;-2_MLF_X21-22843.ISO&lt;/p&gt;

&lt;p&gt;Windows Server 2012 R2 (ENG): http://mirror.hetzner.de/bootimages/windows/SW_DVD5_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_English_Core_MLF_X19-05182.iso&lt;/p&gt;

&lt;p&gt;Anschließend muss die Systemfestplatte noch vorbereitet werden. Hier muss eine Partitionstabelle angelegt werden.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Achtung&lt;/strong&gt; Dabei werden alle Daten der Festplatte gelöscht.
Starten von &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;parted&lt;/code&gt; auf der gewünschten Festplatte:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;parted /dev/sdb
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Erstellen der Partitionstabelle bei Festplatten kleiner 2 TB:&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;mklabel msdos
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Erstellen der Partitionstabelle bei Festplatten größer 2 TB:&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;mklabel gpt
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Das ganze sollte dann in etwa so aussehen:&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;root@rescue ~ #&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;parted /dev/sda
&lt;span class=&quot;go&quot;&gt;GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) [mklabel msdos]
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be
lost. Do you want to continue?
Yes/No? [yes]
(parted) [quit]
Information: You may need to update /etc/fstab.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Alle Eingaben sind mit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[ ]&lt;/code&gt; umrandet&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;schritt-2---herstellen-eines-ssh-tunnels&quot;&gt;Schritt 2 - Herstellen eines SSH Tunnels&lt;/h2&gt;

&lt;p&gt;Um später die installation per VNC durchzuführen wird ein SSH Tunnel benötigt.
Andernfalls ist die installation frei im Internet aufrufbar.&lt;/p&gt;

&lt;p&gt;Unter Linux und Windows mit installiertem OpenSSH genügt es den folgende Befehl lokal auszuführen und sich am Server anzumelden.&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;ssh -L 8888:127.0.0.1:5901 root@your_host
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;schritt-3---starten-der-windows-installation&quot;&gt;Schritt 3 - Starten der Windows Installation&lt;/h2&gt;

&lt;p&gt;Jetzt kann mit der eigentlichen Windows Installation gestartet werden.
Dazu muss nun folgender Befehl (entsprechend abgeändert) auf dem Server ausgeführt werden.&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;qemu-system-x86_64 -enable-kvm -smp 4 -m 4096 -boot d -cdrom en_windows_server_2019_updated_sept_2019_x64_dvd_199664ce.iso -drive file=/dev/sda,format=raw,media=disk -vnc 127.0.0.1:1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Optionen&lt;/th&gt;
      &lt;th&gt; &lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;-smp&lt;/td&gt;
      &lt;td&gt;Anzahl der CPU Kerne&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-m&lt;/td&gt;
      &lt;td&gt;Große des verwendeten RAMs&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-cdrom&lt;/td&gt;
      &lt;td&gt;Pfad zum ISO Image&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-drive&lt;/td&gt;
      &lt;td&gt;Festplatte auf der das System installiert werden soll&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-vnc&lt;/td&gt;
      &lt;td&gt;VNC Server Einstellungen&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Als nächstes kann die Installation per VNC gestartet werden, dazu muss man sich mit einem VNC Viewer der wahl zur folgenden Adresse verbinden.&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;127.0.0.1:8888
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;schritt-4---automatische-ip-konfiguration&quot;&gt;Schritt 4 - Automatische IP Konfiguration&lt;/h2&gt;

&lt;p&gt;Damit wenn der Server von der Windows installation Bootet auch die richtige Netzwerkkonfiguration bekommt, muss ein Scheduled Task angelegt werden der das folgende PowerShell Script ausführt.&lt;/p&gt;

&lt;div class=&quot;language-powershell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;foreach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$Adapter&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Get-NetAdapter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;New-NetIPAddress&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;err&quot;&gt;–&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;IPAddress&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;IPAdresse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-DefaultGateway&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Gateway&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-PrefixLength&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CIDR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-InterfaceIndex&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$Adapter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;InterfaceIndex&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Die Werte in den Klammern müssen entsprechend angepasst werden und das Script sollte dann unter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\script.ps1&lt;/code&gt; abgelegt werden.&lt;/p&gt;

&lt;p&gt;Die Einrichtung des Scheduled Tasks erfolgt anhand dieser Schritte:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Startoptionen festlegen.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;../images/task01.png&quot; alt=&quot;Task 1&quot; /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Aktion Festlegen.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;../images/task02.png&quot; alt=&quot;Task 2&quot; /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;PowerShell optionen eintragen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-ExecutionPolicy Bypass -File C:\script.ps1&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;../images/task03.png&quot; alt=&quot;Task 3&quot; /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Task optionen Übersicht.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;../images/task04.png&quot; alt=&quot;Task 4&quot; /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Sicherheitsoptionen hier sollte Eingestellt werden, dass das Script auch ohne eine Benutzeranmeldung startet.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;../images/task.png&quot; alt=&quot;Task&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;schritt-5---rdp-aktivieren--firewall-deaktivieren&quot;&gt;Schritt 5 - RDP Aktivieren &amp;amp; Firewall Deaktivieren&lt;/h2&gt;

&lt;p&gt;Um später per RDP auf den Server zu verbinden muss diese aktiviert werden:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/RDP.png&quot; alt=&quot;RDP&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Um weitere Fehlerquellen zu minimierern macht es sinn die Windows Firewall vor dem Neustart zu deaktivieren (dies ist aber optional).&lt;/p&gt;

&lt;p&gt;Nun kann Windows heruntergefahren werden und im anschluss der Server neugestartet werden.
Nach ein paar minuten sollte es möglich sein sich per RDP zum Server zu verbinden.&lt;/p&gt;

&lt;h2 id=&quot;schritt-6---script-deaktivieren&quot;&gt;Schritt 6 - Script Deaktivieren&lt;/h2&gt;

&lt;p&gt;Nun sollte der Scheduled Task wieder Deaktiviert werden und die Firewall entsprechend überprüft und wieder eingeschlatet werden.
In den Netzwerkeinstellungen sollten auch noch DNS Server hinterlegt werden, da diese mit dem Script nicht gesetzt wurden.&lt;/p&gt;

&lt;h2 id=&quot;fazit&quot;&gt;Fazit&lt;/h2&gt;

&lt;p&gt;In diesem Tutorial wurde die Installation eines Windows Betriebssystems ohne den einsatz einer KVM Konsole behandelt.&lt;/p&gt;</content><author><name>Markus Brunsch</name></author><summary type="html">Installieren von Windows auf Dediziertem Server ohne KVM Konsole</summary></entry></feed>