Ubuntu部署SRS流媒体服务器
1.安装SRS
1.查看所有的版本 git ls-remote --tags https://github.com/ossrs/srs.git 2.下载6.0版本(稳定版) git clone https://github.com/ossrs/srs.git cd srs git checkout tags/v6.0.36 -b my-branch 3.在 srs/trunk路径下编译 cd srs/trunk ./configure make 4.查看版本号 ./objs/srs -v
2.创建配置文件
sudo vim conf/rtc_web.conf
配置文件 rtc_web.conf 内容如下:
# 全局配置 listen 1935; # RTMP 推流/拉流端口(6.x 默认开启 RTMP,无需额外配置) max_connections 1000; srs_log_tank file; srs_log_file ./objs/srs.log; daemon off; # 调试模式(生产环境改为 on) pid ./objs/srs.pid; # RTC 核心配置(6.x 标准配置) rtc_server { enabled on; # 开启 RTC 服务 listen 6666; # WebRTC 媒体端口(UDP/TCP) candidate 192.168.3.100; # 前端可访问的IP(局域网/公网) } # HTTP 服务(API/前端/跨域) http_api { enabled on; listen 1985; # API 端口 } http_server { enabled on; listen 8080; # 前端访问端口 dir ./objs/nginx/html; # SRS 内置前端目录 crossdomain on; # 跨域支持(自定义前端必备) } # Vhost 配置(6.x 精简版,仅保留支持的项) vhost __defaultVhost__ { # RTC 核心配置(RTMP转WebRTC关键) rtc { enabled on; # 开启 RTC 能力 rtmp_to_rtc on; # 开启 RTMP 转 WebRTC(6.x 支持) rtc_to_rtmp on; # 开启 RTC 转 RTMP(双向互转) nack on; # 丢包重传 twcc on; # 拥塞控制(可选) } # HTTP 解复用(支持 FLV 兜底播放) http_remux { enabled on; mount [vhost]/[app]/[stream].flv; } # HLS 支持(备用方案,6.x 兼容) hls { enabled on; hls_fragment 10; hls_window 60; } }
3.验证配置文件+临时测试
1.检查配置文件 ./objs/srs -c conf/rtc_web.conf -t 2.临时测试: #启动 SRS(指定自定义配置) ./objs/srs -c conf/rtc_web.conf # 杀死srs进程 sudo pkill -9 srs # 查看SRS的状态 ./etc/init.d/srs status # 或者看SRS的日志 tail -n 30 -f ./objs/srs.log # 启动 ./objs/srs -c conf/srs.conf # 停止 ./etc/init.d/srs stop # 重启 ./etc/init.d/srs restart
4.配置systemed后台启动
1.创建SRS服务文件
sudo vim /etc/systemd/system/srs.service
srs.service 配置文件如下:
[Unit] Description=SRS(Simple Real-Time Server) - WebRTC/RTMP Streaming Server After=network.target network-online.target Wants=network-online.target [Service] # SRS运行用户(推荐用非root用户,如www,需先创建:useradd -r -s /sbin/nologin www) User=www Group=www # SRS安装目录(替换为你的实际路径,比如/usr/local/srs) WorkingDirectory=/home/user/srs/trunk # 启动命令(配置文件用绝对路径,避免相对路径问题) ExecStart=/home/user/srs/trunk/objs/srs -c /home/user/srs/trunk/conf/rtc_web.conf # 进程守护配置:崩溃/超时自动重启(生产核心) Restart=always RestartSec=3 # 崩溃后3秒重启 TimeoutSec=30 # 启动超时时间 # 日志配置(集成systemd journal,也可保留文件日志) StandardOutput=journal+console StandardError=journal+console # 进程优先级 Nice=10 [Install] # 开机自启的运行级别 WantedBy=multi-user.target
2.启动并设置开机自启
sudo systemctl daemon-reload
sudo systemctl start srs
sudo systemctl enable srs
sudo systemctl restart srs
sudo systemctl stop srs
3.验证服务状态
sudo systemctl status srs # 输出 "active (running)" 即为正常
4.运维命令
# 启动SRS sudo systemctl start srs # 停止SRS sudo systemctl stop srs # 重启SRS(修改配置后生效) sudo systemctl restart srs # 查看SRS状态(含运行日志) sudo systemctl status srs # 关闭开机自启 systemctl disable srs # 查看SRS详细日志(systemd集成,无需单独看日志文件) journalctl -u srs -f # -f实时跟踪日志 journalctl -u srs --since "10 minutes ago" # 查看最近10分钟日志

浙公网安备 33010602011771号