可参考www.bt.cn 官方的教程,这里是centos的安装脚本,因为版本的变化可能会有更新,请先去官网查询。
yum install -y wget && wget -O install.sh https://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec
这里因为要用rtmp的模块,所以要用新的nginx来替换宝塔的安装源。
这里要先安装宝塔的nginx,再卸载,添加模块后,再安装一次。
yum install -y gcc gcc-c++ autoconf wgetyum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype*
cd /www/server/ clone https://github.com/arut/nginx-rtmp-module.git
通过面板的文件菜单,编辑/www/server/panel/install/nginx.sh
如果没有找到nginx.sh,是因为没有安装过nginx。可以先安装,再卸载。
查找 export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH ,在它下面有 ./configure ,这这个代码后面加入
--add-module=/www/server/nginx-rtmp-module
保存。
sh /www/server/panel/install/nginx.sh install 1.22
这里的1.22是版本号,可根据需要安装,原则上是越新安全性越好
安装完成后,可通过nginx -V查看模块是否安装成功。
打开/www/server/nginx/conf/nginx.conf文件,或者进入宝塔软件商店中nginx的“配置修改”栏目
在nginx.conf中添加以下内容(与http同级):
在修改前确认一下推流文件的存储位置,hls目录需要手工建立
rtmp { server { listen 1935; #监听的端口 ,可以改为你自己喜欢的端口号,记得在宝塔后台放行此端口!!! chunk_size 4000; application hls { #rtmp推流请求路径,可以改为你自己的地址,比如live live on; hls on; hls_path /www/server/nginx/hls; #这个目录就是推流文件存储的位置 hls_fragment 5s; } } }
可以用OBS等推流软件,向服务器的rmtp://IP:1935/hls/test推流了
播放地址为http://ip/hls/test.m3u8
这里的test为直播码
工作原理,调用nginx-rtmp-module的统计功能在WEB显示
修改网站配置文件
打开/www/server/nginx/conf/nginx.conf文件,或者进入宝塔软件商店中nginx的“配置修改”栏目
在nginx.conf中添加以下内容(与http同级):
server { listen 8000; location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { root /www/server/nginx-rtmp-module; } }
修改配置后,保存,重新加载Ngnix配置,同时在宝塔面板中打开8000端口。
这样打开服务器的http://ip:8000/stat 就可以看到推流统计了。
推流服务器参考设置
rtmp_auto_push on; rtmp_auto_push_reconnect 1s; rtmp { server { listen 1935; respawn on; respawn_timeout 2s; chunk_size 4096; ping 20s; ping_timeout 10s; #低带宽10秒积累延迟丢弃积累视频 drop_idle_publisher 5s; publish_notify on; idle_streams off; application swh { live on; #直播流状态响应反馈接口 #on_publish http://name/openapi/update_status?status=up; #on_publish_done http://name/openapi/update_status?status=down; #on_record_done http://name/openapi/update_status?status=on_record_done; allow play all; #直播流HLS转码观看 hls on;#前端服务器204分片直播 hls_path /home/wwwroot/recorder/hls; #hls_fragment 3s; #直播流转推 push rtmp://192.162.64.204:1935; #直播流启用录制 recorder rec { record all;#手动控制录制启停 #record_suffix _%Y%m%d-%H%I%S.mp4; record_suffix .flv; record_path /www/wwwroot/name/data/recorder/swh/;#录制保存地址 record_unique off;#是否添加时间戳到录制文件。否则的话同样的文件在每一次新的录制发生时将被重写。默认为 off record_append on;#切换文件附加模式。当这一指令为开启是,录制时将把新数据附加到老文件,如果老文件丢失的话将重新创建一个。文件中的老数据和新数据没有时间差。默认为 off } } } }
微信扫码添加微信好友