272 lines
5.0 KiB
Markdown
272 lines
5.0 KiB
Markdown
# Blitz Panel - Docker Setup
|
|
|
|
## 📋 Prerequisites
|
|
|
|
- Docker Engine 20.10+
|
|
- Docker Compose 2.0+
|
|
- At least 2GB RAM
|
|
- Ports available: 8000 (API), 443 (Hysteria2), 80 (HTTP)
|
|
|
|
## 🚀 Quick Start
|
|
|
|
### 1. Prepare Your Files
|
|
|
|
Make sure your directory structure looks like this:
|
|
|
|
```
|
|
Blitz/
|
|
├── core/
|
|
│ └── scripts/
|
|
│ ├── auth/
|
|
│ ├── db/
|
|
│ ├── hysteria2/
|
|
│ └── ... (other script folders)
|
|
├── api.py
|
|
├── cli_api.py
|
|
├── requirements.txt
|
|
├── Dockerfile
|
|
├── docker-compose.yml
|
|
└── .dockerignore
|
|
```
|
|
|
|
### 2. Build and Run
|
|
|
|
```bash
|
|
# Build and start containers
|
|
docker-compose up -d --build
|
|
|
|
# Check logs
|
|
docker-compose logs -f blitz-api
|
|
|
|
# Check if services are running
|
|
docker-compose ps
|
|
```
|
|
|
|
### 3. Test the API
|
|
|
|
```bash
|
|
# Health check
|
|
curl http://localhost:8000/health
|
|
|
|
# Get API docs (interactive)
|
|
open http://localhost:8000/docs
|
|
```
|
|
|
|
## 📚 API Endpoints
|
|
|
|
### User Management
|
|
|
|
```bash
|
|
# List all users
|
|
curl http://localhost:8000/api/v1/users
|
|
|
|
# Get specific user
|
|
curl http://localhost:8000/api/v1/users/john
|
|
|
|
# Create user
|
|
curl -X POST http://localhost:8000/api/v1/users \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"username": "john",
|
|
"traffic_limit": 100,
|
|
"expiration_days": 30,
|
|
"unlimited": false
|
|
}'
|
|
|
|
# Edit user
|
|
curl -X PUT http://localhost:8000/api/v1/users/john \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"new_traffic_limit": 200,
|
|
"renew_creation_date": true
|
|
}'
|
|
|
|
# Delete user
|
|
curl -X DELETE http://localhost:8000/api/v1/users/john
|
|
|
|
# Get user URI
|
|
curl http://localhost:8000/api/v1/users/john/uri?qrcode=false
|
|
```
|
|
|
|
### Hysteria2 Management
|
|
|
|
```bash
|
|
# Install Hysteria2
|
|
curl -X POST http://localhost:8000/api/v1/hysteria2/install \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"port": 443,
|
|
"sni": "example.com"
|
|
}'
|
|
|
|
# Restart Hysteria2
|
|
curl -X POST http://localhost:8000/api/v1/hysteria2/restart
|
|
|
|
# Get current port
|
|
curl http://localhost:8000/api/v1/hysteria2/config/port
|
|
|
|
# Change port
|
|
curl -X PUT http://localhost:8000/api/v1/hysteria2/config/port \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"port": 8443}'
|
|
|
|
# Enable obfuscation
|
|
curl -X POST http://localhost:8000/api/v1/hysteria2/obfs/enable
|
|
```
|
|
|
|
### Traffic & Stats
|
|
|
|
```bash
|
|
# Get traffic status
|
|
curl http://localhost:8000/api/v1/traffic/status
|
|
|
|
# Get server info
|
|
curl http://localhost:8000/api/v1/info/server
|
|
|
|
# Get services status
|
|
curl http://localhost:8000/api/v1/info/services
|
|
```
|
|
|
|
## 🛠️ Development Mode
|
|
|
|
To run in development with auto-reload:
|
|
|
|
```bash
|
|
# Run API locally (not in Docker)
|
|
source /etc/hysteria/hysteria2_venv/bin/activate
|
|
cd /path/to/Blitz
|
|
uvicorn api:app --reload --host 0.0.0.0 --port 8000
|
|
```
|
|
|
|
## 🐛 Troubleshooting
|
|
|
|
### Container won't start
|
|
|
|
```bash
|
|
# Check logs
|
|
docker-compose logs blitz-api
|
|
|
|
# Check MongoDB
|
|
docker-compose logs mongodb
|
|
|
|
# Restart services
|
|
docker-compose restart
|
|
```
|
|
|
|
### Permission issues
|
|
|
|
```bash
|
|
# Fix permissions for scripts
|
|
docker-compose exec blitz-api bash
|
|
find /etc/hysteria/core/scripts -type f -name "*.sh" -exec chmod +x {} \;
|
|
find /etc/hysteria/core/scripts -type f -name "*.py" -exec chmod +x {} \;
|
|
```
|
|
|
|
### Network issues
|
|
|
|
```bash
|
|
# Check if ports are available
|
|
sudo netstat -tlnp | grep -E ':(8000|443|80)'
|
|
|
|
# If ports are in use, change them in docker-compose.yml
|
|
```
|
|
|
|
### Reset everything
|
|
|
|
```bash
|
|
# Stop and remove everything
|
|
docker-compose down -v
|
|
|
|
# Remove volumes (WARNING: deletes all data)
|
|
docker volume rm blitz_mongodb_data blitz_config blitz_certs
|
|
|
|
# Rebuild
|
|
docker-compose up -d --build
|
|
```
|
|
|
|
## 📊 Monitoring
|
|
|
|
```bash
|
|
# Watch logs in real-time
|
|
docker-compose logs -f
|
|
|
|
# Check resource usage
|
|
docker stats
|
|
|
|
# Execute commands in container
|
|
docker-compose exec blitz-api bash
|
|
```
|
|
|
|
## 🔒 Production Deployment
|
|
|
|
For production, modify `docker-compose.yml`:
|
|
|
|
1. **Add authentication** to the API (JWT, API keys)
|
|
2. **Use HTTPS** with proper SSL certificates
|
|
3. **Set up reverse proxy** (nginx/traefik)
|
|
4. **Configure firewall** rules
|
|
5. **Enable MongoDB authentication**
|
|
6. **Set resource limits**
|
|
|
|
Example production additions:
|
|
|
|
```yaml
|
|
# In docker-compose.yml
|
|
services:
|
|
blitz-api:
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '2'
|
|
memory: 2G
|
|
reservations:
|
|
cpus: '1'
|
|
memory: 1G
|
|
environment:
|
|
- API_KEY=your-secret-key
|
|
```
|
|
|
|
## 📝 Notes
|
|
|
|
- Default API runs on port 8000
|
|
- MongoDB stores data in named volume `mongodb_data`
|
|
- Configs persist in `blitz_config` volume
|
|
- All scripts from `core/` are copied into container
|
|
- Health check runs every 30 seconds
|
|
|
|
## 🤝 Common Tasks
|
|
|
|
### Backup
|
|
|
|
```bash
|
|
# Backup MongoDB data
|
|
docker-compose exec mongodb mongodump --out /data/backup
|
|
|
|
# Copy backup out
|
|
docker cp blitz-mongodb:/data/backup ./backup
|
|
```
|
|
|
|
### Update
|
|
|
|
```bash
|
|
# Pull latest code
|
|
git pull
|
|
|
|
# Rebuild
|
|
docker-compose up -d --build
|
|
```
|
|
|
|
### Scale
|
|
|
|
To run multiple instances (load balancing):
|
|
|
|
```bash
|
|
docker-compose up -d --scale blitz-api=3
|
|
```
|
|
|
|
## 🆘 Support
|
|
|
|
- Check logs: `docker-compose logs -f`
|
|
- Interactive docs: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|