編碼的世界 / 優質文選 / 感情

Centos7下利用nginx, nginx-rtmp-module搭建流媒體服務器


2022年5月17日
-   

1、下載開源庫
   nginx-1.15.7:  http://nginx.org/download/
   nginx-rtmp-module: 
                 # cd /home/lucongli/
                 # git clone git://github.com/arut/nginx-rtmp-module.git
   pcre-8.42:  https://sourceforge.net/projects/pcre/
   openssl-1.0.2q:  https://www.openssl.org/source/
2、解壓開源庫
    目標位置:/root
3、編譯nginx-1.15.7
# gedit /root/nginx-Install.sh  
#!/bin/bash echo "install nginx!"
cd /usr/local/ if [ -d "nginx" ]; then rm -rf nginx fi mkdir nginx
cd /root/nginx-1.15.7 chmod a+x configure ./configure with-pcre=/root/pcre-8.42 with-openssl=/root/openssl-1.0.2q add-module=/root/nginx-rtmp-module prefix=/usr/local/nginx
make -j 8 install chmod -R 777 /usr/local/nginx
保存後關閉
# cd /root
# chmod a+x nginx-Install.sh
# ./nginx-Install.sh
4、啟動nginx
# cd /usr/local/nginx/sbin
# ./nginx
5、查看nginx端口監聽情況
# netstat -ntlp

6、編輯nginx.conf讓其具有直播、點播、轉發rtmp流能力# gedit /usr/local/nginx/conf/nginx.conf
添加如下內容:
rtmp{      server{           listen 1935;         chunk_size 4096;
          application live{          live on;          }
          application vod{               play /usr/local/nginx/html/;              }             application remote{           live on;           pull rtmp://live.hkstv.hk.lxdns.com/live/hks;              }       } }
//重啟nginx
# kill 9702
# cd /usr/local/nginx/sbin
# ./nginx
# netstat -ntlp

7、測試
直播推流地址:rtmp://localhost/live/dahua.flv
        觀看地址:rtmp://localhost/live/dahua
點播觀看地址:rtmp://localhost/vod/friends
         //點播需要事先將friends.flv存放到目錄:/usr/local/nginx/html
遠程rtmp公測觀看地址:rtmp://localhost/remote

熱門文章