221 lines
5.7 KiB
Bash
Executable File
221 lines
5.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Script para desplegar LiveKit self-hosted con exposición pública
|
|
|
|
set -e
|
|
|
|
# Colores
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
echo -e "${BLUE}🏠 Configurando LiveKit Self-Hosted con exposición pública${NC}"
|
|
echo ""
|
|
|
|
# Detectar IP local
|
|
LOCAL_IP=$(hostname -I | awk '{print $1}')
|
|
echo -e "${BLUE}🌐 IP Local detectada: $LOCAL_IP${NC}"
|
|
|
|
# Preguntar dominio/IP pública
|
|
echo "¿Cuál es tu configuración de acceso público?"
|
|
echo "1) Tengo IP pública fija"
|
|
echo "2) IP dinámica - usar DuckDNS"
|
|
echo "3) Solo testing local"
|
|
echo ""
|
|
read -p "Selecciona opción (1-3): " IP_OPTION
|
|
|
|
case $IP_OPTION in
|
|
1)
|
|
read -p "Ingresa tu IP pública: " PUBLIC_IP
|
|
EXTERNAL_HOST="$PUBLIC_IP"
|
|
;;
|
|
2)
|
|
read -p "Ingresa tu subdominio DuckDNS (ej: mi-livekit): " DUCKDNS_SUBDOMAIN
|
|
EXTERNAL_HOST="$DUCKDNS_SUBDOMAIN.duckdns.org"
|
|
echo -e "${YELLOW}📝 Recuerda configurar DuckDNS token después${NC}"
|
|
;;
|
|
3)
|
|
EXTERNAL_HOST="$LOCAL_IP"
|
|
echo -e "${YELLOW}⚠️ Solo funcionará en red local${NC}"
|
|
;;
|
|
*)
|
|
echo -e "${RED}❌ Opción inválida${NC}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
echo -e "${GREEN}🌐 Host externo configurado: $EXTERNAL_HOST${NC}"
|
|
|
|
# Generar secretos seguros
|
|
API_SECRET=$(openssl rand -hex 32)
|
|
REDIS_PASSWORD=$(openssl rand -hex 16)
|
|
|
|
echo -e "${YELLOW}🔧 Generando configuración...${NC}"
|
|
|
|
# Crear directorio SSL
|
|
mkdir -p ssl logs
|
|
|
|
# Generar livekit-production.yaml
|
|
cat > livekit-production.yaml << EOF
|
|
port: 7880
|
|
bind_addresses: ["0.0.0.0"]
|
|
|
|
# API Keys seguros (generados automáticamente)
|
|
keys:
|
|
production-key: $API_SECRET
|
|
|
|
# Redis para persistence y scaling
|
|
redis:
|
|
address: "redis:6379"
|
|
password: "$REDIS_PASSWORD"
|
|
db: 0
|
|
|
|
# RTC Configuration para acceso público
|
|
rtc:
|
|
# Rango de puertos UDP reducido pero suficiente
|
|
port_range_start: 50000
|
|
port_range_end: 50100
|
|
|
|
# Host/IP externa para acceso público
|
|
use_external_ip: true
|
|
external_ip: "$EXTERNAL_HOST"
|
|
|
|
# STUN servers para NAT traversal
|
|
ice_servers:
|
|
- urls: ["stun:stun.l.google.com:19302"]
|
|
- urls: ["stun:stun1.l.google.com:19302"]
|
|
|
|
# Room settings para producción
|
|
room:
|
|
auto_create: true
|
|
max_participants: 25
|
|
empty_timeout: 600
|
|
|
|
# Logging para producción
|
|
log_level: info
|
|
log_format: json
|
|
EOF
|
|
|
|
# Crear docker-compose-livekit-server.yml
|
|
cat > docker-compose-livekit-server.yml << EOF
|
|
version: '3.8'
|
|
|
|
services:
|
|
livekit-server:
|
|
image: livekit/livekit-server:latest
|
|
container_name: livekit-production
|
|
restart: unless-stopped
|
|
ports:
|
|
- "7880:7880"
|
|
- "50000-50100:50000-50100/udp"
|
|
volumes:
|
|
- ./livekit-production.yaml:/livekit.yaml:ro
|
|
- ./logs:/app/logs
|
|
command: --config /livekit.yaml
|
|
networks:
|
|
- livekit-network
|
|
depends_on:
|
|
- redis
|
|
|
|
redis:
|
|
image: redis:7-alpine
|
|
container_name: livekit-redis
|
|
restart: unless-stopped
|
|
ports:
|
|
- "6379:6379"
|
|
command: redis-server --requirepass $REDIS_PASSWORD
|
|
volumes:
|
|
- redis_data:/data
|
|
networks:
|
|
- livekit-network
|
|
|
|
volumes:
|
|
redis_data:
|
|
|
|
networks:
|
|
livekit-network:
|
|
driver: bridge
|
|
EOF
|
|
|
|
# Crear variables para OpenVidu Meet
|
|
cat > .env.livekit-client << EOF
|
|
# Variables para EasyPanel/OpenVidu Meet
|
|
LIVEKIT_URL=ws://$EXTERNAL_HOST:7880
|
|
LIVEKIT_API_KEY=production-key
|
|
LIVEKIT_API_SECRET=$API_SECRET
|
|
EOF
|
|
|
|
echo -e "${GREEN}✅ Configuración generada${NC}"
|
|
|
|
# Configurar firewall
|
|
echo -e "${YELLOW}🔥 Configurando firewall...${NC}"
|
|
if command -v ufw &> /dev/null; then
|
|
sudo ufw allow 7880/tcp comment "LiveKit API"
|
|
sudo ufw allow 50000:50100/udp comment "LiveKit WebRTC"
|
|
echo -e "${GREEN}✅ Firewall configurado${NC}"
|
|
fi
|
|
|
|
# Parar servicios existentes
|
|
echo -e "${YELLOW}🛑 Parando servicios existentes...${NC}"
|
|
docker-compose -f docker-compose-livekit-server.yml down 2>/dev/null || true
|
|
|
|
# Iniciar LiveKit Server
|
|
echo -e "${YELLOW}🚀 Iniciando LiveKit Server...${NC}"
|
|
docker-compose -f docker-compose-livekit-server.yml up -d
|
|
|
|
# Esperar inicio
|
|
echo -e "${YELLOW}⏳ Esperando que LiveKit inicie...${NC}"
|
|
sleep 15
|
|
|
|
# Verificar servicios
|
|
echo -e "${BLUE}🔍 Verificando servicios...${NC}"
|
|
|
|
if curl -s http://localhost:7880 > /dev/null 2>&1; then
|
|
echo -e "${GREEN}✅ LiveKit API funcionando${NC}"
|
|
else
|
|
echo -e "${RED}❌ LiveKit no responde${NC}"
|
|
fi
|
|
|
|
if docker exec livekit-redis redis-cli -a $REDIS_PASSWORD ping > /dev/null 2>&1; then
|
|
echo -e "${GREEN}✅ Redis funcionando${NC}"
|
|
else
|
|
echo -e "${RED}❌ Redis no responde${NC}"
|
|
fi
|
|
|
|
# Mostrar configuración final
|
|
echo -e "${GREEN}"
|
|
echo "============================================="
|
|
echo "🎉 LIVEKIT SELF-HOSTED CONFIGURADO"
|
|
echo "============================================="
|
|
echo "🌐 Host externo: $EXTERNAL_HOST"
|
|
echo "🔌 Puerto API: 7880"
|
|
echo "📡 Puertos UDP: 50000-50100"
|
|
echo ""
|
|
echo "📋 CONFIGURACIÓN PARA OPENVIDU MEET:"
|
|
echo " LIVEKIT_URL=ws://$EXTERNAL_HOST:7880"
|
|
echo " LIVEKIT_API_KEY=production-key"
|
|
echo " LIVEKIT_API_SECRET=$API_SECRET"
|
|
echo ""
|
|
echo "🔧 PASOS SIGUIENTES:"
|
|
echo "1. Configurar port forwarding en router:"
|
|
echo " - TCP 7880 → $LOCAL_IP:7880"
|
|
echo " - UDP 50000-50100 → $LOCAL_IP:50000-50100"
|
|
echo ""
|
|
if [[ $IP_OPTION == 2 ]]; then
|
|
echo "2. Configurar DuckDNS:"
|
|
echo " - Token en duckdns.org"
|
|
echo " - Script de actualización automática"
|
|
echo ""
|
|
fi
|
|
echo "3. Configurar OpenVidu Meet con variables generadas"
|
|
echo "4. (Opcional) Configurar SSL/HTTPS con Let's Encrypt"
|
|
echo "============================================="
|
|
echo -e "${NC}"
|
|
|
|
# Mostrar logs
|
|
read -p "¿Ver logs de LiveKit en tiempo real? (y/N): " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
docker-compose -f docker-compose-livekit-server.yml logs -f livekit-server
|
|
fi |