Files
assist/Linux使用说明.md

260 lines
5.1 KiB
Markdown
Raw 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.
# TSP智能助手 Linux 使用说明
## 🐧 Linux环境部署指南
### 1. 系统要求
- **操作系统**: Ubuntu 18.04+, CentOS 7+, Debian 9+, Arch Linux
- **Node.js**: 18.x 或更高版本
- **Python**: 3.7 或更高版本
- **内存**: 至少 2GB RAM
- **磁盘**: 至少 1GB 可用空间
### 2. 快速开始
#### 方法一:一键安装(推荐)
```bash
# 下载并运行安装脚本
chmod +x install_dependencies.sh
./install_dependencies.sh
```
#### 方法二:手动安装
```bash
# 安装Node.js (Ubuntu/Debian)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# 安装Node.js (CentOS/RHEL)
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo yum install -y nodejs
# 安装Python依赖
pip3 install -r requirements.txt
# 安装前端依赖
cd frontend
npm install
cd ..
```
### 3. 启动服务
#### 启动传统版本(立即可用)
```bash
chmod +x start_traditional.sh
./start_traditional.sh
```
访问http://localhost:5000
#### 启动现代化前端需要Node.js
```bash
chmod +x start_frontend.sh
./start_frontend.sh
```
访问http://localhost:3000
#### 构建生产版本
```bash
chmod +x build_frontend.sh
./build_frontend.sh
```
### 4. 功能对比
| 功能 | 传统版本 | 现代化前端 |
|------|----------|------------|
| 基础功能 | ✅ 完整支持 | ✅ 完整支持 |
| 聊天系统 | ✅ 支持 | ✅ 统一组件 |
| 预警管理 | ✅ 支持 | ✅ 增强体验 |
| 国际化 | ❌ 仅中文 | ✅ 中英文切换 |
| 主题切换 | ❌ 固定主题 | ✅ 暗色/亮色 |
| 响应式设计 | ⚠️ 基础支持 | ✅ 完整支持 |
| 开发体验 | ⚠️ 传统开发 | ✅ 现代化开发 |
### 5. 常见问题
#### Q: Node.js安装失败
```bash
# 检查Node.js版本
node --version
npm --version
# 如果版本过低,重新安装
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
```
#### Q: Python依赖安装失败
```bash
# 升级pip
pip3 install --upgrade pip
# 重新安装依赖
pip3 install -r requirements.txt
```
#### Q: 前端依赖安装失败
```bash
# 清理缓存
npm cache clean --force
# 删除node_modules重新安装
rm -rf frontend/node_modules
cd frontend
npm install
```
#### Q: 端口被占用
```bash
# 查看端口占用
sudo netstat -tlnp | grep :5000
sudo netstat -tlnp | grep :3000
# 杀死占用进程
sudo kill -9 <PID>
```
### 6. 开发环境配置
#### 使用VS Code开发
```bash
# 安装VS Code
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
sudo apt install code
# 安装推荐扩展
code --install-extension ms-python.python
code --install-extension vue.volar
code --install-extension bradlc.vscode-tailwindcss
```
#### 使用Docker开发
```bash
# 创建Dockerfile
cat > Dockerfile << EOF
FROM node:20-alpine
WORKDIR /app
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ .
EXPOSE 3000
CMD ["npm", "run", "dev"]
EOF
# 构建并运行
docker build -t tsp-frontend .
docker run -p 3000:3000 tsp-frontend
```
### 7. 生产部署
#### 使用Nginx反向代理
```bash
# 安装Nginx
sudo apt install nginx
# 配置Nginx
sudo tee /etc/nginx/sites-available/tsp-assistant << EOF
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /api/ {
proxy_pass http://localhost:5000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF
# 启用站点
sudo ln -s /etc/nginx/sites-available/tsp-assistant /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
```
#### 使用PM2进程管理
```bash
# 安装PM2
npm install -g pm2
# 启动应用
pm2 start src/web/app.py --name "tsp-backend" --interpreter python3
pm2 start frontend/package.json --name "tsp-frontend"
# 保存配置
pm2 save
pm2 startup
```
### 8. 监控和日志
```bash
# 查看应用状态
pm2 status
# 查看日志
pm2 logs tsp-backend
pm2 logs tsp-frontend
# 重启应用
pm2 restart tsp-backend
pm2 restart tsp-frontend
```
### 9. 备份和恢复
```bash
# 备份数据库
cp tsp_assistant.db tsp_assistant_backup_$(date +%Y%m%d).db
# 备份配置文件
tar -czf config_backup_$(date +%Y%m%d).tar.gz config/
# 恢复数据库
cp tsp_assistant_backup_20240101.db tsp_assistant.db
```
---
## 🚀 快速命令参考
```bash
# 一键启动传统版本
./start_traditional.sh
# 一键启动现代化前端
./start_frontend.sh
# 构建生产版本
./build_frontend.sh
# 安装所有依赖
./install_dependencies.sh
```
现在您可以在Linux环境中愉快地使用TSP智能助手了🎉