FlotillasGPS - Sistema completo de monitoreo de flotillas GPS
Sistema completo para monitoreo y gestion de flotas de vehiculos con: - Backend FastAPI con PostgreSQL/TimescaleDB - Frontend React con TypeScript y TailwindCSS - App movil React Native con Expo - Soporte para dispositivos GPS, Meshtastic y celulares - Video streaming en vivo con MediaMTX - Geocercas, alertas, viajes y reportes - Autenticacion JWT y WebSockets en tiempo real Documentacion completa y guias de usuario incluidas.
This commit is contained in:
449
docs/guias/configuracion.md
Normal file
449
docs/guias/configuracion.md
Normal file
@@ -0,0 +1,449 @@
|
||||
# Guia de Configuracion
|
||||
|
||||
Configuracion detallada de todos los componentes del sistema FlotillasGPS.
|
||||
|
||||
## Variables de Entorno
|
||||
|
||||
El archivo `/opt/flotillas/.env` contiene todas las configuraciones del sistema.
|
||||
|
||||
### Base de Datos
|
||||
|
||||
```bash
|
||||
# PostgreSQL
|
||||
DATABASE_URL=postgresql://flotillas:PASSWORD@localhost:5432/flotillas_db
|
||||
|
||||
# Conexiones maximas al pool
|
||||
DB_POOL_SIZE=10
|
||||
DB_MAX_OVERFLOW=20
|
||||
```
|
||||
|
||||
### Redis
|
||||
|
||||
```bash
|
||||
# URL de conexion
|
||||
REDIS_URL=redis://localhost:6379
|
||||
|
||||
# Base de datos (0-15)
|
||||
REDIS_DB=0
|
||||
```
|
||||
|
||||
### Seguridad
|
||||
|
||||
```bash
|
||||
# Clave secreta para JWT (generar con: openssl rand -base64 64)
|
||||
JWT_SECRET=tu_clave_muy_larga_y_segura
|
||||
|
||||
# Expiracion de tokens
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES=1440 # 24 horas
|
||||
REFRESH_TOKEN_EXPIRE_DAYS=7
|
||||
|
||||
# Clave para encriptar datos sensibles
|
||||
ENCRYPTION_KEY=otra_clave_segura
|
||||
```
|
||||
|
||||
### Traccar
|
||||
|
||||
```bash
|
||||
# Conexion a Traccar
|
||||
TRACCAR_HOST=localhost
|
||||
TRACCAR_PORT=5055
|
||||
TRACCAR_FORWARD_URL=http://localhost:8000/api/v1/traccar/position
|
||||
```
|
||||
|
||||
### Video Streaming
|
||||
|
||||
```bash
|
||||
# MediaMTX
|
||||
MEDIAMTX_API=http://localhost:9997
|
||||
MEDIAMTX_RTSP=rtsp://localhost:8554
|
||||
MEDIAMTX_WEBRTC=http://localhost:8889
|
||||
MEDIAMTX_HLS=http://localhost:8888
|
||||
|
||||
# Directorio de grabaciones
|
||||
VIDEO_STORAGE_PATH=/opt/flotillas/videos
|
||||
VIDEO_RETENTION_DAYS=30
|
||||
```
|
||||
|
||||
### MQTT (Meshtastic)
|
||||
|
||||
```bash
|
||||
MQTT_HOST=localhost
|
||||
MQTT_PORT=1883
|
||||
MQTT_USER=mesh_gateway
|
||||
MQTT_PASSWORD=password_seguro
|
||||
MQTT_TOPIC=flotillas/mesh/#
|
||||
```
|
||||
|
||||
### Notificaciones
|
||||
|
||||
```bash
|
||||
# Email (SMTP)
|
||||
SMTP_HOST=smtp.tudominio.com
|
||||
SMTP_PORT=587
|
||||
SMTP_USER=notificaciones@tudominio.com
|
||||
SMTP_PASSWORD=password
|
||||
SMTP_FROM=FlotillasGPS <notificaciones@tudominio.com>
|
||||
|
||||
# Push Notifications (Firebase)
|
||||
FIREBASE_CREDENTIALS_FILE=/opt/flotillas/firebase-credentials.json
|
||||
```
|
||||
|
||||
### Dominio
|
||||
|
||||
```bash
|
||||
DOMAIN=flotillas.tudominio.com
|
||||
API_URL=https://flotillas.tudominio.com/api
|
||||
FRONTEND_URL=https://flotillas.tudominio.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de Traccar
|
||||
|
||||
Archivo: `/opt/traccar/conf/traccar.xml`
|
||||
|
||||
```xml
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!DOCTYPE properties SYSTEM 'http://java.sun.com/dtd/properties.dtd'>
|
||||
<properties>
|
||||
<!-- Base de datos -->
|
||||
<entry key='database.driver'>org.postgresql.Driver</entry>
|
||||
<entry key='database.url'>jdbc:postgresql://localhost:5432/flotillas_db</entry>
|
||||
<entry key='database.user'>flotillas</entry>
|
||||
<entry key='database.password'>TU_PASSWORD</entry>
|
||||
|
||||
<!-- Deshabilitar web UI de Traccar (usamos nuestro dashboard) -->
|
||||
<entry key='web.enable'>false</entry>
|
||||
<entry key='api.enable'>false</entry>
|
||||
|
||||
<!-- Forward de posiciones a nuestra API -->
|
||||
<entry key='forward.enable'>true</entry>
|
||||
<entry key='forward.url'>http://localhost:8000/api/v1/traccar/position</entry>
|
||||
<entry key='forward.json'>true</entry>
|
||||
|
||||
<!-- Protocolos habilitados (agregar segun tus GPS) -->
|
||||
<entry key='gt06.port'>5023</entry>
|
||||
<entry key='tk103.port'>5002</entry>
|
||||
<entry key='gps103.port'>5001</entry>
|
||||
<entry key='osmand.port'>5055</entry>
|
||||
|
||||
<!-- Logging -->
|
||||
<entry key='logger.enable'>true</entry>
|
||||
<entry key='logger.level'>info</entry>
|
||||
</properties>
|
||||
```
|
||||
|
||||
### Protocolos GPS Comunes
|
||||
|
||||
| Protocolo | Puerto | Dispositivos |
|
||||
|-----------|--------|--------------|
|
||||
| osmand | 5055 | Apps moviles, GPS genericos |
|
||||
| gt06 | 5023 | Concox, Wetrack, JM01 |
|
||||
| tk103 | 5002 | TK103, GPS103 |
|
||||
| h02 | 5013 | Sinotrack ST-901 |
|
||||
| watch | 5093 | Smartwatches GPS |
|
||||
| teltonika | 5027 | Teltonika FM |
|
||||
|
||||
Para habilitar un protocolo adicional, agregar la linea:
|
||||
```xml
|
||||
<entry key='PROTOCOLO.port'>PUERTO</entry>
|
||||
```
|
||||
|
||||
Y abrir el puerto en el firewall:
|
||||
```bash
|
||||
ufw allow PUERTO/tcp
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de MediaMTX
|
||||
|
||||
Archivo: `/etc/mediamtx/mediamtx.yml`
|
||||
|
||||
```yaml
|
||||
# Logging
|
||||
logLevel: info
|
||||
logDestinations: [stdout]
|
||||
|
||||
# API para control
|
||||
api: yes
|
||||
apiAddress: 127.0.0.1:9997
|
||||
|
||||
# RTSP Server (para recibir streams de camaras)
|
||||
rtsp: yes
|
||||
rtspAddress: :8554
|
||||
protocols: [tcp, udp]
|
||||
rtspAuthMethods: []
|
||||
|
||||
# WebRTC Server (para dashboard)
|
||||
webrtc: yes
|
||||
webrtcAddress: :8889
|
||||
webrtcAllowOrigin: '*'
|
||||
webrtcICEServers2:
|
||||
- urls: [stun:stun.l.google.com:19302]
|
||||
|
||||
# HLS Server (para app movil)
|
||||
hls: yes
|
||||
hlsAddress: :8888
|
||||
hlsAllowOrigin: '*'
|
||||
hlsAlwaysRemux: yes
|
||||
hlsSegmentCount: 3
|
||||
hlsSegmentDuration: 1s
|
||||
|
||||
# Grabacion
|
||||
record: no # Manejamos grabacion desde nuestra API
|
||||
recordPath: /opt/flotillas/videos/%path/%Y%m%d_%H%M%S.mp4
|
||||
|
||||
# Paths (camaras)
|
||||
paths:
|
||||
# Patron para camaras: cam_{vehiculo_id}_{posicion}
|
||||
cam~:
|
||||
source: publisher
|
||||
# Autenticacion para publicar
|
||||
publishUser: camuser
|
||||
publishPass: campass
|
||||
# Autenticacion para ver (vacio = sin auth, lo manejamos con JWT)
|
||||
readUser: ''
|
||||
readPass: ''
|
||||
```
|
||||
|
||||
### Agregar Camara Manualmente
|
||||
|
||||
```bash
|
||||
# Crear path para una camara
|
||||
curl -X POST http://localhost:9997/v2/config/paths/add/cam_1_frontal \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"source": "rtsp://usuario:password@192.168.1.100/stream1",
|
||||
"sourceOnDemand": true
|
||||
}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de Cloudflare Tunnel
|
||||
|
||||
Archivo: `/etc/cloudflared/config.yml`
|
||||
|
||||
```yaml
|
||||
tunnel: TU_TUNNEL_ID
|
||||
credentials-file: /root/.cloudflared/TU_TUNNEL_ID.json
|
||||
|
||||
ingress:
|
||||
# API Backend
|
||||
- hostname: flotillas.tudominio.com
|
||||
path: /api/*
|
||||
service: http://localhost:8000
|
||||
|
||||
# WebSocket
|
||||
- hostname: flotillas.tudominio.com
|
||||
path: /ws/*
|
||||
service: http://localhost:8000
|
||||
|
||||
# Frontend (default)
|
||||
- hostname: flotillas.tudominio.com
|
||||
service: http://localhost:3000
|
||||
|
||||
# Catch-all
|
||||
- service: http_status:404
|
||||
```
|
||||
|
||||
### Comandos Utiles
|
||||
|
||||
```bash
|
||||
# Ver estado del tunnel
|
||||
cloudflared tunnel info TU_TUNNEL_ID
|
||||
|
||||
# Listar tunnels
|
||||
cloudflared tunnel list
|
||||
|
||||
# Ver conexiones activas
|
||||
cloudflared tunnel run --url http://localhost:3000
|
||||
|
||||
# Reiniciar
|
||||
systemctl restart cloudflared
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de PostgreSQL
|
||||
|
||||
### Ajustes de Rendimiento
|
||||
|
||||
Archivo: `/etc/postgresql/15/main/postgresql.conf`
|
||||
|
||||
```ini
|
||||
# Memoria (ajustar segun RAM disponible)
|
||||
shared_buffers = 2GB # 25% de RAM
|
||||
effective_cache_size = 6GB # 75% de RAM
|
||||
work_mem = 256MB
|
||||
maintenance_work_mem = 512MB
|
||||
|
||||
# Conexiones
|
||||
max_connections = 100
|
||||
|
||||
# WAL
|
||||
wal_buffers = 64MB
|
||||
checkpoint_completion_target = 0.9
|
||||
|
||||
# Logging
|
||||
log_min_duration_statement = 1000 # Log queries > 1 segundo
|
||||
```
|
||||
|
||||
### TimescaleDB
|
||||
|
||||
```sql
|
||||
-- Ver chunks de la hypertable
|
||||
SELECT show_chunks('ubicaciones');
|
||||
|
||||
-- Comprimir chunks antiguos
|
||||
SELECT compress_chunk(c, if_not_compressed => true)
|
||||
FROM show_chunks('ubicaciones', older_than => INTERVAL '7 days') c;
|
||||
|
||||
-- Configurar compresion automatica
|
||||
SELECT add_compression_policy('ubicaciones', INTERVAL '7 days');
|
||||
|
||||
-- Configurar retencion automatica
|
||||
SELECT add_retention_policy('ubicaciones', INTERVAL '90 days');
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de Redis
|
||||
|
||||
Archivo: `/etc/redis/redis.conf`
|
||||
|
||||
```ini
|
||||
# Memoria
|
||||
maxmemory 512mb
|
||||
maxmemory-policy allkeys-lru
|
||||
|
||||
# Persistencia
|
||||
save 900 1
|
||||
save 300 10
|
||||
save 60 10000
|
||||
|
||||
# Solo conexiones locales
|
||||
bind 127.0.0.1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de Firewall (UFW)
|
||||
|
||||
```bash
|
||||
# Ver estado actual
|
||||
ufw status verbose
|
||||
|
||||
# Reglas recomendadas
|
||||
ufw default deny incoming
|
||||
ufw default allow outgoing
|
||||
ufw allow ssh
|
||||
ufw allow 5055/tcp # GPS Traccar
|
||||
|
||||
# Si necesitas mas puertos GPS
|
||||
ufw allow 5001:5099/tcp # Rango de puertos Traccar
|
||||
|
||||
# Habilitar
|
||||
ufw enable
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de Systemd Services
|
||||
|
||||
### flotillas-api.service
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=FlotillasGPS API Backend
|
||||
After=network.target postgresql.service redis.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=www-data
|
||||
Group=www-data
|
||||
WorkingDirectory=/opt/flotillas/backend
|
||||
Environment="PATH=/opt/flotillas/venv/bin"
|
||||
EnvironmentFile=/opt/flotillas/.env
|
||||
ExecStart=/opt/flotillas/venv/bin/uvicorn app.main:app \
|
||||
--host 127.0.0.1 \
|
||||
--port 8000 \
|
||||
--workers 4 \
|
||||
--loop uvloop \
|
||||
--http httptools
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
### flotillas-web.service
|
||||
|
||||
```ini
|
||||
[Unit]
|
||||
Description=FlotillasGPS Web Frontend
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=www-data
|
||||
Group=www-data
|
||||
WorkingDirectory=/opt/flotillas/frontend
|
||||
ExecStart=/usr/bin/npx serve -s dist -l 3000
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion desde el Dashboard
|
||||
|
||||
Muchas configuraciones se pueden cambiar desde **Configuracion** en el dashboard:
|
||||
|
||||
### General
|
||||
- Zona horaria
|
||||
- Unidades (km/millas, litros/galones)
|
||||
- Moneda
|
||||
- Idioma
|
||||
|
||||
### Alertas
|
||||
- Velocidad maxima global
|
||||
- Tiempo de parada para alerta (minutos)
|
||||
- Tiempo offline para alerta (minutos)
|
||||
- Notificaciones por email
|
||||
|
||||
### Mapa
|
||||
- Proveedor de mapas
|
||||
- Estilo (claro/oscuro)
|
||||
- Capas por defecto
|
||||
|
||||
### Retencion de Datos
|
||||
- Dias de ubicaciones detalladas
|
||||
- Dias de ubicaciones agregadas
|
||||
- Dias de grabaciones de video
|
||||
- Dias de alertas
|
||||
|
||||
---
|
||||
|
||||
## Aplicar Cambios
|
||||
|
||||
Despues de modificar archivos de configuracion:
|
||||
|
||||
```bash
|
||||
# Recargar configuracion de systemd
|
||||
systemctl daemon-reload
|
||||
|
||||
# Reiniciar servicio especifico
|
||||
systemctl restart flotillas-api
|
||||
|
||||
# Reiniciar todos los servicios
|
||||
systemctl restart flotillas-api flotillas-web traccar mediamtx
|
||||
|
||||
# Verificar estado
|
||||
systemctl status flotillas-api flotillas-web traccar mediamtx
|
||||
```
|
||||
Reference in New Issue
Block a user