本文档提供了 OpenLucky 在不同环境下的详细部署说明。
This document provides detailed deployment instructions for OpenLucky in different environments.
Linux/macOS:
# 使用安装脚本 / Use installation script
chmod +x install.sh
./install.shWindows:
REM 运行Windows安装脚本 / Run Windows installation script
install.bat-
环境准备 / Environment Preparation
# 创建虚拟环境 / Create virtual environment python -m venv openlucky-env # 激活虚拟环境 / Activate virtual environment source openlucky-env/bin/activate # Linux/Mac openlucky-env\Scripts\activate # Windows
-
安装依赖 / Install Dependencies
pip install --upgrade pip pip install -r requirements.txt
-
配置设置 / Configuration Setup
cp config.ini.template config.ini # 编辑 config.ini 添加API密钥 # Edit config.ini to add API keys
-
构建镜像 / Build Image
docker build -t openlucky:v1.0 . -
运行容器 / Run Container
# 创建必要目录 / Create necessary directories mkdir -p data logs # 运行容器 / Run container docker run -d \ --name openlucky-bot \ --restart unless-stopped \ -v $(pwd)/config.ini:/app/config.ini:ro \ -v $(pwd)/data:/app/data \ -v $(pwd)/logs:/app/logs \ openlucky:v1.0
-
查看日志 / View Logs
docker logs -f openlucky-bot
-
启动服务 / Start Services
# 启动所有服务 / Start all services docker-compose up -d # 查看服务状态 / Check service status docker-compose ps
-
查看日志 / View Logs
# 查看所有服务日志 / View all service logs docker-compose logs -f # 查看特定服务日志 / View specific service logs docker-compose logs -f openlucky
-
停止服务 / Stop Services
docker-compose down
推荐配置 / Recommended Configuration:
- CPU: 1-2 cores
- 内存 / Memory: 2GB+
- 存储 / Storage: 20GB+
- 网络 / Network: 稳定的网络连接
-
系统更新 / System Update
# Ubuntu/Debian sudo apt update && sudo apt upgrade -y sudo apt install python3 python3-pip git -y # CentOS/RHEL sudo yum update -y sudo yum install python3 python3-pip git -y
-
防火墙配置 / Firewall Configuration
# 开放必要端口(如果需要Web界面) # Open necessary ports (if web interface needed) sudo ufw allow 22 # SSH sudo ufw allow 8080 # Web interface (optional) sudo ufw enable
-
系统服务配置 / System Service Configuration
# 创建systemd服务文件 / Create systemd service file sudo tee /etc/systemd/system/openlucky.service > /dev/null <<EOF [Unit] Description=OpenLucky Trading Bot After=network.target [Service] Type=simple User=ubuntu WorkingDirectory=/home/ubuntu/OpenLucky ExecStart=/home/ubuntu/OpenLucky/openlucky-env/bin/python main.py Restart=always RestartSec=10 [Install] WantedBy=multi-user.target EOF # 启用并启动服务 / Enable and start service sudo systemctl enable openlucky sudo systemctl start openlucky
-
服务状态检查 / Service Status Check
# 检查服务状态 / Check service status sudo systemctl status openlucky # 查看实时日志 / View real-time logs sudo journalctl -u openlucky -f
-
资源使用监控 / Resource Usage Monitoring
# 内存使用 / Memory usage free -h # 磁盘使用 / Disk usage df -h # CPU使用 / CPU usage top -p $(pgrep -f "python.*main.py")
-
日志轮转 / Log Rotation
# 配置logrotate / Configure logrotate sudo tee /etc/logrotate.d/openlucky > /dev/null <<EOF /home/ubuntu/OpenLucky/*.log { daily rotate 7 compress delaycompress missingok notifempty create 644 ubuntu ubuntu } EOF
-
数据备份 / Data Backup
# 创建备份脚本 / Create backup script #!/bin/bash DATE=$(date +%Y%m%d_%H%M%S) tar -czf "/backup/openlucky_backup_$DATE.tar.gz" \ /home/ubuntu/OpenLucky/data/ \ /home/ubuntu/OpenLucky/config.ini \ /home/ubuntu/OpenLucky/*.log
-
系统更新 / System Updates
# 定期更新依赖 / Regular dependency updates pip install --upgrade -r requirements.txt # 重启服务 / Restart service sudo systemctl restart openlucky
-
SSH安全配置 / SSH Security Configuration
# 禁用密码登录,只允许密钥登录 # Disable password login, only allow key login sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config sudo systemctl restart ssh
-
文件权限设置 / File Permission Settings
# 设置配置文件权限 / Set config file permissions chmod 600 config.ini chmod 755 *.py chmod 644 *.md
-
自动安全更新 / Automatic Security Updates
# Ubuntu/Debian sudo apt install unattended-upgrades sudo dpkg-reconfigure unattended-upgrades
-
系统监控 / System Monitoring
- 使用 htop、iotop 监控系统资源
- 配置邮件或短信告警
- 设置磁盘空间告警
-
应用监控 / Application Monitoring
- 监控交易执行状态
- 跟踪API调用频率
- 记录异常情况
-
内存优化 / Memory Optimization
# 配置swap / Configure swap sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile -
网络优化 / Network Optimization
- 使用CDN加速API访问
- 配置DNS缓存
- 优化TCP参数
-
数据库优化 / Database Optimization
- 定期清理过期数据
- 优化数据存储格式
- 使用索引加速查询
-
并发优化 / Concurrency Optimization
- 调整并发参数
- 优化API调用频率
- 使用连接池
-
API连接问题 / API Connection Issues
# 测试网络连接 / Test network connection curl -I https://www.okx.com/api/v5/public/time curl -I https://api.x.ai/v1/models -
内存不足 / Out of Memory
# 检查内存使用 / Check memory usage ps aux --sort=-%mem | head # 重启服务释放内存 / Restart service to free memory sudo systemctl restart openlucky
-
磁盘空间不足 / Disk Space Full
# 清理日志文件 / Clean log files find . -name "*.log" -mtime +7 -delete # 清理旧数据 / Clean old data find ./data -name "*.json" -mtime +30 -delete
如果遇到部署问题,请:
If you encounter deployment issues, please:
- 📋 检查日志文件 / Check log files
- 🔍 搜索已知问题 / Search known issues
- 💬 在GitHub Discussions提问 / Ask in GitHub Discussions
- 🐛 创建详细的Issue报告 / Create detailed Issue report
🍀 祝您部署顺利!/ Good Luck with Your Deployment! 🍀