linux下配置nginx+rtmp+obs推流

linux下配置nginx+rtmp+obs推流
1、下载Nginx及相关组件
进入用户目录下载程序

cd /usr/local/src/

下载相关组件,安装前4个

 wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
 wget http://zlib.net/zlib-1.2.11.tar.gz 
 wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz 
 wget http://nginx.org/download/nginx-1.8.1.tar.gz	
 wget http://nginx.org/download/nginx-1.10.2.tar.gz	有问题装不上rtmp 
 wget http://nginx.org/download/nginx-1.16.0.tar.gz	有问题装不上rtmp

安装c++编译环境,如已安装可略过

[root@localhost src]# yum install gcc-c++

省略安装内容…
期间会有确认提示输入y回车

Is this ok [y/N]:y

省略安装内容…

2、安装Nginx及相关组件
openssl安装

[root@localhost src]# tar zxvf openssl-fips-2.0.10.tar.gz

省略安装内容…

[root@localhost src]# cd openssl-fips-2.0.10
[root@localhost openssl-fips-2.0.10]# ./config && make && make install

省略安装内容…

pcre安装

[root@localhost src]# tar zxvf pcre-8.40.tar.gz

省略安装内容…

[root@localhost src]# cd pcre-8.40
[root@localhost pcre-8.40]# ./configure && make && make install

省略安装内容…

zlib安装

[root@localhost src]# tar zxvf zlib-1.2.11.tar.gz

省略安装内容…

[root@localhost src]# cd zlib-1.2.11
[root@localhost zlib-1.2.11]# ./configure && make && make install

省略安装内容…

nginx安装

[root@localhost src]# tar zxvf nginx-1.8.1.tar.gz

省略安装内容…

[root@localhost src]# cd nginx-1.8.1
[root@localhost nginx-1.8.1]# ./configure && make && make install

省略安装内容…
安装时报错了
在这里插入图片描述
解决错误1:进入到nginx-1.8.1目录下(解压的目录)

找到当前目录下找到objs文件夹,并进入,打开文件Makefile,找到有一下内容的这行:

[root@lnmp nginx-1.8.1]# vim objs/Makefile
CFLAGS =  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g 

-Werror: gcc将所有的警告当成错误进行处理把这行内容中的 “-Werror”去掉
在重新编译make又出现一个错误

这里提示我们struct crypt_data’没有名为‘current_salt’的成员:cd.current_salt[0] = ~salt[0];
最好的办法是换一个版本,因为条件限制,我们就进到源码里把这行直接注释掉好了。
在这里插入图片描述

[root@lnmp nginx-1.8.1]# vim src/os/unix/ngx_user.c

进去找到第36行
在这里插入图片描述
在这里插入图片描述

[root@iZwz95w0d1f4luqgag1e9pZ nginx-1.8.1]# make 
[root@iZwz95w0d1f4luqgag1e9pZ nginx-1.8.1]# make install

openssl版本错误
原因:由于默认使用了openssl 1.1.x 版本,导致的API不一致引起
直接安装openssl1.0版本

wget http://www.openssl.org/source/openssl-1.1.0e.tar.gz //下载openssl
tar -zxvf openssl-1.1.0e.tar.gz //解压
cd openssl-1.1.0e/ &&./config shared zlib --prefix=/usr/local/openssl&& make && make install 进入目录把openssl编译安装到 /usr/local/openssl 下
[root@iZgt88z6l1kvd7Z openssl-1.1.0e]# ./config -t
[root@iZgt88z6l1kvd7Z openssl-1.1.0e]# make depend //一种度makefile的规则,通过扫描仪个目录下的所有C\C++ 代码,从而判专断出文件之间的依赖关系,如a.cc文件中调用了b.h(如以形势include<b.h>),如果之后a.cc文件被改动,那 么只需要重新编属译a.cc文件,不需要编译b.h文件。否则所有的文件都需要重新编译。
[root@localhost openssl-1.1.0e]# cd /usr/local
[root@iZgt88z6l1kvd7Z local]# ln -s openssl ssl
[root@iZgt88z6l1kvd7Z local]# echo "/usr/local/openssl/lib" >>/etc/ld.so.conf
[root@iZgt88z6l1kvd7Z local]# cd -
/root/openssl-1.1.0e
[root@iZgt88z6l1kvd7Z openssl-1.1.0e]# ldconfig
[root@iZgt88z6l1kvd7Z openssl-1.1.0e]# echo $?
0
[root@iZgt88z6l1kvd7Z openssl-1.1.0e]# echo "PATH=$PATH:/usr/local/openssl/bin" >> /etc/profile && source /etc/profile

