initial working
This commit is contained in:
311
README.md
Normal file
311
README.md
Normal file
@@ -0,0 +1,311 @@
|
||||
# Proxmox HA Cluster Setup
|
||||
|
||||
Setup automatico di un cluster HA a 2 nodi su Proxmox per applicazioni Python con:
|
||||
- MySQL (su VM1)
|
||||
- Redis Master-Slave
|
||||
- 3 Orchestratori
|
||||
- 2 FTP Server in HA
|
||||
- HAProxy + Keepalived per VIP
|
||||
- Promtail per log shipping a Loki
|
||||
|
||||
## Architettura
|
||||
|
||||
```
|
||||
VM1 (192.168.1.10) PRIMARY VM2 (192.168.1.11) SECONDARY
|
||||
├── MySQL ├── Redis Slave
|
||||
├── Redis Master ├── Orchestrator 2
|
||||
├── Orchestrator 1 ├── Orchestrator 3
|
||||
├── FTP Server 1 ├── FTP Server 2
|
||||
├── HAProxy (MASTER) ├── HAProxy (BACKUP)
|
||||
└── Keepalived (priority 100) └── Keepalived (priority 50)
|
||||
|
||||
VIP: 192.168.1.100
|
||||
```
|
||||
|
||||
## Prerequisiti
|
||||
|
||||
- Proxmox VE installato e configurato
|
||||
- Accesso SSH al nodo Proxmox
|
||||
- Chiave SSH pubblica per accesso alle VM
|
||||
- Rete configurata (192.168.1.0/24 nell'esempio)
|
||||
- Server Loki/Grafana (192.168.1.200)
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Configurazione
|
||||
|
||||
Modifica `scripts/provision-ha-cluster.sh` con i tuoi parametri:
|
||||
- IP delle VM
|
||||
- VIP
|
||||
- Gateway
|
||||
- Chiave SSH pubblica
|
||||
- Risorse (CPU, RAM, disco)
|
||||
|
||||
Oppure usa lo script interattivo:
|
||||
```bash
|
||||
cd scripts
|
||||
./setup-config.sh
|
||||
```
|
||||
|
||||
### 2. Provisioning VM
|
||||
|
||||
Esegui sul nodo Proxmox:
|
||||
```bash
|
||||
cd scripts
|
||||
chmod +x *.sh
|
||||
./provision-ha-cluster.sh
|
||||
```
|
||||
|
||||
Lo script:
|
||||
- Scarica Ubuntu Cloud Image
|
||||
- Crea template Cloud-Init
|
||||
- Crea 2 VM (ID 201 e 202)
|
||||
- Configura networking
|
||||
- Installa Docker
|
||||
- Avvia le VM
|
||||
|
||||
Tempo richiesto: ~5-10 minuti
|
||||
|
||||
### 3. Deploy Applicazione
|
||||
|
||||
#### Su VM1:
|
||||
```bash
|
||||
# Copia file
|
||||
scp -r vm1/* root@192.168.1.201:/opt/myapp/
|
||||
|
||||
# SSH e deploy
|
||||
ssh root@192.168.1.201
|
||||
cd /opt/myapp
|
||||
cp .env.example .env
|
||||
# Modifica .env con le tue password
|
||||
./deploy-ha.sh
|
||||
```
|
||||
|
||||
#### Su VM2:
|
||||
```bash
|
||||
# Copia file
|
||||
scp -r vm2/* root@192.168.1.202:/opt/myapp/
|
||||
|
||||
# SSH e deploy
|
||||
ssh root@192.168.1.202
|
||||
cd /opt/myapp
|
||||
cp .env.example .env
|
||||
# Modifica .env (stesse password di VM1!)
|
||||
./deploy-ha.sh
|
||||
```
|
||||
|
||||
### 4. Verifica
|
||||
|
||||
```bash
|
||||
cd scripts
|
||||
./verify-cluster.sh
|
||||
```
|
||||
|
||||
### 5. Test Failover
|
||||
|
||||
```bash
|
||||
cd scripts
|
||||
./test-failover.sh
|
||||
```
|
||||
|
||||
## Makefile
|
||||
|
||||
Per comodità, usa il Makefile:
|
||||
|
||||
```bash
|
||||
# Provisioning completo
|
||||
make provision
|
||||
|
||||
# Verifica cluster
|
||||
make verify
|
||||
|
||||
# Test failover
|
||||
make test-failover
|
||||
|
||||
# SSH nelle VM
|
||||
make ssh-vm1
|
||||
make ssh-vm2
|
||||
|
||||
# Vedi log
|
||||
make logs-vm1
|
||||
make logs-vm2
|
||||
|
||||
# Distruggi tutto
|
||||
make destroy
|
||||
```
|
||||
|
||||
## Configurazione
|
||||
|
||||
### Variabili d'ambiente (.env)
|
||||
|
||||
Configura in entrambe le VM (stessi valori!):
|
||||
|
||||
```bash
|
||||
VIP=192.168.1.100
|
||||
MYSQL_ROOT_PASSWORD=...
|
||||
MYSQL_DATABASE=myapp
|
||||
MYSQL_USER=appuser
|
||||
MYSQL_PASSWORD=...
|
||||
REDIS_PASSWORD=...
|
||||
LOKI_HOST=192.168.1.200
|
||||
LOKI_PORT=3100
|
||||
```
|
||||
|
||||
### Ports
|
||||
|
||||
- `21`: FTP
|
||||
- `3306`: MySQL (tramite HAProxy)
|
||||
- `6379`: Redis (tramite HAProxy)
|
||||
- `8404`: HAProxy Stats
|
||||
- `30000-30009`: FTP Passive
|
||||
|
||||
## Servizi
|
||||
|
||||
### Accesso ai servizi
|
||||
|
||||
Tutti i servizi sono accessibili tramite VIP:
|
||||
|
||||
```bash
|
||||
# FTP
|
||||
ftp 192.168.1.100
|
||||
|
||||
# MySQL
|
||||
mysql -h 192.168.1.100 -u appuser -p
|
||||
|
||||
# Redis
|
||||
redis-cli -h 192.168.1.100
|
||||
|
||||
# HAProxy Stats
|
||||
http://192.168.1.100:8404
|
||||
```
|
||||
|
||||
### Grafana/Loki
|
||||
|
||||
Log disponibili in Grafana:
|
||||
```logql
|
||||
# Tutti i log
|
||||
{cluster="myapp-cluster"}
|
||||
|
||||
# Per servizio
|
||||
{job="ftp-server"}
|
||||
{job="orchestrator"}
|
||||
{job="mysql"}
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### VIP non risponde
|
||||
```bash
|
||||
# Verifica su entrambe le VM
|
||||
docker compose logs keepalived
|
||||
ip addr show | grep 192.168.1.100
|
||||
```
|
||||
|
||||
### Failover non funziona
|
||||
```bash
|
||||
# Verifica connettività tra le VM
|
||||
ping 192.168.1.10
|
||||
ping 192.168.1.11
|
||||
|
||||
# Controlla keepalived
|
||||
docker compose logs keepalived
|
||||
```
|
||||
|
||||
### Servizi non si avviano
|
||||
```bash
|
||||
# Verifica log
|
||||
docker compose logs
|
||||
|
||||
# Verifica risorse
|
||||
free -h
|
||||
df -h
|
||||
```
|
||||
|
||||
### Redis sync non funziona
|
||||
```bash
|
||||
# Su VM2
|
||||
docker compose exec redis redis-cli INFO replication
|
||||
```
|
||||
|
||||
## Struttura File
|
||||
|
||||
```
|
||||
proxmox-ha-setup/
|
||||
├── scripts/
|
||||
│ ├── provision-ha-cluster.sh # Provisioning Proxmox
|
||||
│ ├── setup-config.sh # Config interattiva
|
||||
│ ├── verify-cluster.sh # Verifica cluster
|
||||
│ └── test-failover.sh # Test HA
|
||||
├── vm1/
|
||||
│ ├── docker-compose.yml # Services VM1
|
||||
│ ├── haproxy.cfg # HAProxy config
|
||||
│ ├── keepalived-master.conf # Keepalived MASTER
|
||||
│ ├── promtail-config.yml # Promtail config
|
||||
│ ├── .env.example # Environment template
|
||||
│ ├── deploy-ha.sh # Deploy script
|
||||
│ └── Dockerfile # App container
|
||||
├── vm2/
|
||||
│ └── (stessi file di vm1)
|
||||
├── README.md
|
||||
└── Makefile
|
||||
```
|
||||
|
||||
## Manutenzione
|
||||
|
||||
### Aggiungere nuovi orchestratori
|
||||
|
||||
Modifica `docker-compose.yml` e aggiungi:
|
||||
```yaml
|
||||
orchestrator-4:
|
||||
# ... config
|
||||
```
|
||||
|
||||
### Scalare FTP servers
|
||||
|
||||
```bash
|
||||
# Aggiungi più istanze FTP editando docker-compose.yml
|
||||
# Poi:
|
||||
docker compose up -d --scale ftp-server-1=2
|
||||
```
|
||||
|
||||
### Backup Database
|
||||
|
||||
```bash
|
||||
# Su VM1
|
||||
docker compose exec mysql mysqldump -u root -p myapp > backup.sql
|
||||
```
|
||||
|
||||
### Update applicazione
|
||||
|
||||
```bash
|
||||
# Pull codice aggiornato
|
||||
git pull
|
||||
|
||||
# Rebuild e restart
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## Sicurezza
|
||||
|
||||
- Cambia tutte le password di default in `.env`
|
||||
- Configura firewall su Proxmox
|
||||
- Abilita SSL/TLS per FTP (FTPS)
|
||||
- Usa autenticazione forte per MySQL
|
||||
- Aggiorna regolarmente le immagini Docker
|
||||
|
||||
## Migrazione a Produzione
|
||||
|
||||
Per usare il cluster Galera in produzione:
|
||||
|
||||
1. Rimuovi il servizio `mysql` da `docker-compose.yml`
|
||||
2. Punta `DB_HOST` al tuo cluster Galera
|
||||
3. Mantieni tutto il resto identico
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Support
|
||||
|
||||
Per problemi o domande, apri una issue.
|
||||
Reference in New Issue
Block a user