Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 1c71ce6e-1a3e-4f53-bb5d-77cdd22b8ea3
187 lines
5.4 KiB
Markdown
187 lines
5.4 KiB
Markdown
# 🕐 CONFIGURAZIONE CRONTAB SISTEMA DDoS DETECTION
|
|
|
|
## 🚀 INSTALLAZIONE RAPIDA
|
|
|
|
```bash
|
|
# 1. Rendi eseguibile lo script di setup
|
|
chmod +x setup_crontab.sh
|
|
|
|
# 2. Esegui la configurazione automatica
|
|
./setup_crontab.sh
|
|
```
|
|
|
|
## 📋 CONFIGURAZIONE CRONTAB MANUALE
|
|
|
|
Se preferisci configurare manualmente il crontab, usa questi comandi:
|
|
|
|
### 1. Modifica il crontab
|
|
```bash
|
|
crontab -e
|
|
```
|
|
|
|
### 2. Aggiungi queste righe:
|
|
```bash
|
|
# ============================================
|
|
# SISTEMA DDoS DETECTION - CONFIGURAZIONE AUTOMATICA
|
|
# ============================================
|
|
|
|
# Training ogni 12 ore (alle 00:00 e 12:00)
|
|
0 */12 * * * cd /percorso/completo/del/progetto && python3 analisys_02.py --training-hours 0.01 --max-records 500000 --force-training >> /root/training.log 2>&1
|
|
|
|
# Verifica processo detect ogni 5 minuti (riavvia se non attivo)
|
|
*/5 * * * * /percorso/completo/del/progetto/check_detect.sh >> /root/cron_ddos.log 2>&1
|
|
|
|
# Pulizia log settimanale (ogni domenica alle 02:00)
|
|
0 2 * * 0 find /root -name "*.log" -size +100M -exec truncate -s 50M {} \; >> /root/cron_ddos.log 2>&1
|
|
|
|
# Restart completo del sistema ogni settimana (domenica alle 03:00)
|
|
0 3 * * 0 /percorso/completo/del/progetto/restart_detect.sh >> /root/cron_ddos.log 2>&1
|
|
```
|
|
|
|
## 🔄 AVVIO MANUALE PROCESSO DETECT
|
|
|
|
Se vuoi avviare manualmente il processo detect in background:
|
|
|
|
```bash
|
|
# Avvio in background con nohup
|
|
nohup python3 detect_multi_03.py --ciclo --pausa 5 --batch-size 20000 --sensibility 1 --cleanup --retention-days 0 >> /root/detect.log 2>&1 &
|
|
|
|
# Salva il PID per controllo successivo
|
|
echo $! > /tmp/detect_ddos.pid
|
|
```
|
|
|
|
## 📊 MONITORAGGIO E LOG
|
|
|
|
### Visualizzazione log in tempo reale:
|
|
```bash
|
|
# Log rilevamento DDoS (quello che hai chiesto)
|
|
tail -f /root/detect.log
|
|
|
|
# Log training (addestramento modelli)
|
|
tail -f /root/training.log
|
|
|
|
# Log crontab (errori/info gestione automatica)
|
|
tail -f /root/cron_ddos.log
|
|
```
|
|
|
|
### Stato dei processi:
|
|
```bash
|
|
# Verifica processo detect attivo
|
|
ps aux | grep detect_multi
|
|
|
|
# Verifica PID salvato
|
|
cat /tmp/detect_ddos.pid
|
|
|
|
# Lista completa processi python
|
|
ps aux | grep python3
|
|
```
|
|
|
|
### Stato crontab:
|
|
```bash
|
|
# Visualizza crontab attuale
|
|
crontab -l
|
|
|
|
# Visualizza log crontab di sistema
|
|
tail -f /var/log/cron
|
|
|
|
# Test manuale job crontab
|
|
./check_detect.sh
|
|
```
|
|
|
|
## 🛠️ SCRIPT DI CONTROLLO
|
|
|
|
### check_detect.sh
|
|
Verifica ogni 5 minuti che il processo detect sia attivo:
|
|
- Se non trova il processo, lo riavvia automaticamente
|
|
- Se il log non viene aggiornato da più di 10 minuti, riavvia il processo
|
|
- Gestisce il file PID per il controllo
|
|
|
|
### restart_detect.sh
|
|
Restart completo settimanale del sistema:
|
|
- Termina il processo esistente gracefully
|
|
- Pulisce file temporanei
|
|
- Riavvia il processo detect
|
|
|
|
## ⚙️ PARAMETRI CONFIGURATI
|
|
|
|
### Training (ogni 12 ore):
|
|
- `--training-hours 0.01`: Training rapido (36 secondi)
|
|
- `--max-records 500000`: Massimo 500k record per training
|
|
- `--force-training`: Forza training anche se modelli esistono
|
|
|
|
### Detection (continuo):
|
|
- `--ciclo`: Esecuzione continua
|
|
- `--pausa 5`: Pausa 5 secondi tra cicli
|
|
- `--batch-size 20000`: 20k record per batch
|
|
- `--sensibility 1`: Massima sensibilità (più aggressivo)
|
|
- `--cleanup`: Pulizia automatica IP vecchi
|
|
- `--retention-days 0`: Rimuove IP immediatamente (test)
|
|
|
|
## 🔧 COMANDI UTILI
|
|
|
|
### Controllo manuale:
|
|
```bash
|
|
# Restart manuale detect
|
|
./restart_detect.sh
|
|
|
|
# Stop processo detect
|
|
kill $(cat /tmp/detect_ddos.pid)
|
|
|
|
# Avvio manuale training
|
|
python3 analisys_02.py --training-hours 0.01 --max-records 500000 --force-training
|
|
|
|
# Test connessione database
|
|
python3 analisys_02.py --test
|
|
```
|
|
|
|
### Gestione log:
|
|
```bash
|
|
# Pulizia manuale log grandi
|
|
find /root -name "*.log" -size +100M -exec truncate -s 50M {} \;
|
|
|
|
# Backup log prima della pulizia
|
|
cp /root/detect.log /root/detect_backup_$(date +%Y%m%d).log
|
|
|
|
# Rotazione log manuale
|
|
mv /root/detect.log /root/detect_old.log && touch /root/detect.log
|
|
```
|
|
|
|
### Debug e troubleshooting:
|
|
```bash
|
|
# Verifica permessi script
|
|
ls -la *.sh
|
|
|
|
# Test script controllo
|
|
bash -x ./check_detect.sh
|
|
|
|
# Verifica sintassi crontab
|
|
crontab -l | crontab
|
|
```
|
|
|
|
## 📅 SCHEDULING DETTAGLIATO
|
|
|
|
| Operazione | Frequenza | Orario | Comando |
|
|
|------------|-----------|--------|---------|
|
|
| **Training** | Ogni 12 ore | 00:00, 12:00 | `analisys_02.py` |
|
|
| **Check Detect** | Ogni 5 minuti | Continuo | `check_detect.sh` |
|
|
| **Pulizia Log** | Settimanale | Domenica 02:00 | `truncate` log > 100MB |
|
|
| **Restart** | Settimanale | Domenica 03:00 | `restart_detect.sh` |
|
|
|
|
## ⚠️ NOTE IMPORTANTI
|
|
|
|
1. **Percorsi assoluti**: Il crontab usa percorsi assoluti, assicurati che siano corretti
|
|
2. **Permessi**: Gli script devono essere eseguibili (`chmod +x`)
|
|
3. **Output log**: Tutti gli output sono redirezionati ai file di log
|
|
4. **Gestione errori**: Gli script gestiscono automaticamente errori e restart
|
|
5. **Monitoraggio**: Il sistema si auto-monitora e auto-ripara
|
|
6. **Backup**: Il crontab esistente viene salvato automaticamente
|
|
|
|
## 🎯 RISULTATO FINALE
|
|
|
|
Con questa configurazione avrai:
|
|
- ✅ Training automatico ogni 12 ore per modelli sempre aggiornati
|
|
- ✅ Detection continuo con massima sensibilità (sensibility 1)
|
|
- ✅ Monitoraggio automatico e restart in caso di problemi
|
|
- ✅ Log centralizzati in `/root/detect.log` per `tail -f`
|
|
- ✅ Pulizia automatica per evitare accumulo log
|
|
- ✅ Restart settimanale per mantenere il sistema pulito |