#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,並在不斷更新中.