nginx 搭建rtmp流媒体服务器

来源:互联网 发布:如何开个淘宝店铺 编辑:程序博客网 时间:2024/05/19 17:25

本文是搭建nginx流媒体服务器过程的笔记,方便自己或者有相关需求的人员参考。

注明:

主机系统:ubuntu16.04

测试主机IP:192.168.0.5

1. 下载PCRE 并安装. 

     主页地址: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

     该下载有点问题,这里是我已经下载好的一个文件:pcre-8.37.tar.gz

2.  解压 tar -xzvf pcre-8.37.tar.gz

     cd pcre-8.37

     ./configure

     make

     make install (if not the root user, please use the sudo)

3.  下载nginx 和 nginx rtmp 模块

     http://nginx.org/download/nginx-1.10.0.tar.gz  

     csdn资源下载:nginx-1.2.0.tar.gz

     解压 tar -zxvf nginx-1.10.0.tar.gz

     https://github.com/arut/nginx-rtmp-module

     执行nginx 编译配置

      ./configure --add-module=/path/to/nginx-rtmp-module
      make
      make install

4.   启动nginx

      sbin 目录下nginx 服务器主程序, 启动 sudo ./nginx

5.   查看

licaibiao@lcb:/usr/local/nginx/sbin$  ps -ef | grep nginx       
root      1566     1  0 17:39 ?        00:00:00 nginx: master process ./nginx
nobody    1601  1566  0 17:42 ?        00:00:00 nginx: worker process
licaibi+  1643  1314  0 18:20 pts/8    00:00:00 grep --color=auto nginx
licaibiao@lcb:/usr/local/nginx/sbin$ 
licaibiao@lcb:/usr/local/nginx/sbin$ 


6.  在浏览器中输入http://localhost/  (192.168.0.5)  , 可以看到nginx 的首页



7. 添加rtmp 支持

       sudo vi conf/nginx.conf

rtmp {
     server {
         listen 1935;
         application live {
             live on;
             record off;
         }
     }
 }

8, 重启 nginx

     sudo ./sbin/nginx -t

     sudo ./sbin/nginx -s reload

9. 添加测试源, 推流到服务器

    ffmpeg -re -i cuc_ieschool.mp4 -c copy -f flv rtmp://192.168.0.5:1935/live


10. 使用vlc在局域网机器上打开rtmp测试流

      rtmp://192.168.0.5:1935/live



    运行时如果出现错误:nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use),表示nginx已经在运行,可以使用下面命令来关闭该端口的连接

    sudo fuser -k 80/tcp


0 0