2025-08-20 03:01:14 +08:00
|
|
|
|
# 部署文档
|
2025-08-18 23:48:54 +08:00
|
|
|
|
|
|
|
|
|
|
## 概述
|
|
|
|
|
|
|
2025-08-20 03:01:14 +08:00
|
|
|
|
本文档描述了锡林郭勒盟智慧养殖数字化管理平台的部署流程和配置要求。
|
2025-08-18 23:48:54 +08:00
|
|
|
|
|
|
|
|
|
|
## 部署架构
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
┌─────────────────────────────────────────────────────────────────────┐
|
|
|
|
|
|
│ 负载均衡器 │
|
|
|
|
|
|
├─────────────────────────────────────────────────────────────────────┤
|
|
|
|
|
|
│ Web服务器 (Nginx) │
|
|
|
|
|
|
├─────────────────────────────────────────────────────────────────────┤
|
|
|
|
|
|
│ 前端静态文件 │ 后端API服务 (Node.js) │
|
|
|
|
|
|
├─────────────────────────────────────────────────────────────────────┤
|
|
|
|
|
|
│ MySQL数据库 │ 腾讯云对象存储 │
|
|
|
|
|
|
└─────────────────────────────────────────────────────────────────────┘
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2025-08-19 22:04:18 +08:00
|
|
|
|
## 硬件配置
|
|
|
|
|
|
- **Web服务器**: 4核CPU / 8GB内存 / 100GB SSD
|
|
|
|
|
|
- **数据库服务器**: 8核CPU / 16GB内存 / 500GB SSD(主从配置)
|
|
|
|
|
|
- **缓存服务器**: 2核CPU / 4GB内存 / 50GB SSD(Redis)
|
|
|
|
|
|
|
|
|
|
|
|
## CI/CD流程
|
|
|
|
|
|
1. **代码提交**: 触发GitHub Actions
|
|
|
|
|
|
2. **自动化测试**: 运行单元测试和集成测试
|
|
|
|
|
|
3. **构建镜像**: 使用Docker构建前后端镜像
|
|
|
|
|
|
4. **部署**: 通过Kubernetes滚动更新到生产环境
|
|
|
|
|
|
|
|
|
|
|
|
## 监控与日志
|
|
|
|
|
|
- **监控工具**: Prometheus + Grafana
|
|
|
|
|
|
- **日志收集**: ELK Stack(Elasticsearch, Logstash, Kibana)
|
|
|
|
|
|
|
2025-08-18 23:48:54 +08:00
|
|
|
|
## 环境要求
|
|
|
|
|
|
|
|
|
|
|
|
### 服务器要求
|
|
|
|
|
|
- 操作系统: Linux (推荐Ubuntu 20.04+ 或 CentOS 8+)
|
|
|
|
|
|
- 内存: 8GB+
|
|
|
|
|
|
- 存储: 100GB+
|
|
|
|
|
|
- CPU: 4核+
|
|
|
|
|
|
|
|
|
|
|
|
### 软件依赖
|
|
|
|
|
|
- Node.js 16+
|
|
|
|
|
|
- MySQL 8.0+
|
|
|
|
|
|
- Nginx 1.20+
|
|
|
|
|
|
- Docker (可选,用于容器化部署)
|
|
|
|
|
|
- Git
|
|
|
|
|
|
|
|
|
|
|
|
## 部署步骤
|
|
|
|
|
|
|
|
|
|
|
|
### 1. 数据库部署
|
|
|
|
|
|
```bash
|
|
|
|
|
|
# 安装MySQL
|
|
|
|
|
|
sudo apt update
|
|
|
|
|
|
sudo apt install mysql-server
|
|
|
|
|
|
|
|
|
|
|
|
# 创建数据库
|
|
|
|
|
|
mysql -u root -p
|
|
|
|
|
|
CREATE DATABASE xlxumu CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
|
|
|
|
|
|
|
|
# 创建用户并授权
|
|
|
|
|
|
CREATE USER 'xlxumu'@'localhost' IDENTIFIED BY 'your_password';
|
|
|
|
|
|
GRANT ALL PRIVILEGES ON xlxumu.* TO 'xlxumu'@'localhost';
|
|
|
|
|
|
FLUSH PRIVILEGES;
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 2. 后端API服务部署
|
|
|
|
|
|
```bash
|
|
|
|
|
|
# 克隆代码
|
|
|
|
|
|
git clone [repository_url] /opt/xlxumu
|
2025-09-10 23:57:44 +08:00
|
|
|
|
cd /opt/xlxumu/backend-java
|
2025-08-18 23:48:54 +08:00
|
|
|
|
|
2025-09-10 23:57:44 +08:00
|
|
|
|
# 构建项目
|
|
|
|
|
|
mvn clean package
|
2025-08-18 23:48:54 +08:00
|
|
|
|
|
|
|
|
|
|
# 配置环境变量
|
2025-09-10 23:57:44 +08:00
|
|
|
|
cp services/farming-service/src/main/resources/application.yml.example services/farming-service/src/main/resources/application.yml
|
|
|
|
|
|
# 编辑application.yml文件,配置数据库连接等信息
|
2025-08-18 23:48:54 +08:00
|
|
|
|
|
|
|
|
|
|
# 启动服务
|
2025-09-10 23:57:44 +08:00
|
|
|
|
java -jar services/farming-service/target/farming-service.jar
|
2025-08-18 23:48:54 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 3. 前端应用部署
|
|
|
|
|
|
```bash
|
|
|
|
|
|
# 构建各个前端应用
|
2025-09-10 23:57:44 +08:00
|
|
|
|
cd /opt/xlxumu/frontend/official-website
|
2025-08-18 23:48:54 +08:00
|
|
|
|
# 构建静态网站
|
|
|
|
|
|
|
2025-09-10 23:57:44 +08:00
|
|
|
|
cd /opt/xlxumu/frontend/admin-system
|
2025-08-18 23:48:54 +08:00
|
|
|
|
npm install
|
|
|
|
|
|
npm run build
|
|
|
|
|
|
|
|
|
|
|
|
# 为其他管理系统执行相同操作
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 4. Nginx配置
|
|
|
|
|
|
```nginx
|
|
|
|
|
|
server {
|
|
|
|
|
|
listen 80;
|
|
|
|
|
|
server_name your_domain.com;
|
|
|
|
|
|
|
|
|
|
|
|
# 静态网站
|
|
|
|
|
|
location / {
|
2025-09-10 23:57:44 +08:00
|
|
|
|
root /opt/xlxumu/frontend/official-website/dist;
|
2025-08-18 23:48:54 +08:00
|
|
|
|
index index.html;
|
|
|
|
|
|
try_files $uri $uri/ =404;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# API代理
|
|
|
|
|
|
location /api/ {
|
|
|
|
|
|
proxy_pass http://localhost:8000/;
|
|
|
|
|
|
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 /farming-management/ {
|
2025-09-10 23:57:44 +08:00
|
|
|
|
alias /opt/xlxumu/frontend/admin-system/dist/;
|
2025-08-18 23:48:54 +08:00
|
|
|
|
try_files $uri $uri/ /farming-management/index.html;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# 为其他管理系统添加类似配置
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 容器化部署 (Docker)
|
|
|
|
|
|
|
|
|
|
|
|
### Docker Compose配置
|
|
|
|
|
|
```yaml
|
|
|
|
|
|
version: '3.8'
|
|
|
|
|
|
services:
|
|
|
|
|
|
mysql:
|
|
|
|
|
|
image: mysql:8.0
|
|
|
|
|
|
environment:
|
|
|
|
|
|
MYSQL_ROOT_PASSWORD: root_password
|
|
|
|
|
|
MYSQL_DATABASE: xlxumu
|
|
|
|
|
|
MYSQL_USER: xlxumu
|
|
|
|
|
|
MYSQL_PASSWORD: user_password
|
|
|
|
|
|
volumes:
|
|
|
|
|
|
- mysql_data:/var/lib/mysql
|
|
|
|
|
|
ports:
|
|
|
|
|
|
- "3306:3306"
|
|
|
|
|
|
|
|
|
|
|
|
api:
|
2025-09-10 23:57:44 +08:00
|
|
|
|
build: ./backend-java/services/farming-service
|
2025-08-18 23:48:54 +08:00
|
|
|
|
ports:
|
|
|
|
|
|
- "8000:8000"
|
|
|
|
|
|
environment:
|
|
|
|
|
|
- DB_HOST=mysql
|
|
|
|
|
|
- DB_USER=xlxumu
|
|
|
|
|
|
- DB_PASSWORD=user_password
|
|
|
|
|
|
- DB_NAME=xlxumu
|
|
|
|
|
|
depends_on:
|
|
|
|
|
|
- mysql
|
|
|
|
|
|
|
|
|
|
|
|
nginx:
|
|
|
|
|
|
image: nginx:alpine
|
|
|
|
|
|
ports:
|
|
|
|
|
|
- "80:80"
|
|
|
|
|
|
volumes:
|
|
|
|
|
|
- ./nginx.conf:/etc/nginx/nginx.conf
|
|
|
|
|
|
- ./frontend:/usr/share/nginx/html
|
|
|
|
|
|
depends_on:
|
|
|
|
|
|
- api
|
|
|
|
|
|
|
|
|
|
|
|
volumes:
|
|
|
|
|
|
mysql_data:
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 监控和日志
|
|
|
|
|
|
|
|
|
|
|
|
### 日志管理
|
|
|
|
|
|
- 应用日志: `/var/log/xlxumu/`
|
|
|
|
|
|
- Nginx日志: `/var/log/nginx/`
|
|
|
|
|
|
- MySQL日志: `/var/log/mysql/`
|
|
|
|
|
|
|
|
|
|
|
|
### 监控指标
|
|
|
|
|
|
- API响应时间
|
|
|
|
|
|
- 数据库查询性能
|
|
|
|
|
|
- 服务器资源使用率
|
|
|
|
|
|
- 用户访问统计
|
|
|
|
|
|
|
|
|
|
|
|
## 安全配置
|
|
|
|
|
|
|
|
|
|
|
|
### SSL证书
|
|
|
|
|
|
推荐使用Let's Encrypt免费SSL证书:
|
|
|
|
|
|
```bash
|
|
|
|
|
|
sudo apt install certbot python3-certbot-nginx
|
|
|
|
|
|
sudo certbot --nginx -d your_domain.com
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 防火墙配置
|
|
|
|
|
|
```bash
|
|
|
|
|
|
# 开放必要端口
|
|
|
|
|
|
sudo ufw allow 22
|
|
|
|
|
|
sudo ufw allow 80
|
|
|
|
|
|
sudo ufw allow 443
|
|
|
|
|
|
sudo ufw enable
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 备份策略
|
|
|
|
|
|
|
|
|
|
|
|
### 数据库备份
|
|
|
|
|
|
```bash
|
|
|
|
|
|
# 定时备份脚本
|
|
|
|
|
|
mysqldump -u xlxumu -p xlxumu > /backup/xlxumu_$(date +%Y%m%d).sql
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 文件备份
|
|
|
|
|
|
- 静态资源文件备份
|
|
|
|
|
|
- 配置文件备份
|
|
|
|
|
|
- 日志文件轮转
|
|
|
|
|
|
|
|
|
|
|
|
## 故障处理
|
|
|
|
|
|
|
|
|
|
|
|
### 常见问题
|
|
|
|
|
|
1. 数据库连接失败
|
|
|
|
|
|
2. API服务无响应
|
|
|
|
|
|
3. 前端页面加载缓慢
|
|
|
|
|
|
4. 权限认证问题
|
|
|
|
|
|
|
|
|
|
|
|
### 恢复流程
|
|
|
|
|
|
1. 检查服务状态
|
|
|
|
|
|
2. 查看日志文件
|
|
|
|
|
|
3. 恢复备份数据
|
|
|
|
|
|
4. 重启相关服务
|