CentOS 7.6 自建 LiveKit 部署指南

1. 环境要求

建议
系统 CentOS 7.6 x86_64
公网 IP 必备(云主机)
域名 建议 livekit.yourdomain.com(生产需 HTTPS/WSS)
开放端口 TCP 7880(信令)、TCP 7881、UDP 50000-60000、TURN 3478/5349
Docker 20+ / docker-compose v1 或 v2

CentOS 7 默认内核较旧,强烈建议用 Docker + host 网络,不要用复杂的 bridge NAT。

2. 安装 Docker(CentOS 7)

复制代码
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
systemctl enable --now docker
​
# compose 插件或独立二进制均可
curl -L "https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-$(uname -s)-$(uname -m)" \
  -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

若官方源慢,可换国内镜像后再装。

3. 准备配置目录

复制代码
mkdir -p /opt/livekit
cd /opt/livekit

3.1 livekit.yaml

coturn 已关闭 时,请打开 LiveKit 内置 TURN(turn.enabled: true),跨运营商/公司网更稳。 若以后再开 coturn 抢 3478,再把 turn.enabled 改回 false

复制代码
port: 7880
log_level: info
​
rtc:
  tcp_port: 7881
  port_range_start: 50000
  port_range_end: 60000
  use_external_ip: true
​
keys:
  # secret 必须 ≥32 字符
  APIoaKey: "请换成openssl_rand_hex_32生成的至少32位密钥"
​
# coturn 已停用:启用 LiveKit 内置 TURN
turn:
  enabled: true
  udp_port: 3478
  # 无独立 TURN 域名/证书时可先不开 TLS
  # tls_port: 5349
  # domain: turn.yourdomain.com

生成强密钥:

复制代码
openssl rand -hex 32

启动LiveKit:

复制代码
cd /opt/livekit
docker-compose pull
docker-compose down
docker-compose up -d
docker-compose logs -f --tail=100

3.2 docker-compose.yaml

复制代码
services:
  livekit:
    # 建议使用最新稳定版,与 livekit-client 2.x 匹配(勿用过旧的 1.8.x)
    image: livekit/livekit-server:v1.13.5
    network_mode: host
    restart: unless-stopped
    volumes:
      - ./livekit.yaml:/etc/livekit.yaml:ro
    command: --config /etc/livekit.yaml

客户端是 livekit-client@2.21 时,服务器请用 v1.9+ ,推荐 v1.13.5 。1.8.4 会先 404 /rtc/v1 再回退,容易「已连接但无画面」。

健康检查(本机):

复制代码
curl -i http://127.0.0.1:7880
# 或
ss -lntp | grep 7880

4. 防火墙 / 安全组

复制代码
# firewalld 示例
firewall-cmd --permanent --add-port=7880/tcp
firewall-cmd --permanent --add-port=7881/tcp
firewall-cmd --permanent --add-port=3478/udp
firewall-cmd --permanent --add-port=3478/tcp
firewall-cmd --permanent --add-port=50000-60000/udp
firewall-cmd --reload

云厂商控制台同步放行上述端口。

5. HTTPS / WSS(生产必做)

浏览器与 App WebView 在 HTTPS 页面下要求 wss://。推荐用 nginx 反代:

nginx.conf:

复制代码
livekit.yourdomain.com {
  proxy_pass 127.0.0.1:7880
}

确认后客户端使用:

复制代码
wss://livekit.yourdomain.com

6. 配置 后端

编辑 web/src/main/resources/application.yml(或 application-prod.yml):

复制代码
livekit:
  enabled: true
  url: wss://livekit.yourdomain.com   # 开发可临时 ws://公网IP:7880
  api-key: APIoaKey
  api-secret: replace_with_32chars_or_longer_secret
  token-ttl-seconds: 7200

api-key / api-secret 必须与 livekit.yamlkeys 一致。

重启后端后:

  • POST /api/v1/webrtc/private/call|accept|token 返回 { url, roomName, token, mediaMode: "sfu" }

  • 群呼同理:/api/v1/webrtc/group/*

7. 最小验证(可选)

本机装 LiveKit CLI:

复制代码
# 生成测试 token(需与 keys 一致)
# 或用官方 meeting demo 指向你的 wss 地址

也可用 LiveKit Meet 示例 自定义 server URL 做连通性测试(需公网可达的 wss)。

相关推荐
薛定谔的悦1 小时前
储能 EMS 的功率策略:从一块电表到一次逆流的 200 毫秒
大数据·linux·能源·储能·bms
2601_962218474 小时前
万象生鲜系统区块链溯源技术帮助生鲜企业搭建食品安全数字化体系
大数据·运维·微服务·云原生·架构
智塑未来4 小时前
中小公司在线文档选型:从协作入口到安全边界
运维·安全
新时代牛马4 小时前
Linux 内核入门地图:架构、源码目录与五大子系统
linux·运维·架构
智购科技无人售货机厂家4 小时前
2026自动售货机制冷系统维护指南:从散热器清洁到压缩机换油的工程实践~YH
运维·redis·物联网·缓存·架构
剑客的茶馆4 小时前
开发者,运维怎样转行FDE?
运维·ai·开发·fde
Julien20044 小时前
控制 SELinux 文件上下文
linux·运维·服务器
sulikey5 小时前
Linux Core Dump 完全指南:从原理到实战的崩溃调试手册。什么是core dump?程序报错core dumped怎么办?
linux·服务器·操作系统·调试·coredump
众壹新能源科技5 小时前
功率预测误差考核怎么降?从气象源到上报口径的排查清单
运维·人工智能·自动化
DevLoom_6 小时前
SD卡插电脑提示:驱动器中的磁盘未被格式化?恢复数据正确处理步骤
运维·服务器·电脑