前言

最近接手了一个跟视频监控相关的项目,用了近年来越来越流行的 Web 服务器 nginx 加上 nginx-rtmp-module 搭建 rtmp 服务器。使用了阿里云的服务器,系统 Ubuntu 16.04 。

步骤

更新源并安装 nginx 。

sudo apt-get update
sudo apt-get install nginx

输入 nginx -V 查看 nginx 版本,可以看到当前版本号是 1.10.3,且可以看到编译选项。所以下一步要做的是下载相同版本的 nginx 源码,使用相同的编译选项并添加 nginx-rtmp-module,替换原来的 nginx 。

下载 nginx 1.10.3 的源码和 nginx-rtmp-module 的源码。

wget https://nginx.org/download/nginx-1.10.3.tar.gz
tar zxvf nginx-1.10.3.tar.gz
git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git
cp -r nginx-rtmp-module nginx-1.10.3

在第 3 步中可以得知安装的 nginx 的编译选项,所以套用这些编译选项,在上一步已经把 nginx-rtmp-module 复制到 nginx 源码目录,所以在结尾添加 --add-module=./nginx-rtmp-module 。在 nginx-1.10.3 目录执行以下命令:

./configure --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads --add-module=./nginx-rtmp-module

上一步执行后可能会提示以下几个错误,需安装相关软件包,然后再次执行步骤 5 的命令。

./configure: error: the HTTP rewrite module requires the PCRE library.
./configure: error: SSL modules require the OpenSSL library.
./configure: error: the HTTP XSLT module requires the libxml2/libxslt
./configure: error: the HTTP image filter module requires the GD library.
./configure: error: the GeoIP module requires the GeoIP library.
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install openssl libssl-dev
sudo apt-get install libxml2 libxml2-dev libxslt-dev
sudo apt-get install libgd2-xpm-dev
sudo apt-get install libgeoip-dev

上一步执行完成后 make,等待 nginx 编译完成。编译过程可能会出现 error: macro "DATE" might prevent reproducible builds 错误,在 CFLAGS 中添加 -Wno-error=date-time 参数即可,也就是步骤5的命令改成

./configure --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -Wno-error=date-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads --add-module=./nginx-rtmp-module

编译完成后,在 objs 目录下会有 nginx 的可执行文件。首先停止 nginx 服务,替换掉 nginx 。

sudo service nginx stop
cd /usr/sbin
sudo mv nginx nginx.bak
sudo cp ~/nginx-1.10.3/objs/nginx ./

修改 /etc/nginx/nginx.conf,在结尾添加使其开启 nginx-rtmp-module 相关的功能。

rtmp {
server {
listen 1935;
chunk_size 4000;
application live {
live on;
}
}
}

执行 sudo service nginx restart 重启 nginx 服务,然后执行 netstat -a|grep 1935,可以看到 1935 端口处于 LISTEN 状态,即可向 nginx 推流。更多强大的功能可以查看 nginx-rtmp-module

