安装记录nginx+rtmp推流大疆的直播

大疆无人机需要推流到服务器上,使用rtmp协议推流

    • ubuntu16.04安装nginx1.18.0+rtmp
    • 背景ubuntu16.04非root用户
      • 安装依赖包
      • 安装依赖包报错
    • 安装nginx和rtmp module
    • 配置rtmp服务
    • 验证rtmp服务
    • 浏览器无flash插件后不支持rtmp协议直播,需要后续转化(待完成)

ubuntu16.04安装nginx1.18.0+rtmp

在安装成功之前我安装了nginx1.14.0和1.16.0都只有nginx成功,配套的rtmp模块被无法识别,换成了1.18.0版本成功推流。也许1.18.0比较顺利是因为前两版安装的时候一些错误都解决了。

所以这只是本人安装成功后的一些要点记录,没有记录全过程,不要当做完整教程!!

背景ubuntu16.04非root用户

安装依赖包

sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install openssl libssl-dev

安装依赖包报错

1、出现版本不匹配问题

$ sudo apt-get install libpcre3 libpcre3-dev
#---------------------------------
Reading package lists... Done
Building dependency tree
Reading state information... Done
libpcre3 is already the newest version (2:8.38-3.1).
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.

将安装命令换成报错信息括号里的版本

$ sudo apt-get install libpcre3=1:8.31-2ubuntu2.3
#----------------------------------------------------------------------
libpcre3-dev=1:8.31-2ubuntu2.3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libpcrecpp0
The following NEW packages will be installed:
  libpcre3-dev libpcrecpp0
The following packages will be DOWNGRADED:
  libpcre3
0 upgraded, 2 newly installed, 1 downgraded, 0 to remove and 9 not upgraded.
Need to get 396 kB of archives.
After this operation, 759 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu trusty-updates/main amd64 libpcre3 amd64 1:8.31-2ubuntu2.3 [144 kB]
Get:2 http://mirrors.aliyun.com/ubuntu trusty-updates/main amd64 libpcrecpp0 amd64 1:8.31-2ubuntu2.3 [14.5 kB]
Get:3 http://mirrors.aliyun.com/ubuntu trusty-updates/main amd64 libpcre3-dev amd64 1:8.31-2ubuntu2.3 [237 kB]
Fetched 396 kB in 0s (565 kB/s)
dpkg: warning: downgrading libpcre3:amd64 from 2:8.38-3.1 to 1:8.31-2ubuntu2.3
(Reading database ... 218985 files and directories currently installed.)
Preparing to unpack .../libpcre3_1%3a8.31-2ubuntu2.3_amd64.deb ...
Unpacking libpcre3:amd64 (1:8.31-2ubuntu2.3) over (2:8.38-3.1) ...
Processing triggers for libc-bin (2.23-0ubuntu11.2) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libpcre3:amd64 (1:8.31-2ubuntu2.3) ...
Processing triggers for libc-bin (2.23-0ubuntu11.2) ...
Selecting previously unselected package libpcrecpp0:amd64.
(Reading database ... 218985 files and directories currently installed.)
Preparing to unpack .../libpcrecpp0_1%3a8.31-2ubuntu2.3_amd64.deb ...
Unpacking libpcrecpp0:amd64 (1:8.31-2ubuntu2.3) ...
Selecting previously unselected package libpcre3-dev:amd64.
Preparing to unpack .../libpcre3-dev_1%3a8.31-2ubuntu2.3_amd64.deb ...
Unpacking libpcre3-dev:amd64 (1:8.31-2ubuntu2.3) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libpcrecpp0:amd64 (1:8.31-2ubuntu2.3) ...
Setting up libpcre3-dev:amd64 (1:8.31-2ubuntu2.3) ...
Processing triggers for libc-bin (2.23-0ubuntu11.2) ...

libssl-dev安装错误,换成报错信息里的版本也未解决:

libssl-dev : 依赖: libssl1.0.0 (= 1.0.1f-1ubuntu2.18) 但是 1.0.1f-1ubuntu9.8 正要被安装
$: sudo apt-get install libssl1.0.0 (= 1.0.1f-1ubuntu2.18)也不管用

2、需要使用apitude降级版本

$:sudo apt-get install aptitude
The following packages have unmet dependencies.
 aptitude : Depends: libcwidget3 but it is not going to be installed
            Depends: libsigc++-2.0-0c2a (>= 2.0.2) but it is not going to be installed
            Depends: libxapian22 but it is not going to be installed

           Recommends: apt-xapian-index but it is not going to be installed
