- Update Ansible playbooks and roles for application deployment - Add new Gitea/Traefik troubleshooting playbooks - Update Docker Compose configurations (base, local, staging, production) - Enhance EncryptedEnvLoader with improved error handling - Add deployment scripts (autossh setup, migration, secret testing) - Update CI/CD workflows and documentation - Add Semaphore stack configuration
5.7 KiB
Autossh Setup - Abgeschlossen
Datum: 2025-11-02
Status: ? Erfolgreich konfiguriert
Server: Production (94.16.110.151)
Durchgef?hrte Schritte
1. Installation von Autossh
Autossh war bereits auf dem System installiert:
/usr/bin/autossh
2. SSH-Konfiguration erweitert
Die SSH-Config (~/.ssh/config) wurde erweitert mit folgenden Eintr?gen:
Host production
HostName 94.16.110.151
User deploy
IdentityFile ~/.ssh/production
ServerAliveInterval 60
ServerAliveCountMax 3
TCPKeepAlive yes
Compression yes
StrictHostKeyChecking accept-new
Wichtige Optionen:
ServerAliveInterval 60: Sendet alle 60 Sekunden ein Keep-Alive-SignalServerAliveCountMax 3: Nach 3 fehlgeschlagenen Versuchen aufgebenTCPKeepAlive yes: Nutzt TCP Keep-Alive f?r zus?tzliche Persistenz
3. Systemd Service erstellt
Systemd Service wurde erstellt unter:
~/.config/systemd/user/autossh-production.service
Service-Konfiguration:
[Unit]
Description=AutoSSH for production
After=network.target
[Service]
Type=simple
Environment="AUTOSSH_GATETIME=0"
Environment="AUTOSSH_POLL=10"
ExecStart=/usr/bin/autossh -M 20000 -N -o "ServerAliveInterval=60" -o "ServerAliveCountMax=3" production
Restart=always
RestartSec=10
[Install]
WantedBy=default.target
Wichtige Parameter:
-M 20000: Monitoring-Port (autossh nutzt diesen zur Verbindungs?berwachung)-N: Keine Remote-Commands ausf?hren (nur persistente Verbindung)AUTOSSH_GATETIME=0: Keine Wartezeit nach Start (sofortige Verbindung)AUTOSSH_POLL=10: Polling-Intervall in Sekunden
Hinweis: Das -f Flag wurde entfernt, da es mit systemd Type=simple nicht kompatibel ist.
4. Service aktiviert und gestartet
# Service aktivieren (startet automatisch beim Login)
systemctl --user enable autossh-production.service
# Service starten
systemctl --user start autossh-production.service
5. Status ?berpr?ft
Service Status:
? autossh-production.service - AutoSSH for production
Loaded: loaded (/home/michael/.config/systemd/user/autossh-production.service; enabled; preset: enabled)
Active: active (running) since Sun 2025-11-02 18:21:06 CET
Main PID: 35533 (autossh)
Tasks: 2 (limit: 14999)
Memory: 1.7M
Laufende Prozesse:
- Autossh Main Process: PID 35533
- SSH Connection Process: PID 35537
Verbindungstest
SSH-Verbindung erfolgreich getestet:
ssh production "echo 'Connection test successful'"
# Output: Connection test successful
Service-Management
Status pr?fen
systemctl --user status autossh-production.service
Logs anzeigen
journalctl --user -u autossh-production.service -f
Service stoppen
systemctl --user stop autossh-production.service
Service neu starten
systemctl --user restart autossh-production.service
Service deaktivieren
systemctl --user disable autossh-production.service
Funktionsweise
Autossh ?berwacht die SSH-Verbindung kontinuierlich:
- Monitoring-Port: Port 20000 wird genutzt, um die Verbindung zu ?berwachen
- Keep-Alive: Alle 60 Sekunden wird ein Keep-Alive-Signal gesendet
- Automatischer Neustart: Bei Verbindungsabbruch wird die Verbindung automatisch neu aufgebaut
- Systemd Integration: Bei Service-Fehler startet systemd den Service nach 10 Sekunden neu
Bekannte Probleme & L?sungen
Problem 1: Monitoring-Port Format
Fehler: invalid port "127.0.0.1"
L?sung: -M Parameter sollte nur die Port-Nummer sein, nicht IP:Port
# Falsch:
-M 127.0.0.1:20000
# Richtig:
-M 20000
Problem 2: -f Flag mit systemd
Fehler: Service startet, beendet sich aber sofort
L?sung: -f Flag entfernen bei systemd Type=simple (systemd ?bernimmt Background-Operation)
Problem 3: Service startet nicht automatisch
L?sung: User lingering aktivieren f?r automatischen Start ohne Login:
sudo loginctl enable-linger $USER
N?chste Schritte
F?r weitere Server
Das Setup-Script kann f?r weitere Server verwendet werden:
./scripts/setup-autossh.sh production # Nur Production
./scripts/setup-autossh.sh git # Nur Git Server
./scripts/setup-autossh.sh both # Beide
SSH-Tunnel einrichten
Falls SSH-Tunnel ben?tigt werden (z.B. Port-Forwarding):
# Lokalen Port weiterleiten
autossh -M 20002 -N -L 8080:localhost:80 production
Monitoring
Regelm??ig den Service-Status ?berpr?fen:
systemctl --user status autossh-production.service
journalctl --user -u autossh-production.service --since "1 hour ago"
Makefile-Befehle
Das Projekt bietet jetzt folgende Makefile-Befehle f?r SSH-Verbindungen:
# SSH-Verbindung zum Production-Server ?ffnen
make ssh
# oder
make ssh-production
# SSH-Verbindung zum Git-Server ?ffnen
make ssh-git
# Status der autossh-Services pr?fen
make ssh-status
# Logs der autossh-Services anzeigen
make ssh-logs
# Autossh einrichten
make setup-autossh
Referenzen
- Setup-Script:
scripts/setup-autossh.sh - Dokumentation:
docs/deployment/AUTOSSH-SETUP.md - SSH-Config:
~/.ssh/config - Service-Datei:
~/.config/systemd/user/autossh-production.service - Makefile:
Makefile(Befehle:ssh,ssh-status,ssh-logs,setup-autossh)
Zusammenfassung
? Autossh erfolgreich installiert
? SSH-Config mit Keep-Alive-Optionen erweitert
? Systemd Service erstellt und konfiguriert
? Service aktiviert und gestartet
? Verbindungstest erfolgreich
? Automatischer Neustart bei Verbindungsabbruch aktiviert
Die SSH-Verbindung zum Production-Server wird jetzt automatisch ?berwacht und bei Abbruch neu aufgebaut.