nginx 搭建 rtmp 服务器的更多相关文章

  1. windows环境下基于nginx搭建rtmp服务器

    基于nginx搭建rtmp服务器需要引入rtmp模块,引入之后需重新编译nginx linux环境几个命令行就能实现编译,笔者未尝试,网上有很多教程. windows环境还需要安装一系列的编译环境,例 ...

  2. Linux上用nginx搭建RTMP服务器

    参考文章:https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.5 ...

  3. 使用nginx搭建rtmp服务器

    一.软件需求 1.nginx源码包  下载地址:http://nginx.org/.笔者下载的是1.10.3. 2.pcre源码包.这是一个正则表达式库.nginx会用到这个开源库来做正则匹配.很多软 ...

  4. 搭建rtmp直播流服务之1:使用nginx搭建rtmp直播流服务器(nginx-rtmp模块的安装以及rtmp直播流配置)

    欢迎大家积极开心的加入讨论群 群号:371249677 (点击这里进群) 一.方案简要 首先通过对开发方案的仔细研究(实时监控.流媒体.直播流方案的数据源-->协议转换-->服务器--&g ...

  5. Nginx 搭建图片服务器

    Nginx 搭建图片服务器 本章内容通过Nginx 和 FTP 搭建图片服务器.在学习本章内容前,请确保您的Linux 系统已经安装了Nginx和Vsftpd. Nginx 安装:http://www ...

  6. Varnish,Nginx搭建缓存服务器

    Varnish,Nginx搭建缓存服务器 一. varnish 1.安装pcre库,兼容正则表达式 # tar -zxvf pcre-8.10.tar.gz # cd pcre-8.10 # ./co ...

  7. Nginx搭建图片服务器

    Nginx搭建图片服务器 标签(空格分隔): linux,nginx Nginx常用命令 ./nginx 启动 ./nginx -s reload 重载配置文件 ./nginx -s stop|sta ...

  8. 悄摸直播(三)—— 搭建rtmp服务器(smart_rtmpd - rtmp服务器搭建)

    悄摸直播 -- javaCV实现本机摄像头画面远程直播 搭建rtmp服务器 一.素材 rtmp服务器:smart_rtmpd ffmpeg工具:ffmpeg.exe 二.搭建 1.下载smart_rt ...

  9. nginx 搭建图片服务器(windows 下,linux 下原理应该一样)

    作者的心声:很多知道的.用过的东西,不写下来,下次还要百度查询,浪费时间和精力,故本次写下学习笔记,方便下次查阅. 题外话:如有读者通过我这篇博客解决了工作上的难题,可以给个评论,让我一起分享你的喜悦 ...

随机推荐

  1. Navicat for Oracle中如何使用外键

    转自:https://blog.csdn.net/weixin_39183543/article/details/80555104 1. 外键名最后保存的时候自动生成: 2. 参考模式自动生成: 3. ...

  2. Android 数据库 OrmLite Failed to open database

    04-01 16:49:32.720: E/SQLiteLog(1894): (14) cannot open file at line 30204 of [00bb9c9ce4]04-01 16:4 ...

  3. AudioManager 音量『转』

    获取系统音量 通过程序获取android系统手机的铃声和音量.同样,设置铃声和音量的方法也很简单! 设置音量的方法也很简单,AudioManager提供了方法: publicvoidsetStream ...

  4. oracle 之sys 、system区别

    角色 1)最重要的区别,存储的数据的重要性不同sys--所有oracle的数据字典的基表和视图都存放在sys用户中,这些基表和视图对于oracle的运行是至关重要的,由数据库自己维护,任何用户都不能手 ...

  5. strcmp()比较函数和strcasecmp()和strnatcmp()

    strcmp()的函数原型如下() int strcmp(string str1,string str2) 该函数需要两个进行比较的参数字符串,如果这两个字符串相等,该函数就返回0,如果按字典顺序st ...

  6. HDOJ 1097 A hard puzzle

    Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...

  7. java全栈day04--方法

    day04内容介绍 1  方法基础知识 2  方法高级内容 3  方法案例 一  方法的概念 A:为什么要有方法 提高代码的复用性 B   什么是方法 完成特定功能的代码块 修饰符  返回值类型  方 ...

  8. Picasso VS Glide

    原文: Introduction to Glide, Image Loader Library for Android, recommended by Google 在泰国举行的谷歌开发者论坛上,谷歌 ...

  9. android 应用间共享数据,调用其他app数据资源

    在Android里面每个app都有一个唯一的linux user ID,则这样权限就被设置成该应用程序的文件只对该用户可见,只对该应用程序自身可见:而我们可以使他们对其他的应用程序可见,可以通过Sha ...

  10. 基于jQuery的Tooltip

    近来,要开发一个关务管理系统,为了增加系统美观度,自己开发了一个基于jQuery框的的小插件,与大家分享一下,希望大家能给我提出宝贵修改意见. 下面开发说明使用方法和内容: 一.引用jQuery框架, ...