red5单机还是比较不错的,但是官方网站没有文档,不知道集群怎么配置,网查找了半天,只有red5 0.8版本有集群配置。以后的版本看了一下,有集群的插件,但是不知道怎么装插件,就算装好了插件,怎么配置集群,还是不知道啊。没文档坑爹。
crtmpserver 流媒体服务器,研究学习,感觉还是不错的,下面说一下,集群配置。
一,crtmpserver下载
https://github.com/j0sh/crtmpserver
二,服务器说明
192.168.10.208 主服务器
192.168.10.202 从服务器
三,主从服务器安装crtmpserver
1,安装相关依赖包
# yum install cmake openssl openssl-devel gcc gcc-c++ make
2,安装crtmpserver
# unzip centosinit.zip
# cd crtmpserver-centosinit
# chmod +x cleanup.sh
# sh cleanup.sh
# cd builders/cmake
# cmake .
# make
3,主服务器208配置
# vim ./crtmpserver/crtmpserver.lua
{ //85行,acceptors加入,rtmp可以使用80端口。如果80有其他用处,就不要这样设置了
ip="0.0.0.0",
port=80,
protocol="inboundRtmp"
},
name="proxypublish", //256行,配置集群的地方
description="Application for forwarding streams to another RTMP server",
protocol="dynamiclinklibrary",
acceptors = //相当于一个连接池
{
{
ip="0.0.0.0",
port=6665, //连接池的端口
protocol="inboundRtmp" //添加
--protocol="inboundLiveFlv" //--注释原来的
},
},
abortOnConnectError=true,
targetServers =
{
{
targetUri="rtmp://192.168.10.208/live/", //实际rtmp服务器
targetStreamType="live",
localStreamName="test",
keepAlive=true,
emulateUserAgent="my master"
},
{
targetUri="rtmp://192.168.10.202:1935/live/", //实际的rtmp服务器
targetStreamType="live",
emulateUserAgent="My user agent",
localStreamName="test",
keepAlive=true
}
}
注意,crtmpserver默认占用8080,8081,有的http会占用这二个端口。端口冲突的话,crtmpserver是启不来的。
4,从服务器默认配置就行了,当然你想做一特殊配置也是可以的。
四,启动主从服务器
# ./crtmpserver/crtmpserver ./crtmpserver/crtmpserver.lua
//出现以下内容说明启动成功了
+-----------------------------------------------------------------------------+
| Services|
+---+---------------+-----+-------------------------+-------------------------+
| c | ip | port| protocol stack name | application name |
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 1112| inboundJsonCli| admin|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 80| inboundRtmp| appselector|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 1935| inboundRtmp| appselector|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 8081| inboundRtmps| appselector|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 8080| inboundRtmpt| appselector|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 6666| inboundLiveFlv| flvplayback|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 9999| inboundTcpTs| flvplayback|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 554| inboundRtsp| flvplayback|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 6665| inboundRtmp| proxypublish|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 8989| httpEchoProtocol| samplefactory|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 8988| echoProtocol| samplefactory|
+---+---------------+-----+-------------------------+-------------------------+
|tcp| 0.0.0.0| 1111| inboundHttpXmlVariant| vptests|
+---+---------------+-----+-------------------------+-------------------------+
/root/crtmpserver-centosinit/sources/crtmpserver/src/crtmpserver.cpp:272 GO! GO! GO! (31278)
注意,先启动从服务器,这一点很重要。
五,测试crtmpserver集群配置,以下安装在主服务器208
1,安装rpmforge
# rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
根你的linux版本选择
2,安装ffmpeg
# yum install ffmpeg
3,利用ffmpeg发布rtmp流
# ffmpeg -re -i "/root/test.flv" -vcodec copy -acodec copy -f flv rtmp://192.168.10.208:6665/live/test //连接池端口
ffmpeg version 2.2.1 Copyright (c) 2000-2014 the FFmpeg developers
built on Apr 13 2014 13:00:18 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --enable-runtime-cpudetect --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --enable-pthreads --enable-x11grab --enable-vdpau --disable-avisynth --enable-frei0r --enable-libopencv --enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --disable-stripping
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100
Input #0, flv, from '/root/test.flv':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf55.33.100
Duration: 00:22:15.69, start: 0.000000, bitrate: 391 kb/s
Stream #0:0: Video: flv1, yuv420p, 320x240, 320 kb/s, 15 tbr, 1k tbn, 1k tbc
Stream #0:1: Audio: mp3, 22050 Hz, stereo, s16p, 0 kb/s
rtmp server sent error
rtmp server sent error
Output #0, flv, to 'rtmp://192.168.10.208:6665/live/test':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2mp41
encoder : Lavf55.33.100
Stream #0:0: Video: flv1 ([2][0][0][0] / 0x0002), yuv420p, 320x240, q=2-31, 320 kb/s, 1k tbn, 1k tbc
Stream #0:1: Audio: mp3 ([2][0][0][0] / 0x0002), 22050 Hz, stereo, 0 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 23 fps= 15 q=-1.0 size= 131kB time=00:00:01.54 bitrate= 694.1kbits/s //往rtmp通道传输数据,会不停的变化直接,直到视频结束
4,接收rtmp流,网上工具好多,就不多说了
rtmp://192.168.10.208:6665/live/test
rtmp://192.168.10.208/live/test
rtmp://192.168.10.202:1935/live/test
以上三个rtmp通道,都可以看ffmpeg发布的视频流