프로덕션 설정
nginx, SSL/TLS, gunicorn, systemd, Docker로 Potato를 프로덕션 환경에 배포합니다. 리버스 프록시 구성, HTTPS 설정, 다중 사용자 성능 튜닝을 다룹니다.
여러 사용자, 데이터 영속성, 적절한 보안을 갖춘 실제 주석 작업을 위해 Potato를 배포합니다.
서버 구성
기본 프로덕션 구성
yaml
server:
host: 0.0.0.0
port: 8000
workers: 4
timeout: 120HTTPS 사용
보안 연결을 위해(프로덕션 환경에서 권장):
yaml
server:
host: 0.0.0.0
port: 443
ssl:
cert: /path/to/cert.pem
key: /path/to/key.pemGunicorn으로 실행하기
더 나은 성능과 안정성을 위해:
bash
gunicorn "potato.server:create_app('config.yaml')" \
--workers 4 \
--bind 0.0.0.0:8000 \
--timeout 120SSL 사용
bash
gunicorn "potato.server:create_app('config.yaml')" \
--workers 4 \
--bind 0.0.0.0:443 \
--certfile /path/to/cert.pem \
--keyfile /path/to/key.pem리버스 프록시 설정
Nginx 구성
nginx
upstream potato {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name annotation.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name annotation.example.com;
ssl_certificate /etc/letsencrypt/live/annotation.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/annotation.example.com/privkey.pem;
location / {
proxy_pass http://potato;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Increase timeouts for long annotation sessions
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
}Apache 구성
apache
<VirtualHost *:443>
ServerName annotation.example.com
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>Docker 배포
Dockerfile
dockerfile
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["gunicorn", "potato.server:create_app('config.yaml')", \
"--workers", "4", "--bind", "0.0.0.0:8000"]Docker Compose
yaml
version: '3.8'
services:
potato:
build: .
ports:
- "8000:8000"
volumes:
- ./data:/app/data
- ./annotations:/app/annotations
environment:
- POTATO_DEBUG=false
restart: unless-stopped
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./certs:/etc/ssl/certs
depends_on:
- potato
restart: unless-stopped사용자 인증
접근 제한
yaml
allow_all_users: false
authorized_users:
- user1@example.com
- user2@example.com
- user3@example.com관리자 접근
yaml
admin_users:
- admin@example.com
admin_dashboard:
enabled: true
path: /admin세션 관리
yaml
session:
secret_key: "your-secure-secret-key-here"
timeout: 3600 # 1 hour
secure_cookie: true # Requires HTTPS데이터 영속성
파일 기반 저장소
yaml
output:
path: /var/potato/annotations/
format: json
backup_interval: 3600 # Hourly backups데이터베이스 백엔드
규모가 큰 배포의 경우 MySQL을 사용합니다:
yaml
database:
type: mysql
host: localhost
port: 3306
name: potato_db
user: potato
password: ${DB_PASSWORD} # Use environment variable자세한 내용은 MySQL Backend를 참고하십시오.
모니터링
상태 확인 엔드포인트
yaml
monitoring:
health_check: /health
metrics: /metrics로깅 구성
yaml
logging:
level: INFO
file: /var/log/potato/app.log
max_size: 100MB
backup_count: 5
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"Prometheus 메트릭
yaml
monitoring:
prometheus:
enabled: true
port: 9090확장
수평 확장
트래픽이 많은 배포의 경우:
yaml
# docker-compose.yml
services:
potato:
deploy:
replicas: 3
# ... rest of config
nginx:
# Load balancer
volumes:
- ./nginx-lb.conf:/etc/nginx/nginx.conf로드 밸런서 구성
nginx
upstream potato_cluster {
least_conn;
server potato_1:8000;
server potato_2:8000;
server potato_3:8000;
}백업 전략
자동 백업
bash
#!/bin/bash
# backup.sh
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR=/var/backups/potato
# Backup annotations
tar -czf $BACKUP_DIR/annotations_$DATE.tar.gz /var/potato/annotations/
# Backup config
cp /var/potato/config.yaml $BACKUP_DIR/config_$DATE.yaml
# Keep only last 7 days
find $BACKUP_DIR -mtime +7 -deletecrontab에 추가합니다:
bash
0 2 * * * /var/potato/backup.sh보안 체크리스트
- 유효한 SSL 인증서로 HTTPS 사용
- 강력한 세션 시크릿 키 설정
-
authorized_users로 사용자 접근 제한 - Potato와 의존성을 최신 상태로 유지
- 민감한 데이터에 환경 변수 사용
- 방화벽 규칙 구성
- 로깅 및 모니터링 활성화
- 정기 백업 설정
- 프로덕션에 데이터베이스 백엔드 사용
- 관리자 접근 권한 정기 검토
환경 변수
bash
# .env file
POTATO_SECRET_KEY=your-super-secret-key
POTATO_DB_PASSWORD=database-password
POTATO_ADMIN_EMAIL=admin@example.comDocker Compose에서 로드합니다:
yaml
services:
potato:
env_file:
- .env문제 해결
로그 확인
bash
# Gunicorn logs
journalctl -u potato -f
# Docker logs
docker-compose logs -f potato일반적인 문제
502 Bad Gateway: Potato가 실행 중이며 올바른 포트에 바인딩되어 있는지 확인하십시오
세션 문제: 재시작 후에도 시크릿 키가 일관되게 유지되는지 확인하십시오
느린 성능: worker 수를 늘리거나 데이터베이스 백엔드를 추가하십시오
다음 단계
- MySQL Backend - 데이터베이스 저장소
- Crowdsourcing - Prolific/MTurk 통합
- 사용자 관리 - 접근 제어