- #centos6.6安装搭建nginx+ffmpeg流媒体服务器
- #此系统实现了视频文件的直播及缓存点播,并支持移动端播放(支持Apple和Android端)
- #系统需要自行安装,流媒体服务器配置完成之后桌面可能挂掉,以后维护需要进命令行进行操作
- #必须按照以下步骤配置流媒体服务器,每一步必须要完成才可以配置成功
- # "#"是文档注释内容 "--"也是注释内容
- # 1.首先设置服务器IP地址,并更改为自动连接
- # 2.修改系统时间和时区为当前时间
- # 3.关闭防火墙
- #在控制台进行如下操作(需要登录root账号): 安装所有的依赖包:
- yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64
- #在usr/local/目录下面新建nginx文件夹
- #打开命令窗口
- #输入:
- mkdir soft-source
- cd soft-source
- #安装git
- wget http://codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.xz
- xz -d git-latest.tar.xz
- tar xf git-latest.tar
- #cd进入的是当前安装的日期
- cd git-2014-12-29
- autoconf
- ./configure
- make
- make install
- git --version --查看git的版本
- cd ..
- #安装zlib
- wget http://zlib.net/zlib-1.2.8.tar.gz
- tar -zxvf zlib-1.2.8.tar.gz
- cd zlib-1.2.8
- ./configure
- make
- make install
- cd ..
- #安装pcre
- wget http://exim.mirror.fr/pcre/pcre-8.12.tar.gz
- tar zxvf pcre-8.12.tar.gz
- cd pcre-8.12
- ./configure
- make
- # make的时候如果出现错误:
- # libtool: compile: unrecognized option `-DHAVE_CONFIG_H'
- # libtool: compile: Try `libtool --help' for more information.
- # make[1]: *** [pcrecpp.lo] Error 1
- # make[1]: Leaving directory `/home/mfcai/pcre-8.10'
- # make: *** [all] Error 2
- # make install
- 执行:yum install gcc gcc-c++ kernel-devel
- 然后:./configure
- make
- make install
- cd ..
- #安装yadmi给flv视频添加关键帧
- wget http://sourceforge.net/projects/yamdi/files/yamdi/1.4/yamdi-1.4.tar.gz
- tar xzvf yamdi-1.4.tar.gz
- cd yamdi-1.4
- make
- make install
- cd ..
- #安装OpenSSL
- wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
- tar -zxvf openssl-1.0.1c.tar.gz
- cd openssl-1.0.1c
- ./config
- make
- make install
- cd ..
- #安装ffmpeg及其依赖包:
- yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel
- 安装Yasm
- cd /usr/local/nginx
- mkdir ffmpeg_sources
- cd ffmpeg_sources
- wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
- tar xzvf yasm-1.3.0.tar.gz
- cd yasm-1.3.0
- ./configure
- make
- make install
- cd ..
- #安装ffmpeg
- cd /ffmpeg_sources
- git clone --depth 1 git://source.ffmpeg.org/ffmpeg
- cd ffmpeg
- PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
- ./configure
- make install
- #ffmpeg正常安装后执行ffmpeg时出现如下错误:
- # ffmpeg: error while loading shared libraries: libavdevice.so.53: cannot open shared object file: No such file or directory
- #解决办法:
- vi /etc/ld.so.conf
- #加入:
- /usr/local/lib
- #执行
- ldconfig
- #安装nginx模块
- cd /usr/local/nginx/soft-source
- wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
- tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
- git clone git://github.com/arut/nginx-rtmp-module.git
- #nginx安装
- wget http://nginx.org/download/nginx-1.6.0.tar.gz
- tar zxvf nginx-1.6.0.tar.gz
- cd nginx-1.6.0
- #编译安装nginx(直接复制nginx_configure.sh至nginx-1.6.0目录,文件在附件中)
- cp nginx_configure.sh /usr/local/nginx/soft-source/nginx-1.6.0
- chmod +x nginx_configure.sh
- ./nginx_configure.sh
- make
- #在执行make的时候可能出现错误
- # /root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c: In function 'ngx_streaming_handler':
- # /root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c:158: error: 'ngx_http_request_t' has no member named 'zero_in_uri'
- # make[1]: *** [objs/addon/src/ngx_http_h264_streaming_module.o] Error 1
- # make[1]: Leaving directory `/root/nginx-0.8.54'
- # make: *** [build] Error 2
- #解决方法:
- #将/usr/local/nginx/soft-source/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c文件中以下代码删除或者是注释掉就可以了:大概在157行
- # /* TODO: Win32 */
- # if (r->zero_in_uri)
- # {
- # return NGX_DECLINED;
- # }
- #
- #在执行make的时候可能出现错误
- # ../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c: 在函数'esds_read'中:
- # ../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:377:16: 错误: 变量'stream_priority'被设定但未被使用 [-Werror=unused-but-set-variable]
- # ../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:376:12: 错误: 变量'stream_id'被设定但未被使用 [-Werror=unused-but-set-variable]
- # ../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c: 在函数'stsd_parse_vide'中:
- # ../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:529:22: 错误: 变量'level_indication'被设定但未被使用 [-Werror=unused-but-set-variable]
- # ../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:528:22: 错误: 变量'profile_compatibility'被设定但未被使用 [-Werror=unused-but-set-variable]
- # ../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:527:22: 错误: 变量'profile_indication'被设定但未被使用 [-Werror=unused-but-set-variable]
- # ../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:526:22: 错误: 变量'configuration_version'被设定但未被使用 [-Werror=unused-but-set-variable]
- # cc1: all warnings being treated as errors
- # make[1]: *** [objs/addon/src/mp4_reader.o] 错误 1
- #解决方法:
- # vi objs/Makefile (修改nginx-1.6.0/objs/Makefile文件, 去掉其中的"-Werror"), 然后就能够正常编译了.
- # 然后再make就能过了。
- vi objs/Makefile
- make install
- #开放80和1935端口 关闭防火墙
- /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 写入修改
- /sbin/iptables -I INPUT -p tcp --dport 1935 -j ACCEPT 写入修改
- /etc/init.d/iptables save 保存修改
- #关闭防火墙
- service iptables stop
- #查看端口状态
- /etc/init.d/iptables status
- 端口映射
- 映射流媒体服务器的 80 1935 22 端口到外网
- #配置Nginx相关模块
- 进入到nginx文件夹!执行./nginx启动nginx
- 然后进行推送到nginx
- rtmp://x.x.x.x/hls/ch68h
- 播放
- rtmp://x.x.x.x.:1935/hls/ch68h
- http://x.x.x.x/hls/ch68h.m3u8
- 以上内容为流媒体服务器的基本配置说明,根据项目不同可配置不同的配置文件,因Nginx配置文件为核心文件,所以暂不公开,如有需要的可与我沟通联系,此系统已经完善部署到几十个项目中,运行状况良好,同时也有少许bug,并在不断更新中.
来源: http://www.cnblogs.com/mrccjj/p/6974185.html