#需要安装报错信息里的所有依赖包
$: sudo apt-get install libsigc++-2.0-0c2a
$: sudo apt-get install libxapian22 
$:sudo apt-get install aptitude

参考该文章解决安装libssl-dev的依赖问题

3、重新执行$ sudo apt-get install libssl-dev命令

$sudo apt-get install openssl libssl-dev

Reading package lists... Done
Building dependency tree
Reading state information... Done
libssl-dev is already the newest version (1.0.1f-1ubuntu2.27).
openssl is already the newest version (1.0.1f-1ubuntu2.27).
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
(base) hadoop@slave1:~/DJI$ sudo apt-get install openssl libssl-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libssl-dev is already the newest version (1.0.1f-1ubuntu2.27).
openssl is already the newest version (1.0.1f-1ubuntu2.27).
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
成功!!!!

安装nginx和rtmp module

1-3.资源下载参考这篇博客的1-3步骤Ubuntu18.04下nginx-1.18.0 + rtmp服务器搭建

4.编译并安装nginx

最好新建一个文件夹用来存放编译后的文件。本人在nginx-1.18.0目录下新建一个文件夹叫build。

cd nginx-1.18.0  #必须进入到nginx-版本号下才能使用./configure命令
mkdir build    #build文件夹是用来放置编译后的文件
./configure --prefix=xxx(#这里是build文件路径) --add-module=xxx/nginx-rtmp-module(这里是nginx-rtmp-module资源的路径) --with-http_stub_status_module(#添加stat模块,该语句可以不使用) 
make -f objs/Makefile #一般使用make命令就可以,但是这里make命令无法识别,进入objs/Makefile发现make命令是make -f objs/Makefile
make install  #编译后的文件在build里

5.启动nginx服务

由于非root用户不能访问1024以下的端口,无法启动nginx。需要修改build/conf/目录下的nginx.conf文件里http的serve端口(未修改的端口默认为80)。

本人修改成8088了,查看tcp的端口列表中没有8088需要将其添加进去。

#不知道我有没有少记录一些命令,可以自行搜索如何添加新端口
$ sysctl -w net.ipv4.ip_forward=1
sysctl: permission denied on key 'net.ipv4.ip_forward'
(base) hadoop@slave1:~/DJI$ sudo sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1
(base) hadoop@slave1:~/DJI$ iptables -F -t nat
iptables v1.6.0: can't initialize iptables table `nat': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.
(base) hadoop@slave1:~/DJI$ sudo iptables -F -t nat
(base) hadoop@slave1:~/DJI$

(base) hadoop@slave1:~/DJI$ sudo iptables -I INPUT -p tcp --dport 8088 -j ACCEPT
(base) hadoop@slave1:~/DJI$ sudo iptables-save #开放新端口并保存

由于本服务器系统根目录下docker也部署了nginx,不能直接使用systemctl start nginx

#cd 到build目录下的sbin文件里
 $ cd /home/hadoop/DJI/nginx/nginx-1.18.0/build/sbin/ 
 $ ./nginx     #nginx服务启动,在浏览器里输入地址——服务器ip:8088验证,若成功页面会出现Welcome to nginx!
 $ ./nginx -s quit        # 停止服务
 $./nginx -s reload        #重启

配置rtmp服务

  • 对应文章Ubuntu18.04下nginx-1.18.0 + rtmp服务器搭建的第7步
#进入nginx安装目录的conf目录下修改配置文件
$ cd /home/hadoop/DJI/nginx/nginx-1.18.0/build/conf/

修改以下两个配置文件,文末加入以下内容:

$ sudo vi nginx.conf
$ sudo vi nginx.conf.default
rtmp {
    server {
        listen 1935;

        application rtmplive {   #rtmplive可以改成其他名字
            live on;    #实时直播 on
            max_connections 1024;
        }
    }
}

修改配置文件后需要重启服务器

验证rtmp服务

大疆直播推流到服务器,使用VLC拉流,推流和拉流地址都为

rtmp://服务器ip:1935/rtmplive

浏览器无flash插件后不支持rtmp协议直播,需要后续转化(待完成)

  • 可以参考以下视频,讲解十分清楚,我试的过程甚至和视频一模一样,只是到最后一步配置好rtmp后,启动nginx无法成功,因为无法识别配置文件nginx.conf里的rtmp,找了内外网各种方法都未解决。视频制作者安装是成功的,也许其他小伙伴按照这个方法能成功。
  • 视频链接:使用nginx-rtmp打造简易直播系统

你可能感兴趣的:(nginx,ubuntu,运维)