From 68ec48c808305302c2fd1122a8ac7ff257969c65 Mon Sep 17 00:00:00 2001 From: Thomas Dannenberg Date: Thu, 4 Sep 2025 10:29:40 +0000 Subject: [PATCH] Kapitel 7/Tutorial.md aktualisiert --- Kapitel 7/Tutorial.md | 343 ++++++++++++++++-------------------------- 1 file changed, 127 insertions(+), 216 deletions(-) diff --git a/Kapitel 7/Tutorial.md b/Kapitel 7/Tutorial.md index a753f46..a5dee66 100644 --- a/Kapitel 7/Tutorial.md +++ b/Kapitel 7/Tutorial.md @@ -1,42 +1,39 @@ -# 🛠️ Kapitel 7 – Nextcloud (Tutorial, Nginx) +# 🛠️ Kapitel 7 – Nextcloud (Nginx + PostgreSQL + Redis, NPM-Setup) ---- +> [!INFO] +> Dieses Kapitel ist eine vorbereitete Rohfassung. Es enthält bereits alle technischen Schritte in korrekter Reihenfolge. Die Blogtexte und Erklärungen folgen später. -## Einleitung +## ✨ Einleitung -Nextcloud ist das Herzstück deiner privaten Cloud. Hier landen Dateien, Fotos, Kalender und Kontakte – ohne Google, ohne Microsoft. In diesem Kapitel installieren wir Nextcloud **in einem LXC-Container unter Proxmox**, setzen auf **PostgreSQL** als Datenbank, **Nginx + PHP-FPM** als Webserver und **Redis** als Cache. Die Benutzerdaten liegen auf einer separaten Festplatte – für Performance, Übersicht und Datensicherheit. +[Platzhalter für Einstiegstext: +Was ist Nextcloud, warum ist es sinnvoll, was kann man damit tun. +Hinweis auf Unabhängigkeit von Google & Co., Einsatz als Streamer, für Teamsharing etc.] ---- +## 📋 Voraussetzungen -## Voraussetzungen +[Platzhalter für grafische Checkliste oder Übersicht: z. B. Screenshot LXC-Übersicht] -* **Proxmox Host** mit 2 Platten (System + Datenplatte) -* **LXC mit Ubuntu 24.04**, Nesting aktiviert -* **Nginx Proxy Manager** für HTTPS-Zugriff -* Eine **Domain**, die auf deinen Proxy zeigt -* Container-Ressourcen: mind. 2 vCPU, 4 GB RAM -* Grundwissen: Proxmox-GUI, SSH, Terminal +- Proxmox-Host mit 2 Platten (System + Daten) +- LXC mit Ubuntu 24.04, „Nesting“ aktiviert +- Nginx Proxy Manager (NPM) läuft bereits +- Domain zeigt korrekt auf den Proxy +- Container-Ressourcen: 2 vCPU, 4–8 GB RAM +- Grundkenntnisse in Proxmox, SSH, Terminal ---- +## ⚙️ LXC-Container anlegen -## Vorbereitung +**In der Proxmox-GUI:** -### LXC-Container erstellen +- CT-Name: `nextcloud` +- Template: `Ubuntu 24.04 LTS` +- CPU: 2+, RAM: 4096+ MB +- „Nesting“ aktivieren (unter „Optionen“) -In der **Proxmox-GUI**: +**Zweite Festplatte direkt einbinden:** -* CT-Name: `nextcloud` -* Template: Ubuntu 24.04 LTS -* CPU: 2+, RAM: 4–8 GB -* **Nesting aktivieren** (unter „Optionen“) - -#### Zweite Festplatte direkt einhängen - -Beim Anlegen im Abschnitt „Disks“: - -* Mount Point: `/mnt/hdd` -* Größe: z. B. `500` GB -* Backup: deaktivieren +- Mount Point: `/mnt/hdd` +- Größe: z. B. `500` GB +- Backup: deaktivieren Nach dem Start: @@ -45,24 +42,26 @@ ssh root@ ls -ld /mnt/hdd ``` -→ Gibt es das Verzeichnis? Dann ist alles korrekt eingebunden. +→ Wenn ein gültiges Verzeichnis erscheint, ist alles korrekt gemountet. ---- +## 📦 System vorbereiten -## Umsetzung - -### System aktualisieren & Pakete installieren +[Platzhalter: Warum update & Basis-Tools wichtig sind] ```bash apt update && apt upgrade -y -apt install -y nginx php-fpm php-gd php-imagick php-intl php-mbstring php-xml \ -php-zip php-curl php-bz2 php-gmp php-pgsql php-redis redis-server \ -postgresql unzip curl +apt install -y curl gnupg2 ca-certificates lsb-release apt-transport-https software-properties-common unzip nano sudo gnupg ``` ---- +## 🌐 Dienste installieren -### Projektstruktur anlegen +[Platzhalter: Hinweis auf explizite PHP-Version, warum kein „php-*“ verwendet wird] + +```bash +apt install -y nginx redis-server postgresql php8.3-fpm php8.3-pgsql php8.3-cli php8.3-common php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip php8.3-curl php8.3-bz2 php8.3-intl php8.3-gmp php8.3-imagick php8.3-redis +``` + +## 📁 Verzeichnisse anlegen ```bash mkdir -p /srv/nextcloud/app @@ -70,165 +69,12 @@ mkdir -p /mnt/hdd/nextcloud_data chown -R www-data:www-data /mnt/hdd/nextcloud_data ``` ---- +## ⚙️ PHP konfigurieren -### Nextcloud herunterladen +### `php.ini` (globale Werte) ```bash -cd /srv/nextcloud/app -curl -LO https://download.nextcloud.com/server/releases/latest.zip -unzip latest.zip && rm latest.zip -chown -R www-data:www-data nextcloud -``` - ---- - -### PostgreSQL: Benutzer & Datenbank - -🔸 WICHTIG: Wir nutzen **nur** `su - postgres`, daher ist **keine Änderung** an `pg_hba.conf` nötig! - -```bash -su - postgres -psql -``` - -Dann in der PostgreSQL-Konsole: - -```sql -CREATE DATABASE nextcloud; -CREATE USER nextcloud WITH PASSWORD 'DEIN_SICHERES_PASSWORT'; -GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud; -\q -``` - -Zurück zur Shell: - -```bash -exit -``` - -Test (optional): - -```bash -psql -U nextcloud -h 127.0.0.1 -d nextcloud -W -``` - -Wenn du Zugriff bekommst → alles korrekt. - ---- - -### PHP-FPM: Version prüfen - -```bash -ls /run/php/ -``` - -→ z. B. `php8.3-fpm.sock` → merken - ---- - -### Nginx konfigurieren - -```bash -nano /etc/nginx/sites-available/nextcloud.conf -``` - -```nginx -server { - listen 80; - server_name _; - - root /srv/nextcloud/app/nextcloud; - index index.php index.html; - - client_max_body_size 10G; - - location = /robots.txt { allow all; log_not_found off; access_log off; } - location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; } - - location ~ \.php(?:$|/) { - fastcgi_split_path_info ^(.+\.php)(/.+)$; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_pass unix:/run/php/php8.3-fpm.sock; # ggf. anpassen - fastcgi_intercept_errors on; - fastcgi_request_buffering off; - } -} -``` - -```bash -ln -s /etc/nginx/sites-available/nextcloud.conf /etc/nginx/sites-enabled/ -nginx -t && systemctl reload nginx -``` - ---- - -### NPM: Proxy Host einrichten - -Im Nginx Proxy Manager: - -* **Domain**: `cloud.deine-domain.tld` -* **IP**: LXC-Adresse (z. B. `10.0.0.42`) -* **Port**: 80 -* **SSL aktivieren** (Let’s Encrypt) -* **Force SSL** + **HTTP/2** aktivieren -* **Advanced Tab** (optional, empfohlen): - -``` -client_max_body_size 10G; -proxy_read_timeout 3600; -proxy_send_timeout 3600; -``` - ---- - -### Browser-Setup - -Im Browser: `https://cloud.deine-domain.tld` - -* Admin-Benutzer erstellen -* Datenverzeichnis: `/mnt/hdd/nextcloud_data` -* Datenbank: PostgreSQL → `127.0.0.1`, DB: `nextcloud`, User: `nextcloud`, Passwort: `DEIN_SICHERES_PASSWORT` - ---- - -### config.php anpassen (Reverse Proxy + Redis) - -```bash -nano /srv/nextcloud/app/nextcloud/config/config.php -``` - -```php -'trusted_domains' => ['cloud.DEINE-DOMAIN.tld'], -'overwrite.cli.url' => 'https://cloud.DEINE-DOMAIN.tld', -'overwritehost' => 'cloud.DEINE-DOMAIN.tld', -'overwriteprotocol' => 'https', -'trusted_proxies' => ['IP.DEINES.NPM'], - -'filelocking.enabled' => true, -'memcache.local' => '\\OC\\Memcache\\Redis', -'memcache.locking' => '\\OC\\Memcache\\Redis', -'redis' => [ - 'host' => '/var/run/redis/redis-server.sock', - 'port' => 0, - 'timeout' => 1.5, -], -``` - -Tipp: `www-data` sollte zur Gruppe `redis` gehören, sonst funktioniert File Locking nicht: - -```bash -usermod -aG redis www-data -``` - ---- - -### PHP anpassen (für große Uploads & Performance) - -```bash -nano /etc/php/*/fpm/php.ini +nano /etc/php/8.3/fpm/php.ini ``` ```ini @@ -236,40 +82,105 @@ upload_max_filesize = 10G post_max_size = 10G memory_limit = 1024M max_execution_time = 3600 -output_buffering = 0 +max_input_time = 3600 date.timezone = Europe/Berlin + +opcache.enable=1 +opcache.memory_consumption=128 +opcache.max_accelerated_files=10000 +opcache.interned_strings_buffer=16 ``` +### `www.conf` (Pool-Konfiguration) + ```bash -systemctl reload php*-fpm +nano /etc/php/8.3/fpm/pool.d/www.conf ``` ---- +```ini +pm = dynamic +pm.max_children = 12 +pm.start_servers = 3 +pm.min_spare_servers = 2 +pm.max_spare_servers = 6 +``` -### Cronjob aktivieren (Nextcloud Hintergrundjobs) +PHP-FPM neu laden: ```bash -crontab -u www-data -e +systemctl reload php8.3-fpm ``` -```cron -*/5 * * * * php -f /srv/nextcloud/app/nextcloud/cron.php +## 🐘 PostgreSQL initialisieren (für LXC) + +```bash +pg_dropcluster 16 main --stop +pg_createcluster 16 main --start +systemctl enable postgresql +systemctl start postgresql +``` + +Zugang zur DB: + +```bash +su - postgres +``` + +Datenbank anlegen: + +```sql +psql +CREATE DATABASE nextcloud; +CREATE USER nextcloud WITH PASSWORD 'DEIN_SICHERES_PASSWORT'; +GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud; +\q +``` + +Dann wieder raus: + +```bash +exit +``` + +## 🔄 Redis konfigurieren + +[Platzhalter: Warum Redis wichtig ist (Caching, File Locking, keine APCu mehr). +Nur lokal via Socket, daher keine Authentifizierung nötig.] + +### Redis-Zugriffsrechte setzen + +```bash +usermod -aG redis www-data +``` + +> [!NOTE] +> Dadurch kann der Webserver-User (`www-data`) auf den Redis-Socket zugreifen. + +### Redis-Konfiguration prüfen + +```bash +nano /etc/redis/redis.conf +``` + +Die folgenden Zeilen sollten gesetzt sein (oder geändert werden): + +```ini +supervised systemd +unixsocket /var/run/redis/redis-server.sock +unixsocketperm 770 +``` + +> [!TIP] +> Weitere Einstellungen wie `bind` oder `requirepass` brauchst du **nicht**, +> solange du Redis **nur lokal über den Socket** nutzt. + +Redis neu starten: + +```bash +systemctl restart redis-server ``` --- -## Ergebnis - -* Nextcloud läuft im LXC, erreichbar via HTTPS -* PostgreSQL-DB ist passwortgesichert & erreichbar -* Daten liegen getrennt unter `/mnt/hdd/nextcloud_data` -* Redis aktiv → keine File-Locking-Warnung -* PHP tuned → große Uploads problemlos -* Hintergrundjobs laufen automatisch - ---- - -## Nächste Schritte - -* Vorheriges Kapitel: Vaultwarden -* Weiter geht’s mit: Affine +Fertig. Jetzt ist Redis bereit für Nextcloud – Caching und Locking funktionieren nach dem Setup automatisch, +wenn wir die Einträge in der `config.php` ergänzen.