Centos中安装带rtmp模块的Nginx

Centos中安装带rtmp模块的Nginx

很多流媒体功能如直播,点播等功能都能够通过Nginx实现。

Nginx官方有一个hls模块实现了HlS协议,但是这个模块为企业版Nginx功能,github上有大佬自己编写了一个开源的nginx-rtmp-module,实现了Nginx官方的hls协议

在Linux系统中安装Nginx时,即可通过二进制编译添加该模块,后续即可以实现rtmp协议。

通过github上的readme指导安装,以下是安装过程,以及一些安装中碰到的小问题

也可以通过脚本一键进行安装,点我下载脚本

一、Centos安装

参考网上Centos安装教程,默认安装就行了,因为只是作为推流服务器和流媒体服务器使用,所以安装的是最小版本。

二、环境准备

1.编译工具安装

安装好CentOS以后,需要安装各种编译工具,如pcre,gcc等,用于对二进制源码进行编译安装

具体命令如下

yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel gcc gcc-c++ 

安装一些支持工具

如vim,wget和lsof

yum install -y vim wget lsof git zip unzip

###2. 获取Nginx二进制源码

通过测试,rtmp模块暂时只支持Nginx13-15版本,在官网中下载稳定版的Nginx14

wget http://nginx.org/download/nginx-1.14.2.tar.gz

下载nginx-rtmp-module

wget https://github.com/arut/nginx-rtmp-module/archive/refs/tags/v1.2.1.tar.gz

下载源码以后,解压

tar xf v1.2.1.tar.gz
tar xf nginx-1.14.2.tar.gz

配置编译,将rtmp模块添加到nginx中

如果出现./configure: error: no ../nginx-rtmp-module/config was found

去掉--with-http_ssl_module重新配置一次,或者直接重新配置

配置完成后直接进行编译安装

cd nginx-1.14.2
./configure --add-module=../nginx-rtmp-module-1.2.1/ --with-http_ssl_module
make && make install
#建立软链接
ln -s /usr/local/nginx/sbin/nginx /usr/bin

三、安装后配置

1. 启用rtmp配置

通过修改nginx的配置文件,启用rtmp模块

vim /usr/local/nginx/conf/nginx.conf
#user  nobody;
worker_processes  1;

#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 {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                }

                application hls {
                        live on;
                        hls on;
                        hls_path /usr/local/nginx/hls;
                        hls_fragment 8s;
                }
        }
}

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;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

2. 开启Nginx服务

nginx

3. 开启端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=1935/tcp --permanent

4.验证服务

通过OBS等测试是否成功

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Virtual Me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值