feat: 项目初始化及当前全部内容提交

This commit is contained in:
2025-07-15 17:37:50 +08:00
parent ec817067f1
commit e78f192d34
622 changed files with 75174 additions and 383 deletions
+342
View File
@@ -0,0 +1,342 @@
# 情绪博物馆自定义目录部署指南
## 📋 部署架构
根据您的要求,本部署方案采用以下目录结构:
```
/data/
├── www/emotion-museum/ # 前端静态文件目录
│ ├── index.html
│ ├── assets/
│ └── ...
├── builds/ # 后端JAR文件目录
│ ├── emotion-gateway.jar
│ ├── emotion-ai.jar
│ └── emotion-user.jar
└── logs/emotion-museum/ # 日志目录
├── nginx/
├── gateway/
├── ai/
├── user/
├── mysql/
├── redis/
└── nacos/
```
## 🏗️ 服务架构
```
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ 用户访问 │───▶│ Nginx │───▶│ 静态文件 │
└─────────────┘ │ (80/443) │ │ /data/www/ │
└─────────────┘ └─────────────┘
┌─────────────┐ ┌─────────────┐
│ API代理 │───▶│ Gateway │
│ /api/* │ │ (9000) │
└─────────────┘ └─────────────┘
┌─────────────┐ ┌─────────────┐
│ 微服务集群 │ │ JAR文件 │
│ AI/User/... │ │ /data/builds│
└─────────────┘ └─────────────┘
```
## 🚀 快速部署
### 1. 准备环境
```bash
# 确保Docker和Docker Compose已安装
docker --version
docker-compose --version
# 创建必要目录
sudo mkdir -p /data/www/emotion-museum
sudo mkdir -p /data/builds
sudo mkdir -p /data/logs/emotion-museum
```
### 2. 配置环境变量
```bash
# 编辑环境变量文件
vim .env
```
**配置说明**
```bash
# Coze API配置(已配置为与开发环境一致)
COZE_API_TOKEN=pat_GCR4qKzqpf90wMCvKsldMrB18KG3QsLDci65bZthssKsbLxu8X70BKYumleDcabO
# 数据库密码(可根据需要修改)
MYSQL_ROOT_PASSWORD=123456
MYSQL_PASSWORD=emotion123
```
### 3. 一键部署
```bash
# 给脚本执行权限
chmod +x deploy-custom.sh
# 执行自定义部署
./deploy-custom.sh
```
## 📁 文件说明
### 新增配置文件
1. **`docker-compose.custom.yml`** - 自定义Docker配置
- 前端文件直接从宿主机目录提供
- 后端JAR文件挂载到容器
- 日志统一保存到指定目录
2. **`deploy-custom.sh`** - 自定义部署脚本
- 自动检查和构建前后端
- 部署文件到指定目录
- 启动Docker服务
3. **`manage-custom.sh`** - 自定义管理脚本
- 服务管理和监控
- 日志查看和健康检查
- 数据备份和恢复
### 修改的配置文件
1. **`deploy/nginx/conf.d/emotion-museum.conf`** - Nginx配置
- 前端文件直接从 `/data/www/emotion-museum` 提供
- API请求代理到Docker容器内的服务
- 日志保存到 `/data/logs/emotion-museum/nginx/`
2. **`deploy/nginx/nginx.conf`** - Nginx主配置
- 更新上游服务器定义
- 支持容器间通信
## 🔧 端口配置
| 服务 | 容器端口 | 宿主机端口 | 说明 |
|------|----------|------------|------|
| Nginx | 80/443 | 80/443 | Web访问 |
| Gateway | 9000 | 9000 | API网关 |
| AI Service | 9002 | 9002 | AI服务 |
| User Service | 9001 | 9001 | 用户服务 |
| MySQL | 3306 | 3306 | 数据库 |
| Redis | 6379 | 6379 | 缓存 |
| Nacos | 8848 | 8848 | 注册中心 |
## 🛠️ 管理命令
### 服务管理
```bash
# 启动所有服务
./manage-custom.sh start
# 停止所有服务
./manage-custom.sh stop
# 重启所有服务
./manage-custom.sh restart
# 重启指定服务
./manage-custom.sh restart emotion-ai
# 查看服务状态
./manage-custom.sh status
```
### 日志管理
```bash
# 查看所有日志
./manage-custom.sh logs
# 跟踪日志输出
./manage-custom.sh logs -f
# 查看指定服务日志
./manage-custom.sh logs -s nginx
./manage-custom.sh logs -s emotion-gateway
```
### 健康检查
```bash
# 执行健康检查
./manage-custom.sh health
# 实时监控
./manage-custom.sh monitor
```
### 数据管理
```bash
# 备份数据
./manage-custom.sh backup
# 更新服务
./manage-custom.sh update
# 清理资源
./manage-custom.sh clean
```
## 📊 目录详情
### 前端目录 `/data/www/emotion-museum/`
```
/data/www/emotion-museum/
├── index.html # 主页面
├── assets/ # 静态资源
│ ├── css/ # 样式文件
│ ├── js/ # JavaScript文件
│ └── images/ # 图片文件
└── favicon.ico # 网站图标
```
### 后端目录 `/data/builds/`
```
/data/builds/
├── emotion-gateway.jar # 网关服务JAR
├── emotion-ai.jar # AI服务JAR
└── emotion-user.jar # 用户服务JAR
```
### 日志目录 `/data/logs/emotion-museum/`
```
/data/logs/emotion-museum/
├── nginx/ # Nginx日志
│ ├── access.log
│ └── error.log
├── gateway/ # 网关服务日志
├── ai/ # AI服务日志
├── user/ # 用户服务日志
├── mysql/ # MySQL日志
├── redis/ # Redis日志
└── nacos/ # Nacos日志
```
## 🔄 更新流程
### 更新前端
```bash
# 1. 重新构建前端
cd web
npm run build
# 2. 部署到目标目录
sudo rm -rf /data/www/emotion-museum/*
sudo cp -r dist/* /data/www/emotion-museum/
sudo chown -R www-data:www-data /data/www/emotion-museum
# 3. 重启Nginx(可选)
./manage-custom.sh restart nginx
```
### 更新后端
```bash
# 1. 重新构建后端
cd backend
mvn clean package -DskipTests
# 2. 部署JAR文件
sudo cp emotion-gateway/target/emotion-gateway-1.0.0.jar /data/builds/emotion-gateway.jar
sudo cp emotion-ai/target/emotion-ai-1.0.0.jar /data/builds/emotion-ai.jar
sudo cp emotion-user/target/emotion-user-1.0.0.jar /data/builds/emotion-user.jar
# 3. 重启相关服务
./manage-custom.sh restart emotion-gateway
./manage-custom.sh restart emotion-ai
./manage-custom.sh restart emotion-user
```
### 一键更新
```bash
# 自动构建和部署
./manage-custom.sh update
```
## 🚨 故障排除
### 常见问题
#### 1. 前端访问404
```bash
# 检查前端文件是否存在
ls -la /data/www/emotion-museum/
# 检查Nginx配置
./manage-custom.sh logs -s nginx
# 检查文件权限
sudo chown -R www-data:www-data /data/www/emotion-museum
```
#### 2. API调用失败
```bash
# 检查网关服务状态
./manage-custom.sh logs -s emotion-gateway
# 检查服务健康状态
curl http://localhost:9000/actuator/health
```
#### 3. 服务启动失败
```bash
# 检查JAR文件是否存在
ls -la /data/builds/
# 检查服务日志
./manage-custom.sh logs -s emotion-ai
# 检查容器状态
docker-compose -f docker-compose.custom.yml ps
```
#### 4. 日志文件过大
```bash
# 清理日志文件
sudo find /data/logs/emotion-museum -name "*.log" -size +100M -delete
# 设置日志轮转
sudo logrotate -f /etc/logrotate.conf
```
## 📞 技术支持
### 快速诊断
```bash
# 执行健康检查
./manage-custom.sh health
# 查看服务状态
./manage-custom.sh status
# 查看实时监控
./manage-custom.sh monitor
```
### 获取帮助
```bash
# 查看管理命令帮助
./manage-custom.sh --help
# 查看部署脚本帮助
./deploy-custom.sh --help
```
---
## ✅ 部署检查清单
- [ ] **目录创建**: `/data/www/emotion-museum`, `/data/builds`, `/data/logs/emotion-museum`
- [ ] **环境配置**: `COZE_API_TOKEN` 已配置为与开发环境一致
- [ ] **前端部署**: 静态文件已复制到 `/data/www/emotion-museum/`
- [ ] **后端部署**: JAR文件已复制到 `/data/builds/`
- [ ] **服务启动**: 所有Docker容器正常运行
- [ ] **访问测试**: 前端页面和API接口正常访问
- [ ] **日志检查**: 日志文件正常生成到 `/data/logs/emotion-museum/`
**🎉 恭喜!您的情绪博物馆项目已成功部署到自定义目录结构!**