Loading... ## 0x01 前言 有时候需要用到OBS推流给朋友直播些内容,但是现有的直播平台基本都需要实名认证,并且直播间处于公开状态,考虑到我有公网IP,干脆自己搭建Rtmp服务好了。 ## 0x02 所需工具与环境 >系统:CentOS 7.2 nginx:http://nginx.org/en/download.html nginx-rtmp-module:https://github.com/arut/nginx-rtmp-module 推流工具:OBS ## 0x03 编译安装Nginx与Rtmp模块 ```shell #依赖安装 yum install -y wget git yum install -y pcre-devel zlib-devel openssl openssl-devel yum -y install gcc gcc-c++ autoconf automake make ``` ```shell #编译安装Nginx与Rtmp模块 wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -zxvf nginx-1.18.0.tar.gz git clone https://github.com/arut/nginx-rtmp-module.git cd /root/nginx-1.18.0 ./configure --add-module=../nginx-rtmp-module --prefix=/usr/local/nginx --with-http_ssl_module make && make install ``` ```shell #关闭防火墙 systemctl stop firewalld systemctl disable firewalld #启动Nginx服务 cd /usr/local/ngnix ./sbin/nginx #其它参数 #停止Nginx服务 -s stop #重启Nginx服务 -s reload ``` > 安装完成后使用浏览器访问服务地址,如果你能看到Welcome to nginx!即代表安装成功 ## 0x04 配置 ```shell #编辑Nginx配置文件 vim /usr/local/nginx/conf/nginx.conf #加入如下配置 rtmp { server { listen 1935; #监听端口,RTMP默认端口为1935 chunk_size 4000; application hls { live on; hls on; hls_path /usr/local/nginx/html/hls;#视频流存放地址,此路径需要读写权限 hls_fragment 5s; #设置HLS片段长度 hls_playlist_length 15s;#设置HLS播放列表长度 hls_continuous on; #连续模式 hls_cleanup on; #对多余的切片进行删除 hls_nested on; #嵌套模式 } } } #创建视频流存放文件夹 mkdir /usr/local/nginx/html/hls chmod 777 /usr/local/nginx/html/hls #重启Nginx服务 cd /usr/local/ngnix ./sbin/nginx -s reload ``` ## 0x05 推流 > 使用OBS推流,串流密钥可自定义  ##0x06 拉流 > 拉流地址为:http://192.168.1.10/hls/test 最后修改:2020 年 09 月 16 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0 如果觉得我的文章对你有用,请随意赞赏