zhibo/环境配置指南.md

178 lines
5.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.

# 环境配置指南
本项目采用分离配置架构:
- **普通业务功能**(用户、消息、商城等)→ 可切换本地/远程
- **直播/通话服务** → 始终连接远程服务器
---
## 一、APP 配置
### 配置文件位置
`android-app/local.properties`
### 配置说明
```properties
# ============ 主API地址普通业务功能============
# 本地开发时使用本地地址
api.base_url_emulator=http://10.0.2.2:8081/
api.base_url_device=http://192.168.1.164:8081/
# ============ 直播/通话服务地址(始终远程)============
live.server_host=1.15.149.240
live.server_port=8083
turn.server_host=1.15.149.240
turn.server_port=3478
```
### 切换环境
#### 本地开发(默认)
```properties
api.base_url_emulator=http://10.0.2.2:8081/
api.base_url_device=http://192.168.1.164:8081/
```
#### 全部连接远程
```properties
api.base_url_emulator=http://1.15.149.240:8083/
api.base_url_device=http://1.15.149.240:8083/
```
### 修改后需要重新编译
```bash
cd android-app
.\gradlew assembleRelease
```
---
## 二、前端管理端配置
### 配置文件位置
- 开发环境:`Zhibo/admin/.env.development`
- 生产环境:`Zhibo/admin/.env.production`
### 开发环境(本地)
```env
ENV = 'development'
VUE_APP_BASE_API = 'http://127.0.0.1:30001'
```
### 生产环境(远程)
```env
ENV = 'production'
VUE_APP_BASE_API = ''
```
> 生产环境使用空字符串由Nginx代理到后端
---
## 三、后端配置
### 配置文件位置
`Zhibo/zhibo-h/crmeb-front/src/main/resources/application.yml`
### 关键配置
```yaml
server:
port: 8081 # 本地开发端口
spring:
datasource:
url: jdbc:mysql://1.15.149.240:3306/zhibo # 数据库地址
redis:
host: 127.0.0.1 # Redis地址
```
### 服务器启动脚本
```bash
#!/bin/bash
JAR_PATH="/www/wwwroot/1.15.149.240_30002/Jar"
# Front API (带SRS配置)
nohup java -Xms512m -Xmx1024m -jar ${JAR_PATH}/Crmeb-front.jar \
--server.port=8083 \
--spring.redis.host=127.0.0.1 \
--LIVE_PUBLIC_SRS_HOST=1.15.149.240 \
--LIVE_PUBLIC_SRS_RTMP_PORT=25002 \
--LIVE_PUBLIC_SRS_HTTP_PORT=25003 \
> ${JAR_PATH}/logs/front.log 2>&1 &
```
---
## 四、服务架构图
```
┌─────────────────────────────────────────────────────────────┐
│ 远程服务器 1.15.149.240 │
├─────────────────────────────────────────────────────────────┤
│ Front API (8083) │
│ ├── WebSocket: /ws/call (通话信令) ←── APP直连 │
│ ├── WebSocket: /ws/live/* (直播弹幕) ←── APP直连 │
│ └── REST API: /api/front/* (可选) │
│ │
│ SRS流媒体服务器 │
│ ├── RTMP: 25002 │
│ └── HTTP-FLV: 25003 │
│ │
│ TURN服务器: 3478 │
└─────────────────────────────────────────────────────────────┘
直播/通话服务 │
─────────────────────┼─────────────────────
普通业务功能 │
┌─────────────────────────────────────────────────────────────┐
│ 本地开发环境 │
├─────────────────────────────────────────────────────────────┤
│ Front API (8081) │
│ └── REST API: /api/front/* ←── APP连接 │
│ │
│ Admin API (30001) │
│ └── REST API: /api/admin/* ←── 管理前端连接 │
└─────────────────────────────────────────────────────────────┘
```
---
## 五、快速切换命令
### APP切换到全远程
编辑 `android-app/local.properties`
```properties
api.base_url_device=http://1.15.149.240:8083/
```
### APP切换到本地开发
编辑 `android-app/local.properties`
```properties
api.base_url_device=http://192.168.1.164:8081/
```
### 前端切换
```bash
# 开发模式(连本地)
npm run dev
# 生产构建(连远程)
npm run build:prod
```
---
## 六、端口清单
| 服务 | 本地端口 | 远程端口 | 说明 |
|------|----------|----------|------|
| Front API | 8081 | 8083 | APP主API |
| Admin API | 30001 | 30003 | 管理后台API |
| SRS RTMP | - | 25002 | 直播推流 |
| SRS HTTP | - | 25003 | 直播播放 |
| TURN | - | 3478 | 视频通话中继 |
| MySQL | - | 3306 | 数据库 |
| Redis | 6379 | 6379 | 缓存 |