Linux平台下使用nginx与nginx-rtmp-module搭建RTMP+HLS流媒体服务器

Linux平台下使用nginx与nginx-rtmp-module搭建RTMP+HLS流媒体服务器

  1. 下载nginx-rtmp-module

命令:wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

提示:服务器没有安装git command not found

CentOS下使用命令:yum install git –y

yum install -y unzip zip

解压:unzip master.zip

安装之后返回 cd ~

  1. 编译安装Nginx

a.安装zlib库
命令:wget http://www.zlib.net/zlib-1.2.11.tar.gz

命令tar xf zlib-1.12.11.tar.gz

cd zlib-1.2.11

./configure

make && make install

安装完返回 cd ~

b.安装openssl库
命令:wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz

tar xf openssl-1.0.2l.tar.gz

cd openssl-1.0.2l

./config

make && make install

安装完返回 cd ~

c.安装pcre库

只要安装bzip2

yum -y install bzip2

**命令:wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2

安装pcre包的时候提示缺少c++编译器

安装命令:yum –y install gcc-c++

更改yum 配置

tar xf pcre-8.38.tar.bz2

cd pcre-8.38

./configure

make && make install

安装完返回 cd ~   

d.编译安装Nginx

命令:wget http://nginx.org/download/nginx-1.13.4.tar.gz

tar xf nginx-1.13.4.tar.gz

cd nginx-1.13.4

./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module-master --with-http_ssl_module  --with-pcre=../pcre-8.38 --with-openssl=../openssl-1.0.2l --with-zlib=../zlib-1.2.11

make && make install

返回 cd ~

  1. 执行完以上步骤,不出错误的话,Nginx编译出生成到/usr/local/nginx  目录

cd ~

cd /usr/local/nginx/

tree

如果tree没有安装的话,请安装tree

命令:yum  install tree

查看安装是否成功命令:yum list installed tree

再执行  tree

  1. Nginx配置

输入命令:

vim /usr/local/nginx/conf/nginx.conf

“insert”键

加入以下内容

hls_path 需要可读可写的权限

cd ~

chmod 777 /html/hls

出现以下错误:

nginx: [emerg] mkdir() “/html/hls” failed (2: No such file or directory)

解决办法:mkdir -p /html/hls

修改http中server模块

退出 :qw 

回车

然后重启nginx

/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

关闭Linux防火墙

systemctl stop firewalld.service

关闭开机启动

systemctl disable firewalld.service

  1. 使用OBS推流

服务器的地址即是我的虚拟机ip hls

  1. 参考文档:

https://blog.csdn.net/liuchen1206/article/details/77771703

https://blog.csdn.net/l1028386804/article/details/80022437

https://blog.csdn.net/heng615975867/article/details/80519274

备注: 删除nginx

进入到这个nginx的目录

yum remove nginx

./nginx -c conf/nginx.conf

./nginx -s reload

 

 192.168.31.133 nginx访问不了,OBS连接服务器失败

进入nginx可执行目录sbin下输入./nginx -s reload 即可

输入完要是提示nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

解决:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 

Nginx 设置开机自启动

在rc.local增加启动代码

vi /etc/rc.local

增加一行 /usr/local/nginx/sbin/nginx

设置执行权限:

chmod 755 rc.local

chmod 755 /etc/rc.local

 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 nginx -s reload

https://www.jianshu.com/p/7a298a0c6052

posted @   量子纠缠的爱  阅读(780)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程
点击右上角即可分享
微信分享提示