# V2-Docker Operations Guide ## Deployment ### Prerequisites - Docker and Docker Compose - PostgreSQL 13+ - Python 3.8+ - Minimum 4GB RAM - 20GB disk space ### Initial Setup ```bash # Clone repository git clone cd v2-Docker # Set environment variables cp .env.example .env # Edit .env with your configuration # Start services docker-compose up -d # Run database migrations docker exec v2_adminpanel python manage.py migrate ``` ### Service Configuration #### License Server ```yaml v2_lizenzserver: image: v2_lizenzserver:latest environment: - DATABASE_URL=postgresql://user:pass@db:5432/v2 - JWT_SECRET=${JWT_SECRET} - API_KEY=${API_KEY} ports: - "8080:8080" ``` #### Admin Panel ```yaml v2_adminpanel: image: v2_adminpanel:latest environment: - DATABASE_URL=postgresql://user:pass@db:5432/v2 - SECRET_KEY=${SECRET_KEY} ports: - "5000:5000" ``` ## Monitoring ### Prometheus Configuration #### Scrape Configs ```yaml scrape_configs: - job_name: 'license-server' static_configs: - targets: ['v2_lizenzserver:8080'] - job_name: 'postgres' static_configs: - targets: ['postgres_exporter:9187'] ``` #### Alert Rules - License server down: `up{job="license-server"} == 0` - High error rate: `rate(http_requests_total{status=~"5.."}[5m]) > 0.05` - Database connections: `pg_stat_database_numbackends > 100` ### Grafana Dashboards 1. **System Overview Dashboard** - CPU and memory usage - Network traffic - Disk usage - Container status 2. **License Server Dashboard** - Active licenses - Heartbeat frequency - API response times - Error rates 3. **Database Performance Dashboard** - Query performance - Connection pool status - Table sizes - Slow queries ### Accessing Monitoring - Prometheus: http://localhost:9090 - Grafana: http://localhost:3001 (admin/admin) - Alertmanager: http://localhost:9093 ## Maintenance ### Database Maintenance #### Partition Management ```sql -- Check existing partitions SELECT tablename FROM pg_tables WHERE tablename LIKE 'license_heartbeats_%' ORDER BY tablename; -- Create future partitions manually CALL create_monthly_partitions('license_heartbeats', 3); -- Drop old partitions DROP TABLE IF EXISTS license_heartbeats_2024_01; ``` #### Backup Procedures ```bash # Full database backup docker exec v2_db pg_dump -U postgres v2 > backup_$(date +%Y%m%d).sql # Backup specific tables docker exec v2_db pg_dump -U postgres -t licenses -t license_activations v2 > licenses_backup.sql # Restore from backup docker exec -i v2_db psql -U postgres v2 < backup_20250619.sql ``` ### Log Management #### Log Locations - License Server: `/var/log/license-server/` - Admin Panel: `/var/log/adminpanel/` - Nginx: `/var/log/nginx/` #### Log Rotation ```bash # Configure logrotate /var/log/license-server/*.log { daily rotate 7 compress delaycompress notifempty create 0640 www-data www-data } ``` ### Performance Optimization #### Database Tuning ```sql -- Update statistics ANALYZE; -- Reindex tables REINDEX TABLE licenses; REINDEX TABLE license_activations; -- Vacuum tables VACUUM ANALYZE licenses; ``` #### Resource Limits ```yaml # Docker resource constraints services: v2_lizenzserver: deploy: resources: limits: cpus: '2' memory: 2G reservations: cpus: '1' memory: 1G ``` ## Troubleshooting ### Common Issues #### License Server Not Responding 1. Check container status: `docker ps` 2. View logs: `docker logs v2_lizenzserver` 3. Test database connection: `docker exec v2_lizenzserver pg_isready` 4. Verify JWT_SECRET is set #### Database Connection Issues 1. Check PostgreSQL status: `docker exec v2_db pg_isready` 2. Verify credentials in .env 3. Check network connectivity: `docker network ls` 4. Review PostgreSQL logs: `docker logs v2_db` #### High Memory Usage 1. Check container stats: `docker stats` 2. Review memory limits in docker-compose.yml 3. Analyze database queries for optimization 4. Consider scaling horizontally ### Health Checks ```bash # License server health curl http://localhost:8080/health # Database health docker exec v2_db pg_isready # Admin panel health curl http://localhost:5000/health # Monitoring stack curl http://localhost:9090/-/healthy # Prometheus curl http://localhost:3001/api/health # Grafana ``` ## Security Considerations ### API Security - Use strong JWT_SECRET (minimum 32 characters) - Rotate API keys regularly - Implement rate limiting - Use HTTPS in production ### Database Security - Use strong passwords - Limit database access - Enable SSL for connections - Regular security updates ### Container Security - Use official base images - Scan images for vulnerabilities - Don't run containers as root - Keep Docker updated ## Scaling Strategies ### Horizontal Scaling ```yaml # Scale license server docker-compose up -d --scale v2_lizenzserver=3 # Load balancing with Nginx upstream license_servers { server v2_lizenzserver_1:8080; server v2_lizenzserver_2:8080; server v2_lizenzserver_3:8080; } ``` ### Database Scaling - Read replicas for reporting - Connection pooling - Query optimization - Partitioning for large tables ## Disaster Recovery ### Backup Strategy - Daily automated backups - Off-site backup storage - Test restore procedures - Document recovery steps ### High Availability - Database replication - Service redundancy - Load balancing - Automated failover ## Monitoring Best Practices 1. **Set up alerts for critical metrics** 2. **Create runbooks for common issues** 3. **Regular review of dashboards** 4. **Capacity planning based on trends** 5. **Document all custom configurations**