官方文档:https://github.com/ossrs/srs/wiki/v1_CN_Home?spm=a2c4e.10696291.0.0.687519a4izveKe
注意:SRS不支持Windows系统如果使用Windows搭建则可使用Docker实现,切记 修改配置中的IP以及路径
参考链接:https://github.com/ossrs/srs/tree/1.0release#usage
工具安装:yum install -y git make
源码拉取:git clone https://github.com/ossrs/srs
编译:进入目录(srs/trunk)运行./configure && make
启动:进入目录(srs/trunk)运行././objs/srs -c conf/srs.conf
A 编写SRS鉴权配置文件(conf/authentication.conf)
listen 1934;
srs_log_tank file;
srs_log_file ./objs/logs/yuanzan2.log;
max_connections 1000;
vhost __defaultVhost__ {
gop_cache off;
queue_length 10;
min_latency on;
mr {
enabled off;
}
mw_latency 100;
tcp_nodelay on;
play {
gop_cache off;
queue_length 10;
mw_latency 100;
}
publish {
mr off;
}
##鉴权 无序鉴权可忽略
http_hooks {
enabled on;
on_connect http://127.0.01/ #鉴权地址
on_close http://127.0.01/ #鉴权地址
on_publish http://127.0.01/ #鉴权地址
on_unpublish http://127.0.01/ #鉴权地址
on_play http://127.0.01/ #鉴权地址
on_stop http://127.0.01/ #鉴权地址
}
}
B 启动SRS
./objs/srs -c conf/authentication.conf
备注: 将47.75.111.156修改为实际php访问服务器ip地址
参考链接:https://github.com/ossrs/srs/wiki/v1_CN_SampleRTMPCluster
1 conf/origin1.conf
listen 1935;
srs_log_tank file;
srs_log_file ./objs/logs/yuanzan1.log;
pid conf/cluster/yuanzan1.pid;
max_connections 2000;
http_server {
enabled on;
listen 2935;
dir ./objs/nginx/html;
}
http_api {
enabled on;
listen 1985;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
gop_cache off;
queue_length 10;
min_latency on;
mr {
enabled off;
}
mw_latency 100;
tcp_nodelay on;
##鉴权 无序鉴权可忽略
http_hooks {
enabled on;
on_connect http://127.0.01/ #鉴权地址
on_close http://127.0.01/ #鉴权地址
on_publish http://127.0.01/ #鉴权地址
on_unpublish http://127.0.01/ #鉴权地址
on_play http://127.0.01/ #鉴权地址
on_stop http://127.0.01/ #鉴权地址
}
cluster {
#集群的模式,对于源站集群,值应该是local。
mode local;
#是否开启源站集群
origin_cluster on;
#源站集群中的其他源站的HTTP API地址
coworkers 172.31.30.35:1985;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
2 conf/origin1.conf
listen 1935;
srs_log_tank file;
srs_log_file ./objs/logs/yuanzan2.log;
pid conf/cluster/yuanzan2.pid;
max_connections 2000;
http_server {
enabled on;
listen 2935;
dir ./objs/nginx/html;
}
http_api {
enabled on;
listen 1985;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
gop_cache off;
queue_length 10;
min_latency on;
mr {
enabled off;
}
mw_latency 100;
tcp_nodelay on;
##鉴权 无序鉴权可忽略
http_hooks {
enabled on;
on_connect http://127.0.01/ #鉴权地址
on_close http://127.0.01/ #鉴权地址
on_publish http://127.0.01/ #鉴权地址
on_unpublish http://127.0.01/ #鉴权地址
on_play http://127.0.01/ #鉴权地址
on_stop http://127.0.01/ #鉴权地址
}
cluster {
#集群的模式,对于源站集群,值应该是local。
mode local;
#是否开启源站集群
origin_cluster on;
#源站集群中的其他源站的HTTP API地址
coworkers 172.31.30.32:1985;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
1 conf/edge1.conf
listen 19350;
srs_log_tank file;
srs_log_file ./objs/logs/bianyuan1.log;
pid conf/cluster/bianyuan1.pid;
max_connections 2000;
http_server {
enabled on;
listen 29350;
dir ./objs/nginx/html;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
gop_cache off;
queue_length 10;
min_latency on;
mr {
enabled off;
}
mw_latency 100;
tcp_nodelay on;
##鉴权 无序鉴权可忽略
http_hooks {
enabled on;
on_connect http://127.0.01/ #鉴权地址
on_close http://127.0.01/ #鉴权地址
on_publish http://127.0.01/ #鉴权地址
on_unpublish http://127.0.01/ #鉴权地址
on_play http://127.0.01/ #鉴权地址
on_stop http://127.0.01/ #鉴权地址
}
cluster {
#集群的模式,对于源站集群,值应该是local。
mode remote;
#源站集群中所有源站流地址
origin 172.31.30.35:1935 172.31.30.32:1935;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
2 conf/edge2.conf
listen 19350;
srs_log_tank file;
srs_log_file ./objs/logs/bianyuan2.log;
pid conf/cluster/bianyuan2.pid;
max_connections 2000;
http_server {
enabled on;
listen 29350;
dir ./objs/nginx/html;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
gop_cache off;
queue_length 10;
min_latency on;
mr {
enabled off;
}
mw_latency 100;
tcp_nodelay on;
##鉴权 无序鉴权可忽略
http_hooks {
enabled on;
on_connect http://127.0.01/ #鉴权地址
on_close http://127.0.01/ #鉴权地址
on_publish http://127.0.01/ #鉴权地址
on_unpublish http://127.0.01/ #鉴权地址
on_play http://127.0.01/ #鉴权地址
on_stop http://127.0.01/ #鉴权地址
}
cluster {
#集群的模式,对于源站集群,值应该是local。
mode remote;
#源站集群中所有源站流地址
origin 172.31.30.35:1935 172.31.30.32:1935;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
./objs/srs -c conf/origin1.conf &
./objs/srs -c conf/origin2.conf &
./objs/srs -c conf/edge1.conf &
./objs/srs -c conf/edge2.conf &
备注:请将所有实例的IP地址192.168.1.170都换成部署的服务器IP地址。
1 安装编译工具
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
2 安装PCRE
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
tar zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install
验证是否安装成功
pcre-config --version
2 下载nginx
wget http://nginx.org/download/nginx-1.17.5.tar.gz
3 编译安装
###注意修改路径
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 --with-stream=dynamic
make
1 rtmp-push转发配置
#注意更换目录
load_module /data/nginx/objs/ngx_stream_module.so;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
events {
worker_connections 1024;
}
stream{
upstream rmtp-push{
server 47.52.195.184:1935;
server 47.75.58.155:1935;
}
server{
listen 1935;
proxy_pass rmtp-push;
}
}
http{
upstream rtmp-http-server{
server 127.0.0.1:2935;
server 127.0.0.1:2935;
}
server{
listen 2935;
location / {
proxy_pass http://rtmp-http-server;
}
}
}
2 rtmp-pull转发配置
#注意更换目录
load_module /data/nginx/objs/ngx_stream_module.so;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
events {
worker_connections 1024;
}
stream{
upstream rmtp-pull{
server 127.0.0.1:19350;
server 127.0.0.1:19350;
}
server{
listen 19350;
proxy_pass rmtp-pull;
}
}
http{
upstream rtmp-http-server{
server 127.0.0.1:29350;
server 127.0.0.1:29350;
}
server{
listen 2935;
location / {
proxy_pass http://rtmp-http-server;
}
}
}
3 注意修改IP以及路径