openresty +rtmp 搭建视频直播服务器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012618915/article/details/81180421

最近搭建了一个rtmp直播服务器, 因为nginx的rtmp服务器本身需要一些http的控制, 所以选用了openresty这个nginx+lua的http框架, 再其中包含rtmp服务器, 这样既可以充当rtmp直播服务器,也可以充当http,还可以直接在其中用lua脚本完成相关控制!
现具体说明:

系统环境:linux centos6.5
环境附属安装:
yum install gcc
yum install pcre-devel
yum install openssl-devel
yum install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev
yum install libxml2 libxml2-devel libxslt libxslt-devel
yum install perl perl-devel perl-ExtUtils-Embed

openresty 下载地址: https://openresty.org/en/download.html
里面有widnows, linux各种版本, 选取好自己所用的版本, 本博客用的是linux最新的版本
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar xzvf openresty-1.13.6.2.tar.gz
cd openresty-1.13.6.2/bundle/LuaJIT-2.1-20180420
make && make install
ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit
以上是单独安装luajit,这是以前的版本安装方法, 现在最新的版本安装luajit已经合并到./configure里面自动编译, 以上的步骤可以跳过, 不过我喜欢按这个方法来, 如果出现问题可以很好的知道哪出现问题,纯属个人喜好。
在budlle目录下执行
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
tar xzvf 2.3.tar.gz
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
tar xzvf v0.3.0.tar.gz
nginx rtmp module 下载最新的版本 地址: https://github.com/arut/nginx-rtmp-module
解压到该目录

到现在,准备工作已经完成, 现可以编译
cd openresty-1.13.6.2

./configure –prefix=/opt/openresty –with-luajit –with-http_ssl_module –user=root –group=root –with-http_realip_module –add-module=./bundle/ngx_cache_purge-2.3/ –add-module=./bundle/nginx_upstream_check_module-0.3.0/ –add-module=./bundle/nginx-rtmp-module-master –with-cc-opt=”-I/usr/local/ssl/include” –with-ld-opt=”-L/usr/local/ssl/lib” –with-http_xslt_module –with-http_stub_status_module –with-http_gzip_static_module –with-http_flv_module –with-http_perl_module –with-mail

说明 加粗的这段是因为执行./configure时, 一直找不到本机的openssl库, 所以手动添加该库的地址, 所包含的参数具体都是干什么用的, 请自行百度谷歌。
make && make install
就安装完成了,
现贴出所使用的conf配置, 一些常用的功能都已经添加, 在需要别的功能的时候, 我会更新本博客

=================nginx.conf=====================================================

user root;
worker_processes 1;

daemon off;

error_log logs/error.log;

error_log logs/error.log notice;

error_log logs/error.log info;

pid logs/nginx.pid;

events {
worker_connections 1024;
}
rtmp {
#设置rtmp的日志记录, 该记录只有在直播流结束后过显示在日志里, 不能connect的阶段记录, 该问题暂未解决
log_format rtmp_main ‘ r e m o t e a d d r [ time_local] c o m m a n d " app” “ n a m e "" args” ’
b y t e s r e c e i v e d bytes_sent “ p a g e u r l "" flashver” ( s e s s i o n r e a d a b l e t i m e ) connection $session_time ‘;
access_log logs/rtmp_access.log rtmp_main;
server{
listen 1935;
ack_window 5000;#窗口大小
chunk_size 1024;
application live {

        live on;
        wait_key on;
        drop_idle_publisher 10s;
        wait_video on;
        interleave on;
        sync 10ms;
    }
}

}

http {
include mime.types;
default_type application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
    listen       80;
    server_name  localhost;
    location / {
        root   html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location /stat {
        rtmp_stat all;
        rtmp_stat_stylesheet stat.xsl;#将stat.xsl文件放置到安装目录里的html文件夹中
    }

    location /stat.xsl {
        root html;
    }
    location /nclients {  
        proxy_pass http://127.0.0.1/stat;  #将nclients.xsl文件放置到安装目录里的html文件夹中, nclients.xsl具体内容在下面
        xslt_stylesheet html/nclients.xsl app='$arg_app' name='$arg_name';  
        add_header Refresh "3; $request_uri";  
    }

    location /test{
        content_by_lua_file conf/lua/test.lua;#测试lua执行的helloworld
    }     

    location /control{
        rtmp_control all;#rtmp的http控制api生效
    }

}

}
————-nclients.xsl———————————————————————–




以上就可以启动nginx, 生效我们自己的rtmp服务器!

如果觉得有用, 请关注我的博客!!!!
做专注最接地气流媒体相关内容!!!!
我以后也会尽可能,尽自己最大水平持续更新!!!!

猜你喜欢

转载自blog.csdn.net/u012618915/article/details/81180421