265 lines
5.5 KiB
Markdown
265 lines
5.5 KiB
Markdown
# Deploy - Sistema de ADAN
|
|
|
|
Scripts y configuraciones para desplegar el sistema de adan en produccion.
|
|
|
|
## Estructura
|
|
|
|
```
|
|
deploy/
|
|
├── proxmox/ # Crear VM en Proxmox VE
|
|
│ └── vm-setup.sh
|
|
├── scripts/ # Scripts de utilidad
|
|
│ ├── install.sh # Instalacion completa
|
|
│ ├── backup.sh # Backup automatico
|
|
│ ├── restore.sh # Restaurar backup
|
|
│ ├── update.sh # Actualizar aplicacion
|
|
│ ├── health-check.sh # Verificar salud
|
|
│ ├── status.sh # Estado del sistema
|
|
│ └── logs.sh # Visor de logs
|
|
├── services/ # Servicios systemd
|
|
│ ├── adan-api.service
|
|
│ ├── adan-web.service
|
|
│ ├── mediamtx.service
|
|
│ └── cloudflared.service
|
|
├── cloudflare/ # Configuracion tunnel
|
|
│ └── config.yml
|
|
├── traccar/ # Configuracion GPS
|
|
│ └── traccar.xml
|
|
├── mediamtx/ # Configuracion streaming
|
|
│ └── mediamtx.yml
|
|
└── postgres/ # Base de datos
|
|
└── init.sql
|
|
```
|
|
|
|
## Requisitos
|
|
|
|
- **SO**: Ubuntu 22.04 LTS
|
|
- **RAM**: Minimo 4GB (recomendado 8GB)
|
|
- **Disco**: Minimo 50GB SSD
|
|
- **CPU**: 4 cores
|
|
|
|
## Instalacion Rapida
|
|
|
|
### 1. En Proxmox (opcional)
|
|
|
|
```bash
|
|
# Crear VM automaticamente
|
|
./deploy/proxmox/vm-setup.sh --vmid 200 --name adan --memory 8192
|
|
```
|
|
|
|
### 2. En Ubuntu
|
|
|
|
```bash
|
|
# Clonar repositorio
|
|
git clone https://github.com/tuorg/adan.git /opt/adan
|
|
cd /opt/adan
|
|
|
|
# Ejecutar instalador
|
|
sudo ./deploy/scripts/install.sh
|
|
```
|
|
|
|
El instalador:
|
|
- Actualiza el sistema
|
|
- Instala PostgreSQL 15 + TimescaleDB + PostGIS
|
|
- Instala Redis
|
|
- Instala Python 3.11 y Node.js 20
|
|
- Instala Traccar GPS Server
|
|
- Instala MediaMTX para video
|
|
- Configura servicios systemd
|
|
- Configura firewall (solo puerto 5055 publico)
|
|
- Genera credenciales aleatorias
|
|
|
|
## Post-Instalacion
|
|
|
|
### Verificar estado
|
|
|
|
```bash
|
|
./deploy/scripts/status.sh
|
|
./deploy/scripts/health-check.sh
|
|
```
|
|
|
|
### Ver logs
|
|
|
|
```bash
|
|
./deploy/scripts/logs.sh api -f # API en tiempo real
|
|
./deploy/scripts/logs.sh traccar # Traccar GPS
|
|
./deploy/scripts/logs.sh all -f # Todos los servicios
|
|
```
|
|
|
|
### Configurar Cloudflare Tunnel
|
|
|
|
1. Instalar cloudflared:
|
|
```bash
|
|
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
|
|
dpkg -i cloudflared.deb
|
|
```
|
|
|
|
2. Autenticarse:
|
|
```bash
|
|
cloudflared tunnel login
|
|
```
|
|
|
|
3. Crear tunnel:
|
|
```bash
|
|
cloudflared tunnel create adan
|
|
```
|
|
|
|
4. Configurar DNS:
|
|
```bash
|
|
cloudflared tunnel route dns adan adan.tudominio.com
|
|
```
|
|
|
|
5. Copiar config y habilitar servicio:
|
|
```bash
|
|
mkdir -p /etc/cloudflared
|
|
cp /opt/adan/deploy/cloudflare/config.yml /etc/cloudflared/
|
|
systemctl enable cloudflared
|
|
systemctl start cloudflared
|
|
```
|
|
|
|
## Mantenimiento
|
|
|
|
### Backup
|
|
|
|
```bash
|
|
# Backup manual
|
|
./deploy/scripts/backup.sh
|
|
|
|
# Backup completo (incluye archivos)
|
|
./deploy/scripts/backup.sh --full
|
|
|
|
# Backup y subir a S3
|
|
./deploy/scripts/backup.sh --upload
|
|
```
|
|
|
|
Backups automaticos: diariamente a las 3 AM (configurado por install.sh)
|
|
|
|
### Restaurar
|
|
|
|
```bash
|
|
# Listar backups disponibles
|
|
./deploy/scripts/restore.sh --list
|
|
|
|
# Restaurar ultimo backup
|
|
./deploy/scripts/restore.sh --latest
|
|
|
|
# Restaurar backup especifico
|
|
./deploy/scripts/restore.sh --db /var/backups/adan/daily/adan_20240115_db.sql.gz
|
|
```
|
|
|
|
### Actualizar
|
|
|
|
```bash
|
|
# Actualizar a ultima version
|
|
./deploy/scripts/update.sh
|
|
|
|
# Forzar actualizacion (descarta cambios locales)
|
|
./deploy/scripts/update.sh --force
|
|
|
|
# Solo actualizar backend
|
|
./deploy/scripts/update.sh --backend
|
|
```
|
|
|
|
## Servicios
|
|
|
|
| Servicio | Puerto | Descripcion |
|
|
|----------|--------|-------------|
|
|
| adan-api | 8000 | Backend FastAPI |
|
|
| adan-web | 3000 | Frontend |
|
|
| postgresql | 5432 | Base de datos |
|
|
| redis | 6379 | Cache |
|
|
| traccar | 5055 | GPS Server |
|
|
| mediamtx | 8554/8889/8888 | Video RTSP/WebRTC/HLS |
|
|
| mosquitto | 1883 | MQTT |
|
|
|
|
### Comandos systemd
|
|
|
|
```bash
|
|
# Estado
|
|
systemctl status adan-api
|
|
|
|
# Reiniciar
|
|
systemctl restart adan-api
|
|
|
|
# Logs
|
|
journalctl -u adan-api -f
|
|
|
|
# Habilitar/Deshabilitar
|
|
systemctl enable adan-api
|
|
systemctl disable adan-api
|
|
```
|
|
|
|
## Seguridad
|
|
|
|
- **Firewall**: Solo puerto 5055 (GPS) esta abierto
|
|
- **Acceso web**: Via Cloudflare Tunnel (HTTPS)
|
|
- **Base de datos**: Solo acceso local
|
|
- **Redis**: Autenticacion con password
|
|
- **Fail2ban**: Proteccion contra fuerza bruta
|
|
|
|
## Puertos
|
|
|
|
| Puerto | Uso | Acceso |
|
|
|--------|-----|--------|
|
|
| 22 | SSH | Firewall |
|
|
| 5055 | Traccar GPS | Publico |
|
|
| 3000 | Frontend | Tunnel |
|
|
| 8000 | API | Tunnel |
|
|
| 5432 | PostgreSQL | Local |
|
|
| 6379 | Redis | Local |
|
|
| 8554 | RTSP | Tunnel |
|
|
| 8889 | WebRTC | Tunnel |
|
|
| 8888 | HLS | Tunnel |
|
|
|
|
## Troubleshooting
|
|
|
|
### API no inicia
|
|
|
|
```bash
|
|
# Ver logs
|
|
journalctl -u adan-api -n 100
|
|
|
|
# Verificar puerto
|
|
ss -tlnp | grep 8000
|
|
|
|
# Verificar base de datos
|
|
psql -h localhost -U adan -d adan -c "SELECT 1"
|
|
```
|
|
|
|
### Traccar no recibe datos
|
|
|
|
```bash
|
|
# Verificar puerto GPS
|
|
ss -tlnp | grep 5055
|
|
|
|
# Ver logs Traccar
|
|
tail -f /opt/traccar/logs/tracker-server.log
|
|
|
|
# Probar conexion
|
|
nc -zv localhost 5055
|
|
```
|
|
|
|
### Problemas de memoria
|
|
|
|
```bash
|
|
# Ver uso de memoria por servicio
|
|
systemctl status adan-api --no-pager | grep Memory
|
|
|
|
# Reducir workers de API
|
|
# Editar /etc/systemd/system/adan-api.service
|
|
# Cambiar --workers 4 a --workers 2
|
|
systemctl daemon-reload
|
|
systemctl restart adan-api
|
|
```
|
|
|
|
## Credenciales
|
|
|
|
Las credenciales se generan durante la instalacion y se guardan en:
|
|
- `/root/adan-credentials.txt`
|
|
|
|
**IMPORTANTE**: Guardar en lugar seguro y eliminar el archivo despues.
|
|
|
|
## Soporte
|
|
|
|
Para soporte, crear un issue en el repositorio o contactar al equipo de desarrollo.
|