Clone
25
v3_CN_SampleForward
winlin edited this page 2022-01-06 11:57:15 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

HOME > CN > Forward

RTMP流转发Forward部署实例

Note: 如果觉得Github的Wiki访问太慢可以访问 Gitee 镜像。

SRS可以将送到SRS的流转发给其他RTMP服务器实现简单集群/热备功能也可以实现一路流热备譬如编码器由于带宽限制只能送一路流到RTMP服务器要求RTMP服务器能将这路流也转发给其他RTMP备用服务器实现主备容错集群

假设服务器的IP是192.168.1.170

Forward就是SRS将流拷贝输出给其他的RTMP服务器以SRS转发给SRS为例

  • 主SRSMaster, 编码器推流到主SRS主SRS将流处理的同时将流转发到备SRS
  • 备SRSSlave, 主SRS转发流到备SRS就像编码器推送流到备用SRS一样。 我们的部署实例中主SRS侦听1935端口备SRS侦听19350端口。

第一步获取SRS。详细参考GIT获取代码

git clone https://github.com/ossrs/srs
cd srs/trunk

或者使用git更新已有代码

git pull

第二步编译SRS。详细参考Build

./configure && make

第三步编写主SRS配置文件。详细参考Forward

将以下内容保存为文件,譬如conf/forward.master.conf,服务器启动时指定该配置文件(srs的conf文件夹有该文件)。

# conf/forward.master.conf
listen              1935;
max_connections     1000;
pid                 ./objs/srs.master.pid;
srs_log_tank        file;
srs_log_file        ./objs/srs.master.log;
vhost __defaultVhost__ {
    forward {
        enabled on;
        destination 127.0.0.1:19350;
    }
}

第四步启动主SRS主SRS将流转发到备SRS。详细参考Forward

./objs/srs -c conf/forward.master.conf

第五步编写备SRS配置文件。详细参考Forward

将以下内容保存为文件,譬如conf/forward.slave.conf,服务器启动时指定该配置文件(srs的conf文件夹有该文件)。

# conf/forward.slave.conf
listen              19350;
pid                 ./objs/srs.slave.pid;
srs_log_tank        file;
srs_log_file        ./objs/srs.slave.log;
vhost __defaultVhost__ {
}

第六步启动备SRS主SRS将流转发到备SRS。详细参考Forward

./objs/srs -c conf/forward.slave.conf

注意启动srs后查看下srs是否启动成功错误可以查看日志。

[winlin@dev6 srs]$ sudo netstat -anp|grep srs
tcp        0      0 0.0.0.0:1935                0.0.0.0:*                   LISTEN      7826/srs            
tcp        0      0 0.0.0.0:19350               0.0.0.0:*                   LISTEN      7834/srs

第七步,启动推流编码器。详细参考Forward

使用FFMPEG命令推流

    for((;;)); do \
        ./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.200kbps.768x320.flv \
        -vcodec copy -acodec copy \
        -f flv -y rtmp://192.168.1.170/live/livestream; \
        sleep 1; \
    done

或使用FMLE推流

FMS URL: rtmp://192.168.1.170/live
Stream: livestream

涉及的流包括:

  • 编码器推送的流rtmp://192.168.1.170/live/livestream
  • 主SRS转发的流rtmp://192.168.1.170:19350/live/livestream
  • 观看主SRS的流rtmp://192.168.1.170/live/livestream
  • 观看备SRS的流rtmp://192.168.1.170:19350/live/livestream

第八步观看主SRS的RTMP流。详细参考Forward

RTMP流地址为rtmp://192.168.1.170/live/livestream

可以使用VLC观看。

或者使用在线SRS播放器播放srs-player

备注请将所有实例的IP地址192.168.1.170都换成部署的服务器IP地址。

第九步观看备SRS的RTMP流。详细参考Forward

RTMP流地址为rtmp://192.168.1.170:19350/live/livestream

可以使用VLC观看。

或者使用在线SRS播放器播放srs-player-19350

备注请将所有实例的IP地址192.168.1.170都换成部署的服务器IP地址。

Winlin 2014.3