Skip to content

Ubuntu上安装SRS源码

1. 依赖库安装

shell
#安装必备开发工具链
sudo apt install -y build-essential automake cmake pkg-config tclsh 
#安装用于推流的ffmpeg程序
sudo apt install -y ffmpeg

2. 获取SRS源码和构建

shell
#进入一个剩余磁盘空间足够的盘,准备clone srs源码仓库,例如用户的HOME目录:
cd ~
 
#克隆SRS源码仓库
git clone -b develop https://gitee.com/ossrs/srs.git
 
#进入SRS主干目录
cd srs/trunk
 
#检出v6.0.48版本,并创建自己的开发分支
git checkout v6.0.48
git switch -c dev-from-v6.0.48
 
#根据开发环境,编译依赖库,并生成makefile脚本
./configure
 
#开始编译SRS
make

3. 启动服务器(对应配置)

 ./objs/srs -c conf/rtc.conf

在 Linux 中,你可以通过在命令末尾加上 &,让进程在后台运行(还有其他方法):

shell
 ./objs/srs -c conf/rtc.conf &

4. 停止服务器

shell
# 查找SRS进程
ps aux | grep srs

alt text

遇到的问题

  1. 怎样判断 udp的8000端口有没有被占用
shell
(base) root@gpufree-container:/# ss -ulnp | grep 8000
UNCONN 0      0            0.0.0.0:8000      0.0.0.0:*    users:(("srs",pid=21896,fd=11))

问题: UDP 8000 端口 映射到了 ou659840-5rc6jhsr-8080.zjrestapi.gpufree.cn:30015,如果想从外网访问它,需要排查以下几个方面:

  1. 确保服务器正确监听 UDP 8000
    shell
    ss -ulnp | grep 8000
  2. 外网测试 UDP 30015

方法 1:用 nc 发送 UDP 测试 在 服务器端 运行:

shell
nc -u -l 30015

然后在 外部机器 运行:

shell
echo "Hello UDP" | nc -u ou659840-5rc6jhsr-8080.zjrestapi.gpufree.cn 30015

如果服务器端 打印出 "Hello UDP",说明外网访问是正常的。

alt text

docker安装srs

shell
docker run -it --rm  
  -p 1935:1935 \
  -p 1985:1985 \
  -p 8080:8080 \
  -p 8000:8000/udp \
  -v $(pwd)/data/srs/srs.conf:/usr/local/srs/conf/srs.conf \
  --name srs \
  registry.cn-hangzhou.aliyuncs.com/ossrs/srs:6 \
  ./objs/srs -c conf/srs.conf

前台启动

shell
docker run -it --rm -p 1935:1935 -p 1985:1985 -p 8080:8080 -p 8000:8000/udp -v /data/srs.conf:/usr/local/srs/conf/srs.conf --name srs registry.cn-hangzhou.aliyuncs.com/ossrs/srs:6 ./objs/srs -c conf/srs.conf

后台启动

shell
docker run -d --rm -p 1935:1935 -p 1985:1985 -p 8080:8080 -p 8000:8000/udp -v /data/srs/srs.conf:/usr/local/srs/conf/srs.conf --name srs registry.cn-hangzhou.aliyuncs.com/ossrs/srs:6 ./objs/srs -c conf/srs.conf

1、srs配置问题:

candidate 127.0.0.1; 这个配置 只影响 WebRTC(包括 WHEP/WHS) 推拉流,对 RTMP、HTTP-FLV、HLS 这些传统方式 没有任何影响

如果你想用 HTTP-FLV 直播,需要访问: http://10.0.103.180:8080/live/livestream.flv 如果是 HLS: http://10.0.103.180:8080/live/livestream.m3u8 如果是 WebRTC: webrtc://10.0.103.180/live/livestream