zhibo/Log/服务搭建/服务部署汇总.md

274 lines
6.4 KiB
Markdown
Raw Normal View History

# 服务部署汇总文档
## 服务器信息
- **IP地址**1.15.149.240
- **操作系统**OpenCloudOS
---
## 服务总览
| 服务 | 用途 | 类型 | 端口 | 状态检查 |
|------|------|------|------|----------|
| **LiveKit** | 多人语音连麦 | Docker | 7880, 7881, 50000-50100 | `curl http://localhost:7880` |
| **SRS** | 直播推流/拉流 | Docker | 25002, 25003, 1985 | `curl http://localhost:1985/api/v1/versions` |
| **API Server** | 后端接口 | Docker | 25001 | `curl http://localhost:25001` |
| **Coturn** | 视频通话中继 | 系统服务 | 3478 | `systemctl status coturn` |
---
## 快速检查所有服务
```bash
# 一键检查所有服务状态
echo "=== Docker 容器 ===" && docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
echo ""
echo "=== Coturn 服务 ===" && systemctl is-active coturn
echo ""
echo "=== 端口监听 ===" && netstat -tlnp | grep -E "7880|1985|25001|25002|25003|3478"
```
---
## 快速重启所有服务
```bash
# 重启所有Docker容器
docker restart livekit srs-server api-server
# 重启Coturn
systemctl restart coturn
# 验证
docker ps
systemctl status coturn
```
---
## 服务详细文档
| 文档 | 说明 |
|------|------|
| [聊天室-LiveKit服务.md](聊天室-LiveKit服务.md) | 多人语音连麦房间 |
| [直播-SRS和API服务.md](直播-SRS和API服务.md) | 直播推流拉流 |
| [视频通话-TURN服务.md](视频通话-TURN服务.md) | 1对1视频通话中继 |
---
## 防火墙/安全组端口汇总
### 必须开放的端口
| 协议 | 端口 | 服务 | 用途 |
|------|------|------|------|
| TCP | 7880 | LiveKit | HTTP API / WebSocket |
| TCP | 7881 | LiveKit | WebRTC TCP |
| UDP | 50000-50100 | LiveKit | WebRTC 媒体 |
| TCP | 25001 | API Server | 后端接口 |
| TCP | 25002 | SRS | RTMP 推流 |
| TCP | 25003 | SRS | HTTP-FLV 播放 |
| TCP | 1985 | SRS | SRS API |
| TCP | 3478 | Coturn | TURN 控制 |
| UDP | 3478 | Coturn | TURN 控制 |
| UDP | 49152-65535 | Coturn | 媒体中继 |
---
## 在新服务器部署(完整流程)
### 1. 安装Docker
```bash
curl -fsSL https://get.docker.com | sh
systemctl enable docker
systemctl start docker
```
### 2. 部署LiveKit语音连麦
```bash
mkdir -p /opt/livekit
cat > /opt/livekit/livekit.yaml << 'EOF'
port: 7880
rtc:
port_range_start: 50000
port_range_end: 50100
use_external_ip: true
keys:
APIKey123456: YourSecretKey123456789012345678901234567890
logging:
level: info
EOF
docker run -d \
--name livekit \
--restart always \
--network host \
-v /opt/livekit/livekit.yaml:/livekit.yaml \
livekit/livekit-server \
--config /livekit.yaml
```
### 3. 部署直播服务SRS + API Server
> ⚠️ **【重要】必须上传完整项目文件!**
>
> 直播服务的 API Server 需要完整的 `live-streaming` 项目代码才能运行,
> **不能只创建配置文件**,必须将本地的 `live-streaming` 文件夹完整上传到服务器!
#### 3.1 上传项目文件(必须)
```bash
# 方式1使用 scp 上传(推荐)
scp -r live-streaming/ root@服务器IP:/opt/
# 方式2使用 rsync 上传
rsync -av live-streaming/ root@服务器IP:/opt/live-streaming/
# 方式3使用 FTP/SFTP 工具上传到 /opt/live-streaming/
```
**需要上传的项目结构:**
```
live-streaming/
├── server/ # ⭐ API服务代码必须
│ ├── index.js # 主入口文件
│ ├── routes/ # 路由
│ ├── middleware/ # 中间件
│ └── utils/ # 工具函数
├── docker/
│ └── srs/
│ └── srs.conf # SRS配置文件
├── package.json # ⭐ Node.js依赖必须
├── Dockerfile # ⭐ Docker构建文件必须
└── docker-compose.yml # Docker编排文件
```
#### 3.2 构建API服务镜像
```bash
cd /opt/live-streaming
# 构建Docker镜像
docker build -t live-streaming-api-server .
```
#### 3.3 启动SRS服务
```bash
docker run -d \
--name srs-server \
--restart always \
-p 25002:1935 \
-p 25003:8080 \
-p 1985:1985 \
-v /opt/live-streaming/docker/srs/srs.conf:/usr/local/srs/conf/srs.conf \
ossrs/srs:5
```
#### 3.4 启动API服务
```bash
docker run -d \
--name api-server \
--restart always \
-p 25001:3001 \
-e PUBLIC_SRS_HOST=你的服务器IP \
-e PUBLIC_SRS_RTMP_PORT=25002 \
-e PUBLIC_SRS_HTTP_PORT=25003 \
-e SRS_HOST=你的服务器IP \
-e SRS_HTTP_PORT=1985 \
-e NODE_ENV=production \
live-streaming-api-server
```
### 4. 部署Coturn视频通话
```bash
# CentOS/OpenCloudOS
yum install -y coturn
# Ubuntu
# apt install -y coturn
cat > /etc/coturn/turnserver.conf << 'EOF'
listening-port=3478
listening-ip=0.0.0.0
external-ip=你的公网IP
realm=你的公网IP
lt-cred-mech
user=turnuser:TurnPass123456
log-file=/var/log/coturn/turnserver.log
verbose
simple-log
no-tls
no-dtls
EOF
mkdir -p /var/log/coturn
systemctl enable coturn
systemctl start coturn
```
### 5. 开放防火墙端口
```bash
# firewalld
firewall-cmd --permanent --add-port=7880/tcp
firewall-cmd --permanent --add-port=7881/tcp
firewall-cmd --permanent --add-port=50000-50100/udp
firewall-cmd --permanent --add-port=25001/tcp
firewall-cmd --permanent --add-port=25002/tcp
firewall-cmd --permanent --add-port=25003/tcp
firewall-cmd --permanent --add-port=1985/tcp
firewall-cmd --permanent --add-port=3478/tcp
firewall-cmd --permanent --add-port=3478/udp
firewall-cmd --permanent --add-port=49152-65535/udp
firewall-cmd --reload
```
### 6. 验证所有服务
```bash
# LiveKit
curl http://localhost:7880
# SRS
curl http://localhost:1985/api/v1/versions
# Coturn
systemctl status coturn
netstat -tlnup | grep 3478
```
---
## Android客户端配置
`android-app/local.properties` 中配置:
```properties
# API服务器
api.base_url_emulator=http://10.0.2.2:8081/
api.base_url_device=http://你的服务器IP:25001/
# 直播/通话服务
live.server_host=你的服务器IP
live.server_port=8083
# TURN服务器
turn.server_host=你的服务器IP
turn.server_port=3478
```
---
## 注意事项
1. **生产环境安全**
- 修改LiveKit的API密钥
- 修改Coturn的用户名密码
- 配置HTTPS/WSS
2. **服务器配置建议**
- 最低配置2核4G
- 推荐配置4核8G支持更多并发
3. **带宽要求**
- 直播每路约2-3Mbps
- 语音连麦每人约100Kbps
- 视频通话每路约1-2Mbps