您现在的位置是:物联网 >>正文
Nginx 动态编译加载第三方流媒体服务模块:Nginx-RTMP-Module
物联网7278人已围观
简介简介Nginx 1.9.11开始增加加载动态模块支持,可以在不停机的情况下加载和卸载模块。从此不再需要替换nginx文件即可增加第三方扩展。目前官方只有几个模块支持动态加载,第三方模块需要升级支持才可 ...
简介
Nginx 1.9.11开始增加加载动态模块支持,态编可以在不停机的译加情况下加载和卸载模块。从此不再需要替换nginx文件即可增加第三方扩展。载第目前官方只有几个模块支持动态加载,流服务第三方模块需要升级支持才可编译成模块 。媒体模块
通过帮助命令./configure --help | grep dynamic 查看是态编否支持动态加载模块
复制~/build/openresty-1.19.3.1$ ./configure --help | grep dynamic --with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module --with-http_image_filter_module=dynamic enable dynamic ngx_http_image_filter_module --with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module --with-http_perl_module=dynamic enable dynamic ngx_http_perl_module --with-mail=dynamic enable dynamic POP3/IMAP4/SMTP proxy module --with-stream=dynamic enable dynamic TCP/UDP proxy module --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module --add-dynamic-module=PATH enable dynamic external module --with-compat dynamic modules compatibility1.2.3.4.5.6.7.8.9.10.11.如上可看出官方支持9个动态模块编译 ,需要增加第三方模块,译加使用参数--add-dynamic-module=即可 。载第
动态模块概述
可以加载到NGINX中的流服务模块是亿华云用C编写的获取匹配的NGINX开源版本获取模块源,并在必要时更改模块的媒体模块配置文件使用configure命令的--add-dynamic-module参数针对NGINX开源版本构建动态模块将生成的动态模块(.so文件)加载到NGINX中(modules目录下),并像使用内置模块一样使用它动态模块语法
命令:load_moduleDefault: —上下文配置段: main说明 :版本必须>=1.9.11实例 :load_module modules/ngx_mail_module.so;编译动态模块
这里安装基于Nginx的态编流媒体服务器 :nginx-rtmp-module 模块
项目地址:https://github.com/arut/nginx-rtmp-module
下载 OpenRestyOpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,香港云服务器其内部集成了大量精良的译加 Lua 库 、第三方模块以及大多数的载第依赖项。用于方便地搭建能够处理超高并发、流服务扩展性极高的媒体模块动态 Web 应用、Web 服务和动态网关 。
复制// 下载 wget https://openresty.org/download/openresty-1.19.3.1.tar.gz // 解压 tar -zxvf openresty-1.19.3.1.tar.gz1.2.3.4.5. 下载 nginx-rtmp-module 复制git clone https://github.com/arut/nginx-rtmp-module.git1.下载模块路径地址为:/home/www/build/nginx-rtmp-module
编译进入 OpenResty 目录
复制cd openresty-1.19.3.11.编译
复制./configure --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 -O3 \ --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-pcre-jit \ --with-stream --with-stream_ssl_module --with-stream=dynamic --with-file-aio \ --with-threads --with-http_v2_module --with-http_realip_module \ --with-http_mp4_module --with-http_gzip_static_module --with-http_ssl_module \ --with-http_stub_status_module --with-http_xslt_module \ --with-openssl-opt=-g enable-tlsext --with-stream \ --with-stream_ssl_preread_module \ --with-compat --add-dynamic-module=/home/www/build/nginx-rtmp-module // 编译 make1.2.3.4.5.6.7.8.9.10.11.12.添加 --with-compat 选项 ,生成可加载模块的 Nginx 可执行文件
注意:这里不要执行make install 命令,免费模板否则会覆盖已安装的Nginx二进制文件 ,我们这里是动态加载只需要编译模块生成第三方模块.so文件就行了 。
复制模块到指定目录
将模块库ngx_rtmp_module.so文件复制到 /usr/local/openresty/nginx/modules
复制cp /home/www/build/openresty-1.19.3.1/build/nginx-1.19.3/objs/ngx_rtmp_module.so /usr/local/openresty/nginx/modules/1.加载模块
要将模块加载到Nginx,请将load_module指令添加到nginx.conf主配置文件的主上下文中 。
复制load_module modules/ngx_rtmp_module.so;1.nginx.conf主配置文件参考
复制user tinywan; worker_processes auto; // 其他配置... load_module modules/ngx_rtmp_module.so; // 其他配置...1.2.3.4.5.6.7.8.使用模块
新增流媒体服务器配置
复制rtmp { server { listen 1935; chunk_size 4000; drop_idle_publisher 10s; idle_streams off; application live { live on; } application hls { live on; hls on; hls_path /tmp/hls; } # MPEG-DASH is similar to HLS application dash { live on; dash on; dash_path /tmp/dash; } } }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.注意 :该配置需要和HTTP上下文并列,而不是放在HTTP模块里面
检测Nginx配置文件是否OK
复制sudo /usr/local/openresty/nginx/sbin/nginx -t nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful1.2.3.4.没问题直接重启openresty服务即可。服务器租用
复制sudo systemctl restart openresty.service1.安全组设置
打开安全组设置,在[入方向] 开放1935端口 ,1935端口是rtmp默认监听端口,必须在这里设置开放,否则在服务器中打开和监听1935端口后公网环境连接不到该端口。
图片
OBS 推流
推流地址:rtmp://{ 服务器公网IP}/live/tinywan2024
图片
VLC 拉流播放
拉流地址 :rtmp://{ 服务器公网IP}/live/tinywan2024
图片
出现“is not binary compatible in”错误的解决方案
复制sudo /usr/local/openresty/nginx/sbin/nginx -t nginx: [emerg] module "/usr/local/openresty/nginx/modules/ngx_rtmp_module.so" is not binary compatible in /usr/local/openresty/nginx/conf/nginx.conf:7 nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test failed1.2.3. 原因第三方模块的编译中包含的签名和使用的nignx不一致 。模板下载
解决方案先通过 nginx -V 命令得到当前配置的configure配置
复制/usr/local/openresty/nginx/sbin/nginx -V nginx version: openresty/1.19.3.1built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) built with OpenSSL 1.1.1 11 Sep 2018TLS SNI support enabledconfigure arguments: --prefix=/usr/local/openresty/nginx \ --with-cc-opt=-O2 -O3 --add-module=../ngx_devel_kit-0.3.1 \ --add-module=../iconv-nginx-module-0.14 \ --add-module=../echo-nginx-module-0.62 \ --add-module=../xss-nginx-module-0.06 \ --add-module=../ngx_coolkit-0.2 \ --add-module=../set-misc-nginx-module-0.32 \ --add-module=../form-input-nginx-module-0.12 \ --add-module=../encrypted-session-nginx-module-0.08 \ --add-module=../srcache-nginx-module-0.32 \ --add-module=../ngx_lua-0.10.19 \ --add-module=../ngx_lua_upstream-0.07 \ --add-module=../headers-more-nginx-module-0.33 \ --add-module=../array-var-nginx-module-0.05 \ --add-module=../memc-nginx-module-0.19 \ --add-module=../redis-nginx-module-0.3.7 \ --add-module=../rds-json-nginx-module-0.15 \ --add-module=../rds-csv-nginx-module-0.09 \ --add-module=../ngx_stream_lua-0.0.9 \ --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib \ --with-pcre-jit --with-stream --with-stream_ssl_module \ --with-stream=dynamic --with-file-aio --with-threads \ --with-http_v2_module --with-http_realip_module \ --with-http_mp4_module --with-http_gzip_static_module \ --with-http_ssl_module --with-http_stub_status_module \ --with-http_xslt_module --with-openssl-opt=-g enable-tlsext \ --with-stream --with-stream_ssl_preread_module1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.在复制所有的配置命令 。添加到 :
复制./configure [“你的nignx -V 得到的配置参数”] --add-dynamic-module=/home/www/build/nginx-rtmp-module1.注意事项 :
动态模块只能在 Nginx 1.9.11 及以上版本中使用。加载和卸载模块需要 root 权限。加载和卸载模块会影响 Nginx 的性能,建议在低峰期进行操作。加载和卸载模块可能会导致 Nginx 进程崩溃,建站模板建议备份配置文件和 Nginx 可执行文件。Tags:
转载:欢迎各位朋友分享到网络,但转载请说明文章出处“信息技术视野”。http://www.bziz.cn/html/508e8999402.html
相关文章
易受攻击的四个关键物联网安全问题
物联网无论是在家还是在工作,我们都被整个物联网设备生态系统所包围。这些小元素也被称为物联网,对于需要相互连接和通信(交换数据)的小设备来说是必不可少的。从智能家居和家电到照明,物联网设备无处不在,如智能手机 ...
【物联网】
阅读更多华为电脑装机分区教程(简单易懂的华为电脑分区方法及步骤)
物联网华为电脑是一款性能出色的设备,但对于不熟悉操作系统安装和分区的用户来说,可能会遇到一些困惑。本文将为大家提供华为电脑装机分区的详细教程,帮助用户轻松完成分区过程。了解分区的概念及作用在开始分区之前,首 ...
【物联网】
阅读更多火狐浏览器设置白名单网址关闭保护的教程
物联网火狐浏览器是一款不错的开源网页浏览器,支持多种操作系统,例如支持windows、macOS等,再加上其中快速、稳定、安全的上网环境,火狐浏览器为用户带来了良好的网页浏览服务,当用户在使用火狐浏览器时, ...
【物联网】
阅读更多
热门文章
最新文章
友情链接
- 体验XboxOneX的卓越性能与极致画质(探索一台引领游戏娱乐新纪元的游戏机)
- 如何找回ID账号和密码?(有效方法帮助你找回丢失的账号和密码)
- 最好的Mac解压工具推荐(选择一个适合你的Mac解压工具是多么重要)
- 数据中心电源的五大趋势
- 探究惠普导航的优势与应用(解密惠普导航的功能和使用体验)
- 昇腾AI异构计算架构CANN 6.0全新开放升级,全面释放AI生产力
- SKG抽油烟机质量评测(全面分析SKG抽油烟机的性能与可靠性)
- 华为Mate9拍摄视频全方位评测(华为Mate9拍视频功能强大,画质出色,满足各类拍摄需求)
- 央广银河(金融增值与财富管理的领先机构)
- 康佳P2如何打造智能生活新体验(品质、智能与创新的完美结合) 网站建设云服务器亿华云企业服务器源码库香港物理机b2b信息平台