我们再次进入nginx下

[root@iZgt88z6l1kvd7Z nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8 --with-openssl=../opensll-1.1.0e

!注意这里还是要把objs/Makefile下的werror去掉
然后启动一下nginx

[root@iZgt88z6l1kvd7Z nginx-1.10.1]# /usr/local/nginx/sbin/nginx

设置一下环境变量

[root@iZgt88z6l1kvd7Z sbin]# echo "PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile && source /etc/profile

查看一下进程和端口是否开启
看看chrome能不能打开nginx的网页
3、启动Nginx
先找一下nginx安装到什么位置上了

[root@iZwz95w0d1f4luqgag1e9pZ nginx-1.8.1]# whereis nginx
	nginx:/usr/local/nginx 

进入nginx目录并启动

cd /usr/local/nginx/
/usr/local/nginx/sbin/nginx

或者这样启动

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

在关闭防火墙到时候,出现:

Redirecting to /bin/systemctl stop  iptables.service
Failed to stop iptables.service: Unit iptables.service not loaded.

解决方法:

暂时关闭防火墙

yum install iptables-services

实际上,centos7后是使用的基于iptable的systemctl stop firewalld

systemctl stop firewalld

谷歌输入公网ip地址访问进入欢迎页面,输入自己的服务器地址
在这里插入图片描述

下载相关组件

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

今天在解压zip文件
gzip: stdin has more than one entry–rest ignored
tar: Child returned status 2
tar: Error is not recoverable: exiting now
解决
没有unzip 安装

yum install unzip

nginx-rtmp-module安装
然后解压

unzip master.zip

运行 unzip master.zip解压完成

nginx-rtmp-module安装

[root@localhost src]# cd /usr/local/src/nginx-1.8.1

#完成rtmp模块安装,=后面输入你的模块包的绝对路径

[root@localhost nginx-1.8.1]# ./configure --add-module=/usr/local/src/nginx-rtmp-module-master
[root@lnmp nginx-1.8.1]# vim objs/Makefile
CFLAGS =  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g 

-Werror”去掉

[root@localhost nginx-1.8.1]# make -j6
[root@localhost nginx-1.8.1]# sudo make install
[root@localhost nginx-1.8.1]# sudo vim /usr/local/nginx/conf/nginx.conf

在最后加

 rtmp {

    server {

        listen 1935;  #监听的端口  

        chunk_size 4000;

        application hls {  #rtmp推流请求路径  
            live on;
            hls on;
            hls_path /usr/local/nginx/html/hls;
            hls_fragment 5s;
        }
    }
}

还有就是这个路径,看你自己的实际情况的访问根目录来,我的是/usr/local/nginx/html/这个路径,
然而/usr/local/nginx/html/hls肯定没有这个目录,所以需要建一个放流文件的目录hls,并且需要改权限可读可写的权限

:wq
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

更改sudo vim /usr/local/nginx/conf/nginx.conf
端口改成81 listen 81;
改root的保存路径

 location / {
            root   /usr/local/nginx/html;
            index  index.html index.htm;
        }

保存退出
需要在网页上显示的拉到/usr/local/nginx/html文件夹下面
浏览器上显示
将播放的视频放到/usr/local/nginx/html目录下 播放文件名改成mp4结尾http://ip地址:端口/播放文件名http://端口号/test.mp4`

obs推流

结束
cd /usr/local/nginx/sbin/nginx
-s stop

查看占用端口
netstat -ntlp 80
后面的多少端口用kill 383杀死
重启nginx

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值