MeiChat 支持自架 LiveKit、Agora 和 LiveKit 云。如果您有支持 WebRTC 的服务器,您可以在自己的服务器上部署 LiveKit——它是免费且开源的。如果您的服务器不支持 WebRTC,或者您使用共享主机,可以选择 LiveKit Cloud 或 Agora 代替。
如何在您的服务器上部署LiveKit ?
首先,SSH连接到服务器,直接从终端执行必要的命令。
1)安装LiveKit服务器
curl -sSL https://get.livekit.io | bash
2)创建配置文件(例如,livekit.yaml)
mkdir /etc/livekit/
nano /etc/livekit/livekit.yaml
粘贴以下内容并保存文件。
port: 7880
rtc:
udp_port: 7881
tcp_port: 7881
use_external_ip: true
keys:
my-api-key: ENTER_YOUR_32_CHARACTER_SECRET_HERE
3) 检查服务器防火墙(UFW)
sudo ufw allow 7880/tcp
sudo ufw allow 7881/tcp
sudo ufw allow 7881/udp
sudo ufw reload
4) 使用 Nginx 设置一个反向代理来处理 WebSocket URL。
设置子域名 livekit.domain.com 并配置 Nginx,如下所示,以启用访问 LiveKit 服务器的 wss://livekit.domain.com 。请在您的 MeiChat 视频聊天设置中使用这个 URL。
location / {
proxy_pass http://127.0.0.1:7880;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
send_timeout 3600s;
keepalive_timeout 3600s;
}
5)重启Nginx服务
您的 LiveKit URL 是您配置的服务器 URL—— wss://livekit.domain.com,API 密钥和秘密是 livekit.yaml 文件中定义的。
6) 创建 systemd 服务文件
您可以用 systemctl 在后台运行LiveKit作为服务。
sudo nano /etc/systemd/system/livekit.service
粘贴以下内容:
[Unit]
Description=LiveKit Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/livekit-server --config /etc/livekit/livekit.yaml
Restart=on-failure
RestartSec=5s
User=root
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
将
User=root
替换为您系统中一个有运行LiveKit权限的有效用户。
7) 启用并启动服务
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable livekit
sudo systemctl start livekit
有关LiveKit配置和优化的更多信息,请参阅以下网址: https://docs.livekit.io/home/self-hosting/local/