CostPrediction/docs/deploy/deploy.md

176 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.

# 装备成本估算系统部署指南
## 一、系统要求
### 1. 基础软件
- Linux 操作系统 (推荐 Ubuntu 22.04+)
- Python 3.12 及相关组件
```bash
sudo apt update
sudo apt install python3 python3-pip python3-venv
sudo apt install python3-dev build-essential
```
- Node.js 14+ 及 npm
```bash
# 使用 nvm 安装 Node.js
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 14
nvm use 14
```
- Windows 操作系统 (推荐 Windows 10+)
- Python 3.12 及相关组件
参考:<https://www.python.org/downloads/>
- Node.js 14+ 及 npm
参考:<https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-windows>
```bash
# 设置执行策略
set-executionpolicy remotesigned
```
### 2. 数据库
- MySQL 8.0+
```bash
sudo apt install mysql-server mysql-client
sudo apt install libmysqlclient-dev
```
Windows 参考:<https://dev.mysql.com/downloads/installer/>
### 3. Python包依赖
```bash
# Windows系统下安装依赖
# 1. 创建并激活虚拟环境
python -m venv venv
.\venv\Scripts\activate
# 2. 设置pip源为国内镜像可选但推荐
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 3. 更新pip
python -m pip install --upgrade pip
# 4. 安装依赖包使用UTF-8编码
# PowerShell命令行
$env:PYTHONUTF8=1
pip install -r requirements.txt
# Linux系统下安装依赖
# 1. 创建并激活虚拟环境
python3 -m venv venv
source venv/bin/activate
# 2. 安装依赖包
pip install -r requirements.txt
# 解析Excel文件需要安装以下依赖
pip install pandas
pip install openpyxl
pip install xlrd
# 常见问题解决:
# 1. 如果遇到编码错误请确保使用UTF-8编码
# 2. 如果安装过程中出现权限问题,请使用管理员权限运行命令行
# 3. 如果下载速度慢,建议使用国内镜像源
# 4. 如果出现SSL证书错误可以尝试添加--trusted-host参数
pip install -r requirements.txt --trusted-host pypi.tuna.tsinghua.edu.cn
```
### 4. 科学计算相关
sudo apt install libatlas-base-dev # numpy依赖
sudo apt install libopenblas-dev # 线性代数库
sudo apt install liblapack-dev # 线性代数包
sudo apt install gfortran # Fortran编译器(scipy依赖)
## XML处理相关(用于Excel文件处理)
```bash
sudo apt install libxml2-dev
sudo apt install libxslt1-dev
```
## 二、部署运行
### 1. 安装服务
```bash
sh scripts/install.sh
```
### 2. 启动服务
```bash
sh scripts/start.sh
```
### 3. 停止服务
```bash
sh scripts/stop.sh
```
## 三、维护说明
### 1. 日志管理
```bash
# 后端日志
tail -f logs/api.log
# 数据库日志
tail -f /var/log/mysql/error.log
```
## 四、安全建议
1. 系统安全
- 使用防火墙限制端口访问
- 定期更新系统和依赖包
2. 数据安全
- 定期备份数据库
- 加密敏感信息
- 限制数据库远程访问
3. 访问控制
- 使用强密码
- 配置适当的文件权限
- 使用非root用户运行服务
## 五、监控方案
### 1. 系统监控
```bash
# 资源使用
top -b -n 1
df -h
free -m
# 服务状态
ps aux | grep gunicorn
ps aux | grep node
```
### 2. 应用监控
```bash
# API 响应时间
curl -w "@curl-format.txt" -o /dev/null -s "http://localhost:5001/api/"
# 错误日志
grep "ERROR" logs/api.log
```