# Deploy - Sistema de ATLAS Scripts y configuraciones para desplegar el sistema de atlas 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 │ ├── atlas-api.service │ ├── atlas-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 atlas --memory 8192 ``` ### 2. En Ubuntu ```bash # Clonar repositorio git clone https://github.com/tuorg/atlas.git /opt/atlas cd /opt/atlas # 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 atlas ``` 4. Configurar DNS: ```bash cloudflared tunnel route dns atlas atlas.tudominio.com ``` 5. Copiar config y habilitar servicio: ```bash mkdir -p /etc/cloudflared cp /opt/atlas/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/atlas/daily/atlas_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 | |----------|--------|-------------| | atlas-api | 8000 | Backend FastAPI | | atlas-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 atlas-api # Reiniciar systemctl restart atlas-api # Logs journalctl -u atlas-api -f # Habilitar/Deshabilitar systemctl enable atlas-api systemctl disable atlas-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 atlas-api -n 100 # Verificar puerto ss -tlnp | grep 8000 # Verificar base de datos psql -h localhost -U atlas -d atlas -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 atlas-api --no-pager | grep Memory # Reducir workers de API # Editar /etc/systemd/system/atlas-api.service # Cambiar --workers 4 a --workers 2 systemctl daemon-reload systemctl restart atlas-api ``` ## Credenciales Las credenciales se generan durante la instalacion y se guardan en: - `/root/atlas-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.