nginx+nginx

    xiaoxiao2021-12-14  21

    有一套直播的系统,想跑器来,但是要流媒体服务器,刚开始想到的是是否可以用第三方比如七牛云,但是七牛云流媒体服务器要企业用户才开放,那就自己搭建一个

    安装依赖包:

    yum install gcc glibc glibc-devel libtool make openssl-devel-0.9.8e pkgconfig lib-devel mhash.x86_64 pcre-8.30 nasm gettext-devel gettext-devel perl-Digest-SHA1.x86_64

    安装ffmpeg及其依赖包

    依赖包所需软件 http://pan.baidu.com/s/1qXDkzLU主要是下载很慢先分享出来media.rar里面有需要的依赖

    +++++++++++++yasm+++++++++++++

    tar zxf yasm-1.2.0.tar.gz cd yasm-1.2.0 ./configure make && make install cd ..

    +++++++++++++x264+++++++++++++

    cd x264 ./configure --enable-shared make && make install cd ..

    +++++++++++++LAME+++++++++++++

    tar zxf lame-3.99.5.tar.gz cd lame-3.99.5 ./configure --enable-nasm make && make install cd ..

    +++++++++++++libogg+++++++++++++

    tar zxf libogg-1.3.0.tar.gz cd libogg-1.3.0 ./configure make && make install cd ..

    +++++++++++++libvorbis+++++++++++++

    tar zxf libvorbis-1.3.3.tar.gz cd libvorbis-1.3.3 ./configure make && make install cd ..

    +++++++++++++libvpx+++++++++++++

    tar -xjf libvpx-v1.3.0.tar.bz2 cd libvpx-v1.3.0 ./configure --enable-shared make && make install cd ..

    +++++++++++++FAAD2+++++++++++++

    tar zxf faad2-2.7.tar.gz cd faad2-2.7 ./configure make && make install cd ..

    +++++++++++++FAAC+++++++++++++

    tar zxf faac-1.28.tar.gz cd faac-1.28 ./configure make && make install cd ..

    PS.编译的时候遇到mpeg4ip.h:126: error: new declaration ‘char* strcasestr(const char*, const char*)’的错误请看【编译FAAC-1.28时遇到的错误于解决方法】

    +++++++++++++xvidcore+++++++++++++ tar zxf xvidcore-1.3.2.tar.gz cd xvidcore/build/generic ./configure make && make install cd ../../../

    +++++++++++++libaacplus+++++++++++++

    tar zxf libaacplus-2.0.2.tar.gz cd libaacplus-2.0.2 ./autogen.sh ./configure make && make install cd ..

    ps.安装后检查是否有库文件

    ls /usr/local/lib|grep libaacplus libaacplus.so libaacplus.so.2

    +++++++++++++Ffmpeg+++++++++++++

    tar zxf ffmpeg-2.1.tar.gz cd ffmpeg-2.1 ./configure --prefix=/opt/ffmpeg/ --enable-version3 --enable-libvpx --enable-libfaac --enable-libmp3lame --enable-libvorbis --enable-libx264 --enable-libxvid --enable-shared --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --enable-libaacplus make && make install cd ..

    #以上所有安装后修改/etc/ld.so.conf库配置文件如下:

    vi /etc/ld.so.conf

    #添加以下内容:

    /lib /lib64 /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 /opt/ffmpeg/lib

    添加以上内容后运行命令:

    ldconfig

    注意!如果以上相关包有新加或是重新安装,需要重新执行:ldconfig #使其新加的库文件加载

    /opt/ffmpeg/bin/ffmpeg -i

    安装Nginx相关模块

    Nginx的安装就不多讲了,我这里已经安装了nginx我需要添加模块重新编译我的nginx安装在/usr/local/nginx/目录下新建一个目录

    mkdir /usr/local/nginx/nginx_mod

    下载3个相关模块 http://pan.baidu.com/s/1qXDkzLU把下载nginx_mod.rar的丢到nginx_mod目录里面

    cd /usr/local/nginx/nginx_mod tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz mv nginx_mod_h264_streaming-2.2.7 nginx_mod_h264_streaming mv nginx-rtmp-module nginx_mod_rtmp tar -zxvf pcre-8.30.tar.gz mv pcre-8.30 nginx_mod_pcrenginx -V #查看已安装nginx的配置参数

    在原来编译的参数后面添加

    --with-http_flv_module --with-http_gzip_static_module --with-http_mp4_module --with-cc-opt=-I/opt/ffmpeg/include --with-ld-opt='-L/opt/ffmpeg/lib -Wl,-rpath=/opt/ffmpeg/lib' --add-module=/usr/local/nginx/nginx_mod/nginx_mod_h264_streaming/ --add-module=/usr/local/nginx/nginx_mod/nginx_mod_rtmp/ --with-pcre=/usr/local/nginx/nginx_mod/nginx_mod_pcre

    重新编译

    进入nginx源码目录执行我的nginx源码目录是/root/lnmp1.2-full/src/nginx-1.8.0

    cd /root/lnmp1.2-full/src/nginx-1.8.0 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_gzip_static_module --with-http_mp4_module --with-cc-opt=-I/opt/ffmpeg/include --with-ld-opt='-L/opt/ffmpeg/lib -Wl,-rpath=/opt/ffmpeg/lib' --add-module=/usr/local/nginx/nginx_mod/nginx_mod_h264_streaming/ --add-module=/usr/local/nginx/nginx_mod/nginx_mod_rtmp/ --with-pcre=/usr/local/nginx/nginx_mod/nginx_mod_pcre make #不要make install,否则覆盖安装

    PS.nginx_mod_h264_streaming-2.2.7.tar.gz编译时会出错:ngx_http_streaming_module.c:158: 错误:‘ngx_http_request_t’ 没有名为 ‘zero_in_uri’ 的成员解决方法:

    vi /usr/local/nginx/nginx_mod/nginx_mod_h264_streaming/src/ngx_http_streaming_module.c

    #需要注释掉 第158行:

    /* if (r->zero_in_uri) { return NGX_DECLINED; } */

    已运行nginx,需先停止

    service nginx stop cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak cp /root/lnmp1.2-full/src/nginx-1.8.0/objs/nginx /usr/local/nginx/sbin/nginx service nginx start

    配置 nginx.conf

    vi /usr/local/nginx/conf/nginx.conf

    添加rtmp模块参数

    rtmp { server { listen 1935; application vod { #Directory of flv files play /home/wwwroot/default/live; } } }

    PS.路径可以修改成自己的,我这里live目录没有,mkdir live创建一个目录

    nginx -t #测试配置

    如果没有错误,重新nginx

    service nginx restart

    测试流媒体是否安装成功下载jwplayer ,需要注册,邮件地址必须正确jwplayer官网: http://www.jwplayer.com百度云盘上live.rar是我用来测测,里面有写好的测试demo

    参考:http://www.cnblogs.com/janas/p/3665486.html

    QQ交流群:136351212查看原文:https://www.phpsong.com/2626.html
    转载请注明原文地址: https://ju.6miu.com/read-970586.html

    最新回复(0)