100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Docker 实战系列之 SRS 流媒体服务器

Docker 实战系列之 SRS 流媒体服务器

时间:2018-08-18 01:31:39

相关推荐

Docker 实战系列之 SRS 流媒体服务器

1、简介

1.1、官网概述

SRS定位是运营级的互联网直播服务器集群,追求更好的概念完整性和最简单实现的代码。SRS提供了丰富的接入方案将RTMP流接入SRS, 包括推送RTMP到SRS、推送RTSP/UDP/FLV到SRS、拉取流到SRS。 SRS还支持将接入的RTMP流进行各种变换,譬如将RTMP流转码、流截图、 转发给其他服务器、转封装成HTTP-FLV流、转封装成HLS、 转封装成HDS、转封装成DASH、录制成FLV/MP4。SRS包含支大规模集群如CDN业务的关键特性, 譬如RTMP多级集群、源站集群、VHOST虚拟服务器 、 无中断服务Reload、HTTP-FLV集群。此外,SRS还提供丰富的应用接口, 包括HTTP回调、安全策略Security、HTTP API接口、 RTMP测速。SRS在源站和CDN集群中都得到了广泛的应用Applications。

1.2、官网资料

SRS 官网地址

SRS WIKI 地址

SRS HTTP 回调

SRS DRM 防盗链

1.3、镜像列表

SRS Docker Hub

2、准备工作

2.1、安装 Docker

CentOS7 安装 Docker

2.2、创建 bridge 网络并指定 IP 区间

#创建自定义网络docker network create --driver bridge --subnet 172.0.0.0/16 woniu_network#查看已存在网络docker network ls

2.3、创建数据目录

# 创建数据目录mkdir -p /home/docker/srs4

3、安装 SRS

3.1、创建配置文件

# 安装并启动 srsdocker run -p 1935:1935 -p 1985:1985 -p 8080:8080 \--name srs \ossrs/srs:v4.0.85

3.2、复制配置文件

# 把容器中的配置文件复制出来docker cp -a srs:/usr/local/srs/conf /home/docker/srs4/conf# 把容器中的数据文件复制出来docker cp -a srs:/usr/local/srs/objs /home/docker/srs4/objs# 删除 srs 容器docker rm -f srs

3.3、启动 SRS

docker run -p 1935:1935 -p 1985:1985 -p 8080:8080 \--name srs \--network woniu_network \--ip 172.0.0.35 \--restart=always \-v /home/docker/srs4/conf/:/usr/local/srs/conf/ \-v /home/docker/srs4/objs/:/usr/local/srs/objs/ \ossrs/srs:v4.0.85

5、SRS 控制台

# SRS 控制台访问地址http://服务器 IP 地址:8080

6、实战配置

6.1、自定义配置文件

# SRS 参考配置listen 1935;max_connections1000;srs_log_tank file;srs_log_file ./objs/srs.log;daemon on;http_api {enabled on;listen1985;}http_server {enabled on;listen8080;dir ./objs/nginx/html;# 开启 https 支持,需要开放 8088端口# https {# enabled on;# listen 8088;# key ./conf/woniu.key;# cert ./conf/woniu.crt;# }}vhost __defaultVhost__ {# http-flv设置http_remux{enabled on;mount[vhost]/[app]/[stream].flv;hstrson;}# hls设置hls {enabled on;hls_fragment 1;hls_window2;hls_path ./objs/nginx/html;hls_m3u8_file [app]/[stream].m3u8;hls_ts_file[app]/[stream]-[seq].ts;}# dvr设置dvr {enabled off;dvr_path ./objs/nginx/html/[app]/[stream]/[]/[01]/[02]/[timestamp].flv;dvr_plan segment;dvr_duration 30;dvr_wait_keyframe on;}# rtc 设置rtc {enabledon;bframediscard;}# SRS支持refer防盗链:检查用户从哪个网站过来的。譬如不是从公司的页面过来的人都不让看。refer {# whether enable the refer hotlink-denial.# default: off.enabled off;# the common refer for play and publish.# if the page url of client not in the refer, access denied.# if not specified this field, allow all.# default: not specified.all github.io;# refer for publish clients specified.# the common refer is not overrided by this.# if not specified this field, allow all.# default: not specified.publish github.io;# refer for play clients specified.# the common refer is not overrided by this.# if not specified this field, allow all.# default: not specified.play github.io;}# http 回调http_hooks {# 事件:发生该事件时,即回调指定的HTTP地址。# HTTP地址:可以支持多个,以空格分隔,SRS会依次回调这些接口。# 数据:SRS将数据POST到HTTP接口。# 返回值:SRS要求HTTP服务器返回HTTP200并且response内容为整数错误码(0表示成功),其他错误码会断开客户端连接。# whether the http hooks enable.# default off.enabled on;# 当客户端连接到指定的vhost和app时on_connecthttp://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;# 当客户端关闭连接,或者SRS主动关闭连接时on_close http://127.0.0.1:8085/api/v1/clients http://localhost:8085/api/v1/clients;# 当客户端发布流时,譬如flash/FMLE方式推流到服务器on_publishhttp://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;# 当客户端停止发布流时on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;# 当客户端开始播放流时on_play http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;# 当客户端停止播放时。备注:停止播放可能不会关闭连接,还能再继续播放。on_stop http://127.0.0.1:8085/api/v1/sessions http://localhost:8085/api/v1/sessions;# 当DVR录制关闭一个flv文件时on_dvrhttp://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;# 当HLS生成一个ts文件时on_hlshttp://127.0.0.1:8085/api/v1/hls http://localhost:8085/api/v1/hls;# when srs reap a ts file of hls, call this hook,on_hls_notify http://127.0.0.1:8085/api/v1/hls/[app]/[stream]/[ts_url][param];}}

6.2、指定配置文件启动 SRS

docker run -p 1935:1935 -p 1985:1985 -p 8080:8080 \--name srs \--network woniu_network \--ip 172.0.0.35 \--restart=always \-v /home/docker/srs4/conf/:/usr/local/srs/conf/ \-v /home/docker/srs4/objs/:/usr/local/srs/objs/ \ossrs/srs:v4.0.85 \./objs/srs -c conf/srs.woniu.conf

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。