主题:添加聊天室
功能:聊天室功能添加
This commit is contained in:
parent
b02fdf2ea7
commit
7376df609d
273
Log/服务搭建/服务部署汇总.md
Normal file
273
Log/服务搭建/服务部署汇总.md
Normal file
|
|
@ -0,0 +1,273 @@
|
||||||
|
# 服务部署汇总文档
|
||||||
|
|
||||||
|
## 服务器信息
|
||||||
|
- **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
|
||||||
223
Log/服务搭建/直播-SRS和API服务.md
Normal file
223
Log/服务搭建/直播-SRS和API服务.md
Normal file
|
|
@ -0,0 +1,223 @@
|
||||||
|
# 直播服务部署文档 (SRS + API)
|
||||||
|
|
||||||
|
## 服务信息
|
||||||
|
|
||||||
|
| 服务 | 端口 | 用途 |
|
||||||
|
|------|------|------|
|
||||||
|
| SRS RTMP | 25002 (映射到1935) | 推流地址 |
|
||||||
|
| SRS HTTP-FLV | 25003 (映射到8080) | 拉流播放 |
|
||||||
|
| SRS API | 1985 | SRS管理接口 |
|
||||||
|
| API Server | 25001 (映射到3001) | 后端接口 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
/opt/live-streaming/
|
||||||
|
├── docker/
|
||||||
|
│ └── srs/
|
||||||
|
│ └── srs.conf # SRS配置文件
|
||||||
|
├── docker-compose.yml # Docker编排文件
|
||||||
|
└── server/ # API服务代码
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、SRS配置文件
|
||||||
|
|
||||||
|
位置:`/opt/live-streaming/docker/srs/srs.conf`
|
||||||
|
|
||||||
|
```conf
|
||||||
|
listen 1935;
|
||||||
|
max_connections 1000;
|
||||||
|
srs_log_tank console;
|
||||||
|
daemon off;
|
||||||
|
|
||||||
|
http_api {
|
||||||
|
enabled on;
|
||||||
|
listen 1985;
|
||||||
|
}
|
||||||
|
|
||||||
|
http_server {
|
||||||
|
enabled on;
|
||||||
|
listen 8080;
|
||||||
|
dir ./objs/nginx/html;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtc_server {
|
||||||
|
enabled on;
|
||||||
|
listen 8000;
|
||||||
|
candidate $CANDIDATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
vhost __defaultVhost__ {
|
||||||
|
hls {
|
||||||
|
enabled on;
|
||||||
|
}
|
||||||
|
http_remux {
|
||||||
|
enabled on;
|
||||||
|
mount [vhost]/[app]/[stream].flv;
|
||||||
|
}
|
||||||
|
rtc {
|
||||||
|
enabled on;
|
||||||
|
rtmp_to_rtc on;
|
||||||
|
rtc_to_rtmp on;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、Docker启动命令
|
||||||
|
|
||||||
|
### 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
|
||||||
|
```
|
||||||
|
|
||||||
|
### API服务
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name api-server \
|
||||||
|
--restart always \
|
||||||
|
-p 25001:3001 \
|
||||||
|
-e PUBLIC_SRS_HOST=1.15.149.240 \
|
||||||
|
-e PUBLIC_SRS_RTMP_PORT=25002 \
|
||||||
|
-e PUBLIC_SRS_HTTP_PORT=25003 \
|
||||||
|
-e SRS_HOST=srs \
|
||||||
|
-e SRS_HTTP_PORT=8080 \
|
||||||
|
-e NODE_ENV=production \
|
||||||
|
live-streaming-api-server
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、推流/拉流地址
|
||||||
|
|
||||||
|
### 推流地址 (OBS/手机)
|
||||||
|
```
|
||||||
|
rtmp://1.15.149.240:25002/live/{streamKey}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 拉流地址 (播放器)
|
||||||
|
```
|
||||||
|
# HTTP-FLV (推荐,低延迟)
|
||||||
|
http://1.15.149.240:25003/live/{streamKey}.flv
|
||||||
|
|
||||||
|
# HLS (兼容性好)
|
||||||
|
http://1.15.149.240:25003/live/{streamKey}.m3u8
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看服务状态
|
||||||
|
docker ps | grep -E "srs|api"
|
||||||
|
|
||||||
|
# 查看SRS日志
|
||||||
|
docker logs srs-server
|
||||||
|
docker logs -f srs-server # 实时
|
||||||
|
|
||||||
|
# 查看API日志
|
||||||
|
docker logs api-server
|
||||||
|
|
||||||
|
# 重启服务
|
||||||
|
docker restart srs-server
|
||||||
|
docker restart api-server
|
||||||
|
|
||||||
|
# 停止服务
|
||||||
|
docker stop srs-server api-server
|
||||||
|
|
||||||
|
# 启动服务
|
||||||
|
docker start srs-server api-server
|
||||||
|
|
||||||
|
# 查看SRS统计信息
|
||||||
|
curl http://localhost:1985/api/v1/streams
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、在新服务器部署
|
||||||
|
|
||||||
|
### 1. 创建目录和配置
|
||||||
|
```bash
|
||||||
|
mkdir -p /opt/live-streaming/docker/srs
|
||||||
|
|
||||||
|
# 创建SRS配置文件
|
||||||
|
cat > /opt/live-streaming/docker/srs/srs.conf << 'EOF'
|
||||||
|
listen 1935;
|
||||||
|
max_connections 1000;
|
||||||
|
srs_log_tank console;
|
||||||
|
daemon off;
|
||||||
|
|
||||||
|
http_api {
|
||||||
|
enabled on;
|
||||||
|
listen 1985;
|
||||||
|
}
|
||||||
|
|
||||||
|
http_server {
|
||||||
|
enabled on;
|
||||||
|
listen 8080;
|
||||||
|
dir ./objs/nginx/html;
|
||||||
|
}
|
||||||
|
|
||||||
|
vhost __defaultVhost__ {
|
||||||
|
hls {
|
||||||
|
enabled on;
|
||||||
|
}
|
||||||
|
http_remux {
|
||||||
|
enabled on;
|
||||||
|
mount [vhost]/[app]/[stream].flv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 启动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. 开放防火墙端口
|
||||||
|
```bash
|
||||||
|
# TCP端口
|
||||||
|
firewall-cmd --permanent --add-port=25002/tcp
|
||||||
|
firewall-cmd --permanent --add-port=25003/tcp
|
||||||
|
firewall-cmd --permanent --add-port=1985/tcp
|
||||||
|
firewall-cmd --reload
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 云服务器安全组
|
||||||
|
开放以下端口:
|
||||||
|
- TCP 25002 (RTMP推流)
|
||||||
|
- TCP 25003 (HTTP-FLV播放)
|
||||||
|
- TCP 1985 (SRS API)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、验证服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 检查SRS版本
|
||||||
|
curl http://localhost:1985/api/v1/versions
|
||||||
|
|
||||||
|
# 检查当前直播流
|
||||||
|
curl http://localhost:1985/api/v1/streams
|
||||||
|
```
|
||||||
132
Log/服务搭建/聊天室-LiveKit服务.md
Normal file
132
Log/服务搭建/聊天室-LiveKit服务.md
Normal file
|
|
@ -0,0 +1,132 @@
|
||||||
|
# LiveKit 语音聊天室服务部署文档
|
||||||
|
|
||||||
|
## 服务信息
|
||||||
|
|
||||||
|
| 项目 | 值 |
|
||||||
|
|------|-----|
|
||||||
|
| 服务器IP | 1.15.149.240 |
|
||||||
|
| HTTP端口 | 7880 |
|
||||||
|
| TCP端口 | 7881 |
|
||||||
|
| UDP端口范围 | 50000-50100 |
|
||||||
|
| API Key | APIKey123456 |
|
||||||
|
| API Secret | YourSecretKey123456789012345678901234567890 |
|
||||||
|
| WebSocket地址 | wss://1.15.149.240:7880 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、安装步骤
|
||||||
|
|
||||||
|
### 1. 安装Docker(如果没有)
|
||||||
|
```bash
|
||||||
|
curl -fsSL https://get.docker.com | sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 创建配置目录
|
||||||
|
```bash
|
||||||
|
mkdir -p /opt/livekit
|
||||||
|
cd /opt/livekit
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 创建配置文件
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. 启动LiveKit服务器(使用host网络模式)
|
||||||
|
```bash
|
||||||
|
docker run -d \
|
||||||
|
--name livekit \
|
||||||
|
--restart always \
|
||||||
|
--network host \
|
||||||
|
-v /opt/livekit/livekit.yaml:/livekit.yaml \
|
||||||
|
livekit/livekit-server \
|
||||||
|
--config /livekit.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 检查是否启动成功
|
||||||
|
```bash
|
||||||
|
docker ps | grep livekit
|
||||||
|
docker logs livekit
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、防火墙/安全组配置
|
||||||
|
|
||||||
|
需要开放以下端口:
|
||||||
|
|
||||||
|
| 协议 | 端口 | 用途 |
|
||||||
|
|------|------|------|
|
||||||
|
| TCP | 7880 | HTTP API / WebSocket |
|
||||||
|
| TCP | 7881 | WebRTC TCP |
|
||||||
|
| UDP | 50000-50100 | WebRTC 媒体传输 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看服务状态
|
||||||
|
docker ps | grep livekit
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
docker logs livekit
|
||||||
|
docker logs -f livekit # 实时查看
|
||||||
|
|
||||||
|
# 重启服务
|
||||||
|
docker restart livekit
|
||||||
|
|
||||||
|
# 停止服务
|
||||||
|
docker stop livekit
|
||||||
|
|
||||||
|
# 删除服务
|
||||||
|
docker rm -f livekit
|
||||||
|
|
||||||
|
# 更新服务
|
||||||
|
docker pull livekit/livekit-server
|
||||||
|
docker rm -f livekit
|
||||||
|
# 然后重新执行启动命令
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、验证服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 本地测试
|
||||||
|
curl http://localhost:7880
|
||||||
|
|
||||||
|
# 外网测试
|
||||||
|
curl http://1.15.149.240:7880
|
||||||
|
# 返回 "OK" 表示服务正常
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、后续开发
|
||||||
|
|
||||||
|
### 后端需要实现
|
||||||
|
- Token生成接口:`/api/voice-room/join-token`
|
||||||
|
|
||||||
|
### Android客户端需要
|
||||||
|
- 添加依赖:`io.livekit:livekit-android:2.0.0`
|
||||||
|
- 实现语音房间Activity
|
||||||
|
- 麦位UI界面
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、注意事项
|
||||||
|
|
||||||
|
1. **生产环境请修改API密钥**:当前使用的是示例密钥,正式上线前请更换
|
||||||
|
2. **建议配置HTTPS**:可以用Nginx反向代理添加SSL证书
|
||||||
|
3. **UDP端口范围**:当前配置100个端口,支持约50人同时连麦
|
||||||
191
Log/服务搭建/视频通话-TURN服务.md
Normal file
191
Log/服务搭建/视频通话-TURN服务.md
Normal file
|
|
@ -0,0 +1,191 @@
|
||||||
|
# TURN服务器部署文档 (Coturn)
|
||||||
|
|
||||||
|
## 服务信息
|
||||||
|
|
||||||
|
| 项目 | 值 |
|
||||||
|
|------|-----|
|
||||||
|
| 服务器IP | 1.15.149.240 |
|
||||||
|
| 监听端口 | 3478 (UDP/TCP) |
|
||||||
|
| 用户名 | turnuser |
|
||||||
|
| 密码 | TurnPass123456 |
|
||||||
|
| TURN地址 | turn:1.15.149.240:3478 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、安装Coturn
|
||||||
|
|
||||||
|
### CentOS/OpenCloudOS
|
||||||
|
```bash
|
||||||
|
yum install -y coturn
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ubuntu/Debian
|
||||||
|
```bash
|
||||||
|
apt install -y coturn
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、配置文件
|
||||||
|
|
||||||
|
位置:`/etc/coturn/turnserver.conf`
|
||||||
|
|
||||||
|
```conf
|
||||||
|
# 监听端口
|
||||||
|
listening-port=3478
|
||||||
|
|
||||||
|
# 监听所有网卡
|
||||||
|
listening-ip=0.0.0.0
|
||||||
|
|
||||||
|
# 你的服务器公网IP(需要修改)
|
||||||
|
external-ip=你的公网IP
|
||||||
|
|
||||||
|
# realm
|
||||||
|
realm=你的公网IP
|
||||||
|
|
||||||
|
# 认证方式
|
||||||
|
lt-cred-mech
|
||||||
|
|
||||||
|
# 用户名:密码
|
||||||
|
user=turnuser:TurnPass123456
|
||||||
|
|
||||||
|
# 日志
|
||||||
|
log-file=/var/log/coturn/turnserver.log
|
||||||
|
verbose
|
||||||
|
simple-log
|
||||||
|
|
||||||
|
# 不使用TLS
|
||||||
|
no-tls
|
||||||
|
no-dtls
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、启动服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 启动
|
||||||
|
systemctl start coturn
|
||||||
|
|
||||||
|
# 设置开机自启
|
||||||
|
systemctl enable coturn
|
||||||
|
|
||||||
|
# 查看状态
|
||||||
|
systemctl status coturn
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
tail -f /var/log/coturn/turnserver.log
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、防火墙配置
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 开放端口
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
### 云服务器安全组
|
||||||
|
| 协议 | 端口 | 用途 |
|
||||||
|
|------|------|------|
|
||||||
|
| TCP | 3478 | TURN控制 |
|
||||||
|
| UDP | 3478 | TURN控制 |
|
||||||
|
| UDP | 49152-65535 | 媒体中继 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、验证服务
|
||||||
|
|
||||||
|
### 1. 检查端口
|
||||||
|
```bash
|
||||||
|
netstat -tlnup | grep 3478
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 在线测试
|
||||||
|
访问:https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
|
||||||
|
|
||||||
|
填入:
|
||||||
|
- STUN or TURN URI: `turn:你的IP:3478`
|
||||||
|
- TURN username: `turnuser`
|
||||||
|
- TURN password: `TurnPass123456`
|
||||||
|
|
||||||
|
点击 "Gather candidates",如果看到 `relay` 类型的候选者,说明TURN服务正常。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 启动
|
||||||
|
systemctl start coturn
|
||||||
|
|
||||||
|
# 停止
|
||||||
|
systemctl stop coturn
|
||||||
|
|
||||||
|
# 重启
|
||||||
|
systemctl restart coturn
|
||||||
|
|
||||||
|
# 查看状态
|
||||||
|
systemctl status coturn
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
tail -100 /var/log/coturn/turnserver.log
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 七、Android客户端配置
|
||||||
|
|
||||||
|
在 `local.properties` 中配置:
|
||||||
|
```properties
|
||||||
|
turn.server_host=你的服务器IP
|
||||||
|
turn.server_port=3478
|
||||||
|
```
|
||||||
|
|
||||||
|
在 `WebRTCConfig.java` 中使用:
|
||||||
|
```java
|
||||||
|
public static final String TURN_SERVER_URL = "turn:" + BuildConfig.TURN_SERVER_HOST + ":" + BuildConfig.TURN_SERVER_PORT;
|
||||||
|
public static final String TURN_USERNAME = "turnuser";
|
||||||
|
public static final String TURN_PASSWORD = "TurnPass123456";
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 八、在新服务器部署(完整步骤)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 安装coturn
|
||||||
|
yum install -y coturn # CentOS
|
||||||
|
# 或
|
||||||
|
apt install -y coturn # Ubuntu
|
||||||
|
|
||||||
|
# 2. 创建配置文件
|
||||||
|
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
|
||||||
|
|
||||||
|
# 3. 创建日志目录
|
||||||
|
mkdir -p /var/log/coturn
|
||||||
|
|
||||||
|
# 4. 启动服务
|
||||||
|
systemctl enable coturn
|
||||||
|
systemctl start coturn
|
||||||
|
|
||||||
|
# 5. 验证
|
||||||
|
systemctl status coturn
|
||||||
|
netstat -tlnup | grep 3478
|
||||||
|
```
|
||||||
Loading…
Reference in New Issue
Block a user