Files
aitsc/docs/development/Windows生产环境部署指南.md

206 lines
3.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Windows 生产环境部署指南
## 📋 概述
本指南介绍如何在 Windows 环境下部署 Flask 提示词大师应用的生产环境。
## 🎯 部署方案
### 方案一Waitress 服务器(推荐)
Waitress 是一个纯 Python 的 WSGI 服务器,完全兼容 Windows 环境。
#### 1. 安装依赖
```bash
pip install -r requirements.txt
```
#### 2. 启动生产环境
**方法一:使用 Python 脚本**
```bash
python run_production.py
```
**方法二:使用批处理文件**
```bash
start_production.bat
```
#### 3. 停止服务器
**方法一Ctrl+C**
在运行窗口按 `Ctrl+C` 停止服务器
**方法二:使用批处理文件**
```bash
stop_production.bat
```
## ⚙️ 配置说明
### 环境变量配置
生产环境需要设置以下环境变量:
```bash
# 设置生产环境
set FLASK_ENV=production
# 数据库配置
set DATABASE_URL=mysql+pymysql://root:123456@localhost:3306/pro_db?charset=utf8mb4
# API 配置
set LLM_API_URL=https://api.deepseek.com/v1
set LLM_API_KEY=your-actual-api-key
# 微信小程序配置
set WX_APPID=your-wx-appid
set WX_SECRET=your-wx-secret
# 安全配置
set SECRET_KEY=your-secret-key
```
### 服务器配置
Waitress 服务器配置(在 `run_production.py` 中):
```python
serve(
app,
host='0.0.0.0', # 监听所有网络接口
port=5000, # 端口号
threads=4, # 线程数
connection_limit=1000, # 连接限制
cleanup_interval=30, # 清理间隔
channel_timeout=120, # 通道超时
max_request_body_size=1073741824, # 最大请求体大小1GB
)
```
## 📊 性能优化
### 1. 数据库优化
- 使用连接池
- 配置适当的索引
- 定期清理日志表
### 2. 缓存策略
- 启用 Redis 缓存
- 配置模板缓存
- 实现 API 响应缓存
### 3. 日志管理
- 配置日志轮转
- 设置日志级别
- 监控错误日志
## 🔒 安全配置
### 1. 网络安全
- 配置防火墙规则
- 使用 HTTPS
- 限制访问 IP
### 2. 应用安全
- 启用 CSRF 保护
- 配置 CORS 策略
- 输入验证和过滤
### 3. 数据安全
- 数据库访问控制
- 敏感信息加密
- 定期备份
## 📈 监控和维护
### 1. 健康检查
访问健康检查接口:
```
GET http://localhost:5000/health
```
### 2. 日志监控
- 应用日志:`logs/app.log`
- 访问日志:`logs/access.log`
- 错误日志:`logs/error.log`
### 3. 性能监控
- CPU 使用率
- 内存使用情况
- 响应时间
- 并发连接数
## 🚀 部署脚本
### 启动脚本
`start_production.bat` - 生产环境启动脚本
### 停止脚本
`stop_production.bat` - 生产环境停止脚本
### 部署脚本
`deploy.sh` - 自动化部署脚本Linux 环境)
## 🔧 故障排除
### 常见问题
1. **端口被占用**
```bash
netstat -ano | findstr :5000
taskkill /PID <进程ID> /F
```
2. **数据库连接失败**
- 检查数据库服务状态
- 验证连接字符串
- 确认网络连接
3. **API 调用失败**
- 检查 API 密钥配置
- 验证网络连接
- 查看错误日志
### 日志分析
```bash
# 查看应用日志
type logs\app.log
# 查看错误日志
type logs\error.log
# 实时监控日志
Get-Content logs\app.log -Wait
```
## 📞 技术支持
如遇到问题,请:
1. 查看日志文件
2. 检查配置参数
3. 验证环境变量
4. 联系技术支持
---
**版本**: 1.0
**更新日期**: 2025-08-17
**维护者**: 开发团队