티스토리 뷰
반응형
☁️ AI 퀀트 시스템 실전 배포 – Docker Compose + Nginx + SSL 완전 설정 가이드
— 로컬에서 만든 AI 투자 시스템을 클라우드에서 “운용 가능한 서비스”로 만드는 법
이제 우리는 완전한 AI 퀀트 시스템을 구축했습니다.
- 데이터 수집 (Airflow)
- 모델 학습/배포 (MLflow)
- 실시간 트레이딩 (Redis + Flask)
- 리스크 모니터링 (Streamlit)
이번 글에서는 이 모든 구성요소를 Docker Compose 기반으로 클라우드 서버에 배포하고,
Nginx Reverse Proxy + SSL 인증서로 HTTPS 접속까지 설정해봅니다.
🎯 이번 글의 목표
“AI 퀀트 시스템을 도커 컨테이너로 완전히 분리하고,
도메인 + HTTPS 환경에서 안전하게 외부 접근 가능한 형태로 배포한다.”
⚙️ 1️⃣ 전체 아키텍처
┌──────────────────────────────────────────────────────────┐
│ Cloud Server (Ubuntu 22.04) │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ MLflow API │ ← │ PostgreSQL │ → │ Airflow │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ ↑ ↑ │ │
│ │ │ │ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Flask API │ → │ Redis Cache │ → │ Streamlit │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ↓ │
│ Nginx Reverse Proxy │
│ ↓ │
│ https://quant.ai.example.com │
└──────────────────────────────────────────────────────────┘
🧱 2️⃣ Docker Compose 설정
version: "3.9"
services:
postgres:
image: postgres:15
container_name: quant_postgres
environment:
POSTGRES_USER: quant
POSTGRES_PASSWORD: quant123
POSTGRES_DB: quantdb
volumes:
- ./postgres:/var/lib/postgresql/data
networks: [quant]
redis:
image: redis:7
container_name: quant_redis
networks: [quant]
mlflow:
image: cr.fly.io/mlflow:latest
container_name: quant_mlflow
environment:
BACKEND_STORE_URI: postgresql://quant:quant123@postgres:5432/quantdb
ARTIFACT_ROOT: /mlruns
ports:
- "5001:5001"
command: >
mlflow server
--backend-store-uri postgresql://quant:quant123@postgres:5432/quantdb
--default-artifact-root /mlruns
--host 0.0.0.0
--port 5001
networks: [quant]
depends_on: [postgres]
flask:
build: ./flask
container_name: quant_flask
ports:
- "6000:6000"
depends_on: [mlflow, redis]
networks: [quant]
streamlit:
build: ./streamlit
container_name: quant_streamlit
ports:
- "8501:8501"
depends_on: [flask, redis, postgres]
networks: [quant]
nginx:
image: nginx:alpine
container_name: quant_nginx
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./certs:/etc/ssl/certs
ports:
- "80:80"
- "443:443"
depends_on: [streamlit, flask]
networks: [quant]
networks:
quant:
driver: bridge
🌐 3️⃣ Nginx Reverse Proxy 설정
nginx/nginx.conf
events {}
http {
upstream flask_backend {
server flask:6000;
}
upstream streamlit_front {
server streamlit:8501;
}
server {
listen 80;
server_name quant.ai.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name quant.ai.example.com;
ssl_certificate /etc/ssl/certs/fullchain.pem;
ssl_certificate_key /etc/ssl/certs/privkey.pem;
location /api/ {
proxy_pass http://flask_backend/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
proxy_pass http://streamlit_front/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
🔒 4️⃣ SSL 인증서 설정
Let's Encrypt (Certbot) 설치 후 자동 인증서 발급:
sudo apt install certbot python3-certbot-nginx
sudo certbot certonly --nginx -d quant.ai.example.com
인증서 위치 확인:
/etc/letsencrypt/live/quant.ai.example.com/fullchain.pem
/etc/letsencrypt/live/quant.ai.example.com/privkey.pem
Nginx에 위 경로를 적용합니다.
🧰 5️⃣ Flask API Dockerfile
flask/Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
EXPOSE 6000
CMD ["python", "main.py"]
🧰 6️⃣ Streamlit Dockerfile
streamlit/Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
EXPOSE 8501
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
🚀 7️⃣ 배포 실행
docker compose up -d --build
확인:
- MLflow → http://quant.ai.example.com:5001
- Streamlit 대시보드 → https://quant.ai.example.com
- Flask API → https://quant.ai.example.com/api/risk_status
📡 8️⃣ 자동 재배포 (CI/CD 연동)
GitHub Actions 예시:
name: Deploy Quant System
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Copy files to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ubuntu
key: ${{ secrets.SSH_KEY }}
source: "."
target: "/home/ubuntu/quant-system"
- name: Run Docker Compose
run: ssh -i ${{ secrets.SSH_KEY }} ubuntu@${{ secrets.SERVER_IP }} "cd /home/ubuntu/quant-system && docker compose up -d --build"
커밋만 푸시하면 서버에서 자동으로 컨테이너를 재빌드하고 재배포합니다.
🧠 9️⃣ 보안 및 모니터링 팁
- UFW 방화벽 설정
- sudo ufw allow 22,80,443/tcp sudo ufw enable
- Nginx Access/Error 로그 → /var/log/nginx/
- MLflow UI 접속 제한 시 Basic Auth 추가
✅ 배포 완료 결과
- https://quant.ai.example.com → 실시간 AI 퀀트 대시보드
- https://quant.ai.example.com/api/risk_status → Flask API 리스크 상태
- 내부 네트워크: MLflow / Redis / Airflow 연동
이제 “AI가 운영하는 퀀트 펀드”가 클라우드 상에서 24시간 자동으로 작동합니다.
📘 다음 글 예고
다음 편에서는 **“AI 퀀트 전략의 성능 분석과 최적화 – Hyperparameter Tuning + AutoML 파이프라인”**을 다룹니다.
즉, 모델 성능을 주기적으로 자동 검증하고,
가장 성과 좋은 모델만 운영 환경으로 승격시키는 AutoML 구조를 완성할 예정입니다.
DockerCompose,MLflow,Nginx,SSL배포,Streamlit,AI퀀트,클라우드운영,DevOps,CI/CD,자동배포
'주식' 카테고리의 다른 글
| 🤖 강화학습 기반 AI 자기진화 퀀트 트레이딩 시스템 (0) | 2025.11.25 |
|---|---|
| ⚙️ AI 퀀트 전략의 성능 최적화 – AutoML + Hyperparameter Tuning 파이프라인 구축 (0) | 2025.11.17 |
| 📊 AI 퀀트 통합 운용 대시보드 구축 – Streamlit으로 실시간 트레이딩·리스크·성과를 한눈에 (0) | 2025.11.12 |
| 🔄 AI 글로벌 자산 로테이션 엔진 – 경기·금리·물가에 따라 스스로 자산을 갈아타는 시스템 (0) | 2025.11.12 |
| 🌍 글로벌 멀티에셋 자산배분 AI 시스템 구축 (0) | 2025.11.11 |
※ 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- flax
- nextJS
- node.js
- SEO최적화
- CI/CD
- 프론트엔드개발
- Python
- Next.js
- DevOps
- 쿠버네티스
- 딥러닝
- Docker
- JAX
- ai철학
- Redis
- rag
- 개발블로그
- fastapi
- llm
- seo 최적화 10개
- Prisma
- REACT
- Express
- PostgreSQL
- 압박면접
- 웹개발
- 백엔드개발
- JWT
- NestJS
- kotlin
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
글 보관함
반응형
