Skip to content

v1_EN_SampleForward

winlin edited this page Nov 17, 2014 · 35 revisions

Forward deploy example

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

Suppose the server ip is 192.168.1.170

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

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

Step 1, get SRS. For detail, read GIT

git clone https://github.com/winlinvip/simple-rtmp-server
cd simple-rtmp-server/trunk

Or update the exists code:

git pull

Step 2, build SRS. For detail, read Build

./configure --disable-all --with-ssl && make

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

将以下内容保存为文件,譬如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         127.0.0.1:19350;
}

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

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

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

将以下内容保存为文件,譬如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。详细参考Cluster

./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

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

使用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流。详细参考Cluster

RTMP url is: rtmp://192.168.1.170:1935/live/livestream

User can use vlc to play the RTMP stream.

Or, use online SRS player: http://winlinvip.github.io/srs.release/trunk/research/players/srs_player.html?vhost=defaultVhost&autostart=true&server=192.168.1.170&app=live&stream=livestream&port=1935

Note: Please replace all ip 192.168.1.170 to your server ip.

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

RTMP url is: rtmp://192.168.1.170:19350/live/livestream

User can use vlc to play the RTMP stream.

Or, use online SRS player: http://winlinvip.github.io/srs.release/trunk/research/players/srs_player.html?vhost=defaultVhost&autostart=true&server=192.168.1.170&app=live&stream=livestream&port=19350

Note: Please replace all ip 192.168.1.170 to your server ip.

Winlin 2014.3

Welcome to SRS wiki!

SRS 5.0 wiki

Please select your language:

SRS 4.0 wiki

Please select your language:

SRS 3.0 wiki

Please select your language:

SRS 2.0 wiki

Please select your language:

SRS 1.0 wiki

Please select your language:

Clone this wiki locally