rwadurian/backend/services/README.md

174 lines
7.6 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.

# RWA Backend Services
统一部署管理 RWA 后端微服务。
## 架构概览
```
┌─────────────────────────────────────────────────────────────────┐
│ 192.168.1.100 (Gateway) │
│ ┌─────────────┐ ┌─────────────────────────────────────────┐ │
│ │ Nginx │ │ MPC-System (Go) │ │
│ │ (Reverse │ │ - session-coordinator (:8081) │ │
│ │ Proxy) │ │ - message-router (:8082) │ │
│ │ │ │ - server-party-1/2/3 (:8083-8085) │ │
│ └─────────────┘ │ - account-service (:8080) │ │
│ └─────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│ Internal Network
┌─────────────────────────────────────────────────────────────────┐
│ 192.168.1.111 (Backend) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Docker Compose Services │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ PostgreSQL │ │ Redis │ │ Kafka │ │ │
│ │ │ (:5432) │ │ (:6379) │ │ (:9092) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ identity │ │ wallet │ │ backup │ │ │
│ │ │ (:3000) │ │ (:3001) │ │ (:3002) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ planting │ │ referral │ │ reward │ │ │
│ │ │ (:3003) │ │ (:3004) │ │ (:3005) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ mpc │ │ leaderboard │ │ reporting │ │ │
│ │ │ (:3006) │ │ (:3007) │ │ (:3008) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │authorization│ │ admin │ │ │
│ │ │ (:3009) │ │ (:3010) │ │ │
│ │ └─────────────┘ └─────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
```
## 快速开始
### 1. 首次安装
```bash
# 进入服务目录
cd ~/rwadurian/backend/services
# 运行安装(自动生成安全密钥)
./deploy.sh install
```
### 2. 构建镜像
```bash
./deploy.sh build
```
### 3. 启动服务
```bash
./deploy.sh up
```
### 4. 检查状态
```bash
./deploy.sh status
./deploy.sh health
```
## 常用命令
| 命令 | 说明 |
|------|------|
| `./deploy.sh install` | 首次安装,生成配置 |
| `./deploy.sh build` | 构建所有 Docker 镜像 |
| `./deploy.sh up` | 启动所有服务 |
| `./deploy.sh down` | 停止所有服务 |
| `./deploy.sh restart` | 重启所有服务 |
| `./deploy.sh status` | 查看服务状态 |
| `./deploy.sh health` | 检查服务健康 |
| `./deploy.sh logs` | 查看所有日志 |
| `./deploy.sh logs <service>` | 查看指定服务日志 |
| `./deploy.sh migrate` | 运行数据库迁移 |
| `./deploy.sh rebuild-svc <name>` | 重建指定服务 |
## 服务列表
| 服务 | 端口 | 说明 |
|------|------|------|
| identity-service | 3000 | 身份认证服务 |
| wallet-service | 3001 | 钱包账本服务 |
| backup-service | 3002 | MPC 备份服务 |
| planting-service | 3003 | 认种服务 |
| referral-service | 3004 | 推荐系统服务 |
| reward-service | 3005 | 奖励服务 |
| mpc-service | 3006 | MPC 中间层服务 |
| leaderboard-service | 3007 | 排行榜服务 |
| reporting-service | 3008 | 报表服务 |
| authorization-service | 3009 | 授权服务 |
| admin-service | 3010 | 管理后台服务 |
## 基础设施
| 服务 | 端口 | 说明 |
|------|------|------|
| PostgreSQL | 5432 | 主数据库 |
| Redis | 6379 | 缓存/会话 |
| Kafka | 9092 | 消息队列 |
| Zookeeper | 2181 | Kafka 协调 |
## 环境配置
配置文件 `.env``./deploy.sh install` 自动生成,包含:
- 数据库密码
- JWT 密钥
- 加密密钥
- MPC 系统地址
**重要**: `.env` 文件包含敏感信息,请勿提交到 Git
## 与 MPC-System 集成
mpc-service 需要连接到运行在 192.168.1.100 上的 MPC-System
- Session Coordinator: `http://192.168.1.100:8081`
- Message Router: `ws://192.168.1.100:8082`
确保 192.168.1.111 能够访问 192.168.1.100 的这些端口。
## 故障排除
### 查看服务日志
```bash
./deploy.sh logs identity-service
```
### 重建单个服务
```bash
./deploy.sh rebuild-svc mpc-service
```
### 数据库连接问题
```bash
# 进入 postgres 容器
docker exec -it rwa-postgres psql -U rwa_user -d rwa_identity
```
### 清理重新开始
```bash
./deploy.sh clean # 删除所有容器和数据
./deploy.sh install
./deploy.sh build
./deploy.sh up
```