2.4 KiB
2.4 KiB
系统运行说明
一、环境准备
1. 安装必要软件
# 安装 Python 3.8+
# 安装 MySQL 8.0+
# 安装 Node.js 14+
2. 安装 Python 依赖
pip install -r requirements.txt
3. 安装前端依赖
cd frontend
npm install
二、数据库配置
1. 创建数据库
CREATE DATABASE equipment_cost_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
2. 初始化数据库结构
# 执行数据库结构初始化脚本
mysql -u username -p equipment_cost_db < src/schema.sql
# 导入示例数据
mysql -u username -p equipment_cost_db < src/init_data.sql
# 导入真实数据
mysql -u username -p equipment_cost_db < src/real_data.sql
三、配置文件
1. 后端配置
创建 config.py 文件:
# config.py
DATABASE_URI = "mysql+pymysql://username:password@localhost:3306/equipment_cost_db"
SECRET_KEY = "your-secret-key"
DEBUG = True
2. 前端配置
修改 frontend/src/config.js:
export const API_BASE_URL = 'http://localhost:5001/api';
四、启动系统
1. 启动后端服务
# 开发环境
python run.py # 服务将在 http://localhost:5001 启动
# 生产环境
gunicorn -w 4 -b 0.0.0.0:5001 run:app
2. 启动前端服务
# 开发环境
cd frontend
npm run serve # 前端将在 http://localhost:8080 启动
# 生产环境
npm run build
五、访问系统
- 后端API:http://localhost:5001/api
- 前端界面:http://localhost:8080
六、常见问题
1. 数据库连接问题
- 检查 MySQL 服务是否启动
- 验证数据库用户名和密码
- 确认数据库端口是否正确
2. 模型训练
# 训练模型
python src/train_model.py
# 查看训练日志
tail -f logs/training.log
3. 系统监控
# 查看系统日志
tail -f logs/app.log
# 监控API请求
tail -f logs/access.log
七、开发调试
1. 后端调试
# 启动调试模式
python run.py --debug
# 运行测试
python -m pytest tests/
2. 前端调试
# 启动开发服务器
npm run serve
# 运行测试
npm run test
八、部署建议
1. 使用 Docker 部署
# 构建镜像
docker-compose build
# 启动服务
docker-compose up -d
2. 生产环境配置
- 使用 Nginx 作为反向代理
- 配置 SSL 证书
- 设置适当的防火墙规则
- 启用数据库备份