feat: update deployment configuration and encrypted env loader
- 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
This commit is contained in:
243
docs/deployment/AUTOSSH-SETUP-COMPLETED.md
Normal file
243
docs/deployment/AUTOSSH-SETUP-COMPLETED.md
Normal file
@@ -0,0 +1,243 @@
|
||||
# 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:
|
||||
```bash
|
||||
/usr/bin/autossh
|
||||
```
|
||||
|
||||
### 2. SSH-Konfiguration erweitert
|
||||
|
||||
Die SSH-Config (`~/.ssh/config`) wurde erweitert mit folgenden Eintr?gen:
|
||||
|
||||
```ssh-config
|
||||
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-Signal
|
||||
- `ServerAliveCountMax 3`: Nach 3 fehlgeschlagenen Versuchen aufgeben
|
||||
- `TCPKeepAlive 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:**
|
||||
```ini
|
||||
[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
|
||||
|
||||
```bash
|
||||
# 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:
|
||||
```bash
|
||||
ssh production "echo 'Connection test successful'"
|
||||
# Output: Connection test successful
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Service-Management
|
||||
|
||||
### Status pr?fen
|
||||
```bash
|
||||
systemctl --user status autossh-production.service
|
||||
```
|
||||
|
||||
### Logs anzeigen
|
||||
```bash
|
||||
journalctl --user -u autossh-production.service -f
|
||||
```
|
||||
|
||||
### Service stoppen
|
||||
```bash
|
||||
systemctl --user stop autossh-production.service
|
||||
```
|
||||
|
||||
### Service neu starten
|
||||
```bash
|
||||
systemctl --user restart autossh-production.service
|
||||
```
|
||||
|
||||
### Service deaktivieren
|
||||
```bash
|
||||
systemctl --user disable autossh-production.service
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Funktionsweise
|
||||
|
||||
Autossh ?berwacht die SSH-Verbindung kontinuierlich:
|
||||
|
||||
1. **Monitoring-Port**: Port 20000 wird genutzt, um die Verbindung zu ?berwachen
|
||||
2. **Keep-Alive**: Alle 60 Sekunden wird ein Keep-Alive-Signal gesendet
|
||||
3. **Automatischer Neustart**: Bei Verbindungsabbruch wird die Verbindung automatisch neu aufgebaut
|
||||
4. **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`
|
||||
```bash
|
||||
# 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:
|
||||
```bash
|
||||
sudo loginctl enable-linger $USER
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## N?chste Schritte
|
||||
|
||||
### F?r weitere Server
|
||||
Das Setup-Script kann f?r weitere Server verwendet werden:
|
||||
```bash
|
||||
./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):
|
||||
```bash
|
||||
# Lokalen Port weiterleiten
|
||||
autossh -M 20002 -N -L 8080:localhost:80 production
|
||||
```
|
||||
|
||||
### Monitoring
|
||||
Regelm??ig den Service-Status ?berpr?fen:
|
||||
```bash
|
||||
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:
|
||||
|
||||
```bash
|
||||
# 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.
|
||||
428
docs/deployment/AUTOSSH-SETUP.md
Normal file
428
docs/deployment/AUTOSSH-SETUP.md
Normal file
@@ -0,0 +1,428 @@
|
||||
# Autossh Setup - Persistente SSH-Verbindungen
|
||||
|
||||
**Status**: ? Ready
|
||||
**Last Updated**: 2025-01-31
|
||||
**Purpose**: Automatische ?berwachung und Neustart von SSH-Verbindungen zum Production-Server
|
||||
|
||||
---
|
||||
|
||||
## ?bersicht
|
||||
|
||||
Autossh ist ein Tool, das SSH-Verbindungen automatisch ?berwacht und neu aufbaut, wenn sie abbrechen. Dies ist besonders n?tzlich f?r:
|
||||
- SSH-Tunnel zu entfernten Servern
|
||||
- Persistente SSH-Verbindungen f?r Ansible/CI/CD
|
||||
- Automatische Verbindungswiederherstellung nach Netzwerkunterbrechungen
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
### Linux (Ubuntu/Debian)
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install autossh
|
||||
```
|
||||
|
||||
### macOS
|
||||
|
||||
```bash
|
||||
brew install autossh
|
||||
```
|
||||
|
||||
### WSL2 / Windows
|
||||
|
||||
Autossh ist normalerweise ?ber das Linux-Subsystem verf?gbar. Falls nicht:
|
||||
|
||||
```bash
|
||||
# In WSL2
|
||||
sudo apt update
|
||||
sudo apt install autossh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Konfiguration
|
||||
|
||||
### Schritt 1: SSH-Config erweitern
|
||||
|
||||
Erweitere deine `~/.ssh/config` mit Keep-Alive und ServerAliveInterval Optionen:
|
||||
|
||||
```bash
|
||||
# Edit SSH config
|
||||
nano ~/.ssh/config
|
||||
```
|
||||
|
||||
F?ge folgende Konfiguration hinzu:
|
||||
|
||||
```
|
||||
# Production Server - Persistent Connection
|
||||
Host production
|
||||
HostName 94.16.110.151
|
||||
User deploy
|
||||
IdentityFile ~/.ssh/production
|
||||
ServerAliveInterval 60
|
||||
ServerAliveCountMax 3
|
||||
TCPKeepAlive yes
|
||||
Compression yes
|
||||
StrictHostKeyChecking accept-new
|
||||
|
||||
# Git Server - Persistent Connection
|
||||
Host git.michaelschiemer.de
|
||||
HostName git.michaelschiemer.de
|
||||
Port 2222
|
||||
User git
|
||||
IdentityFile ~/.ssh/git_michaelschiemer
|
||||
ServerAliveInterval 60
|
||||
ServerAliveCountMax 3
|
||||
TCPKeepAlive yes
|
||||
Compression yes
|
||||
StrictHostKeyChecking no
|
||||
UserKnownHostsFile /dev/null
|
||||
```
|
||||
|
||||
**Wichtige Optionen:**
|
||||
- `ServerAliveInterval 60`: Sendet alle 60 Sekunden ein Keep-Alive-Signal
|
||||
- `ServerAliveCountMax 3`: Gibt nach 3 fehlgeschlagenen Keep-Alive-Versuchen auf
|
||||
- `TCPKeepAlive yes`: Nutzt TCP Keep-Alive f?r zus?tzliche Persistenz
|
||||
|
||||
### Schritt 2: Autossh als Service einrichten
|
||||
|
||||
#### Option A: Systemd Service (Linux/WSL2)
|
||||
|
||||
Erstelle einen systemd Service f?r autossh:
|
||||
|
||||
```bash
|
||||
# Create systemd service directory
|
||||
mkdir -p ~/.config/systemd/user
|
||||
|
||||
# Create service file
|
||||
nano ~/.config/systemd/user/autossh-production.service
|
||||
```
|
||||
|
||||
Service-Datei Inhalt:
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=AutoSSH for Production Server
|
||||
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 Hinweise:**
|
||||
- `-M 20000`: Monitoring-Port (nur Port-Nummer, nicht IP:Port!)
|
||||
- `-N`: Keine Remote-Commands (nur persistente Verbindung)
|
||||
- **Kein `-f` Flag**: Bei systemd Type=simple wird `-f` nicht ben?tigt, da systemd die Background-Operation ?bernimmt
|
||||
|
||||
**Service aktivieren:**
|
||||
|
||||
```bash
|
||||
# Reload systemd user services
|
||||
systemctl --user daemon-reload
|
||||
|
||||
# Enable service (startet automatisch beim Login)
|
||||
systemctl --user enable autossh-production.service
|
||||
|
||||
# Start service
|
||||
systemctl --user start autossh-production.service
|
||||
|
||||
# Check status
|
||||
systemctl --user status autossh-production.service
|
||||
|
||||
# View logs
|
||||
journalctl --user -u autossh-production.service -f
|
||||
```
|
||||
|
||||
#### Option B: Manuelle Autossh-Verbindung
|
||||
|
||||
F?r manuelle/tempor?re Verbindungen:
|
||||
|
||||
```bash
|
||||
# Start autossh mit Monitoring-Port
|
||||
autossh -M 20000 -N -f -o "ServerAliveInterval=60" -o "ServerAliveCountMax=3" production
|
||||
|
||||
# Check if running
|
||||
ps aux | grep autossh
|
||||
|
||||
# Stop autossh
|
||||
pkill autossh
|
||||
```
|
||||
|
||||
**Parameter-Erkl?rung:**
|
||||
- `-M 20000`: Monitoring-Port (autossh nutzt diesen zum Health-Check)
|
||||
- `-N`: Keine Remote-Commands ausf?hren (nur Tunnel)
|
||||
- `-f`: Im Hintergrund laufen
|
||||
- `-o "ServerAliveInterval=60"`: SSH Keep-Alive alle 60 Sekunden
|
||||
- `-o "ServerAliveCountMax=3"`: Nach 3 Fehlversuchen aufgeben
|
||||
|
||||
#### Option C: SSH-Tunnel mit Autossh
|
||||
|
||||
F?r SSH-Tunnel (z.B. Port-Forwarding):
|
||||
|
||||
```bash
|
||||
# Forward local port 8080 to remote 80
|
||||
autossh -M 20000 -N -f -L 8080:localhost:80 production
|
||||
|
||||
# Forward remote port 3306 to local
|
||||
autossh -M 20000 -N -f -R 3306:localhost:3306 production
|
||||
|
||||
# Check tunnel
|
||||
ps aux | grep autossh
|
||||
ss -tuln | grep 8080
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Testing
|
||||
|
||||
### Verbindung testen
|
||||
|
||||
```bash
|
||||
# Test normal SSH
|
||||
ssh production "echo 'Connection successful'"
|
||||
|
||||
# Test autossh connection
|
||||
autossh -M 20000 -v -N -o "ServerAliveInterval=60" production
|
||||
|
||||
# Check if autossh is monitoring
|
||||
ps aux | grep autossh
|
||||
netstat -tuln | grep 20000
|
||||
```
|
||||
|
||||
### Verbindungsstatus ?berwachen
|
||||
|
||||
```bash
|
||||
# Check active SSH connections
|
||||
ssh production "who"
|
||||
|
||||
# Check autossh process
|
||||
ps aux | grep autossh
|
||||
|
||||
# Check systemd service status
|
||||
systemctl --user status autossh-production.service
|
||||
|
||||
# View logs
|
||||
journalctl --user -u autossh-production.service --since "10 minutes ago"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Autossh startet nicht
|
||||
|
||||
**Problem**: Autossh-Process startet nicht oder crasht sofort
|
||||
|
||||
**L?sung**:
|
||||
```bash
|
||||
# Test SSH-Verbindung manuell
|
||||
ssh -v production "echo test"
|
||||
|
||||
# Test autossh mit verbose logging
|
||||
autossh -M 20000 -v -N production
|
||||
|
||||
# Pr?fe SSH-Config
|
||||
ssh -F ~/.ssh/config production "echo test"
|
||||
|
||||
# Pr?fe Berechtigungen
|
||||
ls -la ~/.ssh/production
|
||||
chmod 600 ~/.ssh/production
|
||||
```
|
||||
|
||||
### Verbindung bricht trotzdem ab
|
||||
|
||||
**Problem**: Verbindung bricht auch mit autossh regelm??ig ab
|
||||
|
||||
**L?sung**:
|
||||
1. **Erh?he Keep-Alive-Interval:**
|
||||
```bash
|
||||
# In ~/.ssh/config
|
||||
ServerAliveInterval 30
|
||||
ServerAliveCountMax 10
|
||||
```
|
||||
|
||||
2. **Pr?fe Netzwerk/Firewall:**
|
||||
```bash
|
||||
# Test network connectivity
|
||||
ping 94.16.110.151
|
||||
|
||||
# Test SSH port
|
||||
nc -zv 94.16.110.151 22
|
||||
```
|
||||
|
||||
3. **Pr?fe Server-Konfiguration:**
|
||||
```bash
|
||||
# Auf dem Server pr?fen
|
||||
ssh production "cat /etc/ssh/sshd_config | grep -E 'ClientAlive|TCPKeepAlive'"
|
||||
```
|
||||
|
||||
### Port-Konflikte
|
||||
|
||||
**Problem**: Monitoring-Port (20000) ist bereits belegt
|
||||
|
||||
**L?sung**:
|
||||
```bash
|
||||
# W?hle einen anderen Port
|
||||
autossh -M 20001 -N -f production
|
||||
|
||||
# Oder nutze einen zuf?lligen Port
|
||||
autossh -M 0 -N -f production # 0 = random port
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Best Practices
|
||||
|
||||
### 1. Monitoring-Port anpassen
|
||||
|
||||
Wenn mehrere autossh-Instanzen laufen, nutze verschiedene Monitoring-Ports:
|
||||
|
||||
```bash
|
||||
# Production Server
|
||||
autossh -M 20000 -N -f production
|
||||
|
||||
# Git Server
|
||||
autossh -M 20001 -N -f git.michaelschiemer.de
|
||||
```
|
||||
|
||||
### 2. Systemd Service f?r Produktivit?t
|
||||
|
||||
Nutze systemd Services f?r automatischen Start:
|
||||
|
||||
```bash
|
||||
# Enable lingering f?r user services
|
||||
sudo loginctl enable-linger $USER
|
||||
|
||||
# Services starten beim Boot
|
||||
systemctl --user enable autossh-production.service
|
||||
```
|
||||
|
||||
### 3. Logging konfigurieren
|
||||
|
||||
F?r besseres Debugging:
|
||||
|
||||
```bash
|
||||
# Systemd service mit logging
|
||||
[Service]
|
||||
ExecStart=/usr/bin/autossh -M 20000 -v -N -o "ServerAliveInterval=60" -o "LogLevel=DEBUG" production
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
```
|
||||
|
||||
### 4. Automatischer Neustart
|
||||
|
||||
Systemd Service startet automatisch neu, aber f?r manuelle Instanzen:
|
||||
|
||||
```bash
|
||||
# Mit automatischem Restart
|
||||
while true; do
|
||||
autossh -M 20000 -N production || sleep 10
|
||||
done
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Integration mit Ansible
|
||||
|
||||
Autossh kann auch f?r Ansible-Verbindungen genutzt werden:
|
||||
|
||||
```yaml
|
||||
# ansible.cfg
|
||||
[defaults]
|
||||
transport = ssh
|
||||
pipelining = True
|
||||
ssh_args = -o ServerAliveInterval=60 -o ServerAliveCountMax=3
|
||||
control_path = ~/.ansible/cp/%%h-%%p-%%r
|
||||
```
|
||||
|
||||
Oder nutze die SSH-Config direkt (empfohlen):
|
||||
|
||||
```bash
|
||||
# ~/.ssh/config ist bereits f?r Ansible nutzbar
|
||||
ansible production -m ping
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Sicherheitshinweise
|
||||
|
||||
1. **SSH-Keys sch?tzen:**
|
||||
```bash
|
||||
chmod 600 ~/.ssh/production
|
||||
chmod 644 ~/.ssh/production.pub
|
||||
```
|
||||
|
||||
2. **Monitoring-Port absichern:**
|
||||
```bash
|
||||
# Monitoring-Port nur lokal verf?gbar
|
||||
autossh -M 127.0.0.1:20000 -N -f production
|
||||
```
|
||||
|
||||
3. **Keine Passw?rter:**
|
||||
- Nutze immer SSH-Keys
|
||||
- Keine Passw?rter in autossh-Commands
|
||||
|
||||
---
|
||||
|
||||
## Quick Reference
|
||||
|
||||
### Makefile-Befehle
|
||||
|
||||
```bash
|
||||
# SSH-Verbindung zum Production-Server
|
||||
make ssh
|
||||
# oder
|
||||
make ssh-production
|
||||
|
||||
# SSH-Verbindung zum Git-Server
|
||||
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
|
||||
```
|
||||
|
||||
### Manuelle Befehle
|
||||
|
||||
```bash
|
||||
# Service starten
|
||||
systemctl --user start autossh-production.service
|
||||
|
||||
# Service stoppen
|
||||
systemctl --user stop autossh-production.service
|
||||
|
||||
# Service Status
|
||||
systemctl --user status autossh-production.service
|
||||
|
||||
# Logs anzeigen
|
||||
journalctl --user -u autossh-production.service -f
|
||||
|
||||
# Manuelle Verbindung (ohne systemd)
|
||||
autossh -M 20000 -N -f production
|
||||
|
||||
# Verbindung beenden
|
||||
pkill autossh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Weitere Ressourcen
|
||||
|
||||
- [Autossh Manual](https://www.harding.motd.ca/autossh/)
|
||||
- [SSH Keep-Alive Documentation](https://www.ssh.com/academy/ssh/config)
|
||||
- [Systemd User Services](https://wiki.archlinux.org/title/Systemd/User)
|
||||
319
docs/deployment/SSH-MAKEFILE-COMMANDS.md
Normal file
319
docs/deployment/SSH-MAKEFILE-COMMANDS.md
Normal file
@@ -0,0 +1,319 @@
|
||||
# SSH Makefile-Befehle
|
||||
|
||||
**Datum**: 2025-11-02
|
||||
**Status**: ? Verf?gbar
|
||||
**Zweck**: Einfache SSH-Verbindungen ?ber Makefile-Befehle
|
||||
|
||||
---
|
||||
|
||||
## ?bersicht
|
||||
|
||||
Das Projekt bietet Makefile-Befehle f?r SSH-Verbindungen zum Production- und Git-Server. Diese nutzen die konfigurierte SSH-Config (`~/.ssh/config`) und autossh f?r persistente Verbindungen.
|
||||
|
||||
---
|
||||
|
||||
## Verf?gbare Befehle
|
||||
|
||||
### `make ssh` oder `make ssh-production`
|
||||
|
||||
?ffnet eine SSH-Verbindung zum Production-Server.
|
||||
|
||||
```bash
|
||||
make ssh
|
||||
```
|
||||
|
||||
**Was passiert:**
|
||||
- Nutzt die SSH-Config (`~/.ssh/config`) mit dem `production` Host
|
||||
- Verbindet zu `94.16.110.151` als User `deploy`
|
||||
- Nutzt den SSH-Schl?ssel `~/.ssh/production`
|
||||
- Keep-Alive aktiviert (ServerAliveInterval 60)
|
||||
|
||||
**Beispiel:**
|
||||
```bash
|
||||
$ make ssh
|
||||
?? Verbinde zum Production-Server...
|
||||
Welcome to Ubuntu...
|
||||
deploy@production:~$
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `make ssh-git`
|
||||
|
||||
?ffnet eine SSH-Verbindung zum Git-Server.
|
||||
|
||||
```bash
|
||||
make ssh-git
|
||||
```
|
||||
|
||||
**Was passiert:**
|
||||
- Nutzt die SSH-Config mit dem `git.michaelschiemer.de` Host
|
||||
- Verbindet zu `git.michaelschiemer.de` Port 2222 als User `git`
|
||||
- Nutzt den SSH-Schl?ssel `~/.ssh/git_michaelschiemer`
|
||||
|
||||
---
|
||||
|
||||
### `make ssh-status`
|
||||
|
||||
Pr?ft den Status der autossh-Services.
|
||||
|
||||
```bash
|
||||
make ssh-status
|
||||
```
|
||||
|
||||
**Ausgabe:**
|
||||
```bash
|
||||
?? Pr?fe autossh 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.8M
|
||||
|
||||
michael 35533 0.0 0.0 2484 1536 ? Ss 18:21 0:00 /usr/lib/autossh/autossh -M 20000 -N -o ServerAliveInterval=60 -o ServerAliveCountMax=3 production
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `make ssh-logs`
|
||||
|
||||
Zeigt die Logs der autossh-Services an.
|
||||
|
||||
```bash
|
||||
make ssh-logs
|
||||
```
|
||||
|
||||
**Ausgabe:**
|
||||
```bash
|
||||
?? Zeige autossh Logs...
|
||||
Nov 02 18:21:06 Mike-PC systemd[19787]: Started autossh-production.service - AutoSSH for production.
|
||||
Nov 02 18:21:06 Mike-PC autossh[35533]: short poll time: adjusting net timeouts to 5000
|
||||
Nov 02 18:21:06 Mike-PC autossh[35533]: starting ssh (count 1)
|
||||
Nov 02 18:21:06 Mike-PC autossh[35533]: ssh child pid is 35537
|
||||
```
|
||||
|
||||
**F?r Live-Logs:**
|
||||
```bash
|
||||
journalctl --user -u autossh-production.service -f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `make setup-autossh`
|
||||
|
||||
Richtet autossh f?r persistente SSH-Verbindungen ein.
|
||||
|
||||
```bash
|
||||
make setup-autossh
|
||||
```
|
||||
|
||||
**Was passiert:**
|
||||
- F?hrt das Setup-Script aus (`scripts/setup-autossh.sh both`)
|
||||
- Erweitert SSH-Config mit Keep-Alive-Optionen
|
||||
- Erstellt systemd Services f?r Production- und Git-Server
|
||||
- Testet SSH-Verbindungen
|
||||
|
||||
**Siehe auch:** `docs/deployment/AUTOSSH-SETUP.md`
|
||||
|
||||
---
|
||||
|
||||
## SSH-Config
|
||||
|
||||
Die Makefile-Befehle nutzen die SSH-Config (`~/.ssh/config`):
|
||||
|
||||
### Production-Server
|
||||
|
||||
```ssh-config
|
||||
Host production
|
||||
HostName 94.16.110.151
|
||||
User deploy
|
||||
IdentityFile ~/.ssh/production
|
||||
ServerAliveInterval 60
|
||||
ServerAliveCountMax 3
|
||||
TCPKeepAlive yes
|
||||
Compression yes
|
||||
StrictHostKeyChecking accept-new
|
||||
```
|
||||
|
||||
### Git-Server
|
||||
|
||||
```ssh-config
|
||||
Host git.michaelschiemer.de
|
||||
HostName git.michaelschiemer.de
|
||||
Port 2222
|
||||
User git
|
||||
IdentityFile ~/.ssh/git_michaelschiemer
|
||||
ServerAliveInterval 60
|
||||
ServerAliveCountMax 3
|
||||
TCPKeepAlive yes
|
||||
Compression yes
|
||||
StrictHostKeyChecking no
|
||||
UserKnownHostsFile /dev/null
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Erweiterte Nutzung
|
||||
|
||||
### SSH mit zus?tzlichen Befehlen
|
||||
|
||||
Du kannst auch direkt `ssh` mit zus?tzlichen Befehlen verwenden:
|
||||
|
||||
```bash
|
||||
# Remote-Befehl ausf?hren
|
||||
ssh production "docker ps"
|
||||
|
||||
# SSH-Tunnel erstellen
|
||||
ssh production -L 8080:localhost:80 -N
|
||||
|
||||
# Datei kopieren (SCP)
|
||||
scp production:/path/to/file ./local-file
|
||||
|
||||
# Datei hochladen
|
||||
scp ./local-file production:/path/to/file
|
||||
```
|
||||
|
||||
### Mit dem Production-Server arbeiten
|
||||
|
||||
```bash
|
||||
# Docker-Container Status pr?fen
|
||||
make ssh
|
||||
# Dann im SSH:
|
||||
docker ps
|
||||
cd /var/www/html && docker compose ps
|
||||
|
||||
# Logs anzeigen
|
||||
cd ~/deployment/stacks/application && docker compose logs -f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### SSH-Verbindung schl?gt fehl
|
||||
|
||||
**Problem**: `make ssh` verbindet nicht
|
||||
|
||||
**L?sung**:
|
||||
1. Pr?fe SSH-Config:
|
||||
```bash
|
||||
cat ~/.ssh/config | grep -A 10 "Host production"
|
||||
```
|
||||
|
||||
2. Teste Verbindung manuell:
|
||||
```bash
|
||||
ssh -v production
|
||||
```
|
||||
|
||||
3. Pr?fe SSH-Schl?ssel:
|
||||
```bash
|
||||
ls -la ~/.ssh/production
|
||||
```
|
||||
|
||||
4. Teste mit IP-Adresse:
|
||||
```bash
|
||||
ssh -i ~/.ssh/production deploy@94.16.110.151
|
||||
```
|
||||
|
||||
### Autossh l?uft nicht
|
||||
|
||||
**Problem**: `make ssh-status` zeigt Service als inaktiv
|
||||
|
||||
**L?sung**:
|
||||
1. Service starten:
|
||||
```bash
|
||||
systemctl --user start autossh-production.service
|
||||
```
|
||||
|
||||
2. Service aktivieren:
|
||||
```bash
|
||||
systemctl --user enable autossh-production.service
|
||||
```
|
||||
|
||||
3. Autossh neu einrichten:
|
||||
```bash
|
||||
make setup-autossh
|
||||
```
|
||||
|
||||
### Verbindung bricht regelm??ig ab
|
||||
|
||||
**Problem**: SSH-Verbindung bricht auch mit autossh ab
|
||||
|
||||
**L?sung**:
|
||||
1. Pr?fe autossh Status:
|
||||
```bash
|
||||
make ssh-status
|
||||
```
|
||||
|
||||
2. Pr?fe Logs:
|
||||
```bash
|
||||
make ssh-logs
|
||||
```
|
||||
|
||||
3. Teste Keep-Alive:
|
||||
```bash
|
||||
ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=10 production
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Weitere SSH-Befehle im Makefile
|
||||
|
||||
Es gibt weitere SSH-bezogene Befehle im Makefile:
|
||||
|
||||
```bash
|
||||
# Production-Container neu starten
|
||||
make restart-production
|
||||
|
||||
# Production-Logs anzeigen
|
||||
make logs-production
|
||||
make logs-staging
|
||||
|
||||
# Production-Status pr?fen
|
||||
make status-production
|
||||
```
|
||||
|
||||
**Siehe auch:** `make help` f?r alle verf?gbaren Befehle
|
||||
|
||||
---
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Nutze `make ssh` statt direkter SSH-Befehle**:
|
||||
Dies stellt sicher, dass die korrekte Konfiguration verwendet wird.
|
||||
|
||||
2. **Pr?fe regelm??ig den autossh-Status**:
|
||||
```bash
|
||||
make ssh-status
|
||||
```
|
||||
|
||||
3. **Nutze SSH-Config statt direkter IPs**:
|
||||
Nutze `ssh production` statt `ssh deploy@94.16.110.151`
|
||||
|
||||
4. **Pr?fe Logs bei Problemen**:
|
||||
```bash
|
||||
make ssh-logs
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Referenzen
|
||||
|
||||
- **Autossh Setup**: `docs/deployment/AUTOSSH-SETUP.md`
|
||||
- **Autossh Setup Abgeschlossen**: `docs/deployment/AUTOSSH-SETUP-COMPLETED.md`
|
||||
- **Setup-Script**: `scripts/setup-autossh.sh`
|
||||
- **SSH-Config**: `~/.ssh/config`
|
||||
- **Makefile**: `Makefile`
|
||||
|
||||
---
|
||||
|
||||
## Zusammenfassung
|
||||
|
||||
? Makefile-Befehle f?r SSH-Verbindungen verf?gbar
|
||||
? Einfache Verbindung zum Production-Server: `make ssh`
|
||||
? Service-Status pr?fen: `make ssh-status`
|
||||
? Logs anzeigen: `make ssh-logs`
|
||||
? Autossh einrichten: `make setup-autossh`
|
||||
|
||||
Alle Befehle nutzen die konfigurierte SSH-Config und autossh f?r persistente Verbindungen.
|
||||
@@ -303,14 +303,20 @@ php console.php ssl:test
|
||||
|
||||
## Environment File Hierarchy
|
||||
|
||||
**New Base + Override Pattern (Development):**
|
||||
```
|
||||
.env.example # Template with placeholders
|
||||
.env # Development (local, debug enabled)
|
||||
.env.staging # Staging (production-like, staging SSL)
|
||||
.env.production # Production (this template)
|
||||
.env.example # Template with placeholders (documentation)
|
||||
.env.base # Shared variables for all environments (versioned)
|
||||
.env.local # Local development overrides (gitignored)
|
||||
.env.staging # Staging-specific overrides (optional, gitignored)
|
||||
.env.production # Production (generated by Ansible - this template)
|
||||
```
|
||||
|
||||
**Load Priority**: `.env.production` > `.env` > Environment Variables > Defaults
|
||||
**Production Load Priority**: Docker ENV vars → `.env.production` (generated by Ansible) → Environment Variables → Defaults
|
||||
|
||||
**Development Load Priority**: `.env.base` → `.env.local` → System ENV vars
|
||||
|
||||
**Note**: Framework automatically loads `.env.base` + `.env.local` in development. For production, Ansible generates `.env.production` with `*_FILE` pattern for Docker Secrets.
|
||||
|
||||
## Docker Compose Integration
|
||||
|
||||
|
||||
Reference in New Issue
Block a user