nginx 搭建 rtmp 服務器

搭建nginx + nginx-rtmp-module
演示的系統使用CentOS-7-x86_64-Everything-1611.iso

關閉防火牆

請根據實際情況調整防火牆。爲了演示方便,博主關閉防火牆。
臨時停止

systemctl stop firewalld

禁用

systemctl disable firewalld

查看狀態

systemctl status firewalld

安裝wget

yum -y install wget

安裝 gcc gcc-c++

yum -y install gcc gcc-c++

安裝PCRE庫

cd /usr/local/
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
tar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make && make install

安裝openssl

cd /usr/local/ 
wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz 
tar -zxvf openssl-1.0.1j.tar.gz 
cd openssl-1.0.1j
./config
make && make install

nginxrtmp2.jpg
如果提示You need Perl 5,則輸入下面這個命令。

yum -y install Perl 5

安裝zlib

cd /usr/local/
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
./configure
make && make install

git clone

cd /usr/local/
yum -y install git
git clone https://github.com/arut/nginx-rtmp-module.git 

安裝nginx

cd /usr/local/
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/src/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module  --add-module=../nginx-rtmp-module  --with-openssl=<path> --with-http_ssl_module
make && make install 

如果提示

./configure: error: SSL modules require the OpenSSL library.

執行

yum -y install openssl openssl-devel

如果提示

 ./configure: error: the HTTP rewrite module requires the PCRE library.

執行

yum -y install pcre-devel

我下載並安裝了pcre-8.33.tar.gz 和 openssl-1.0.1j.tar.gz ,並沒有出現上面的錯誤

nginx相關命令

啓動

/usr/local/src/nginx/sbin/nginx

重啓

/usr/local/src/nginx/sbin/nginx –s reload

啓動後,打開瀏覽器,輸入服務器ip地址,訪問顯示如下頁面,則表示成功安裝。
nginxrtmp3.jpg

修改conf

nginxrtmp4.jpg
使用 winscp 前往/usr/local/src/nginx/conf/nginx.conf
在 http{ 前加入

rtmp {
    server {
        listen 1935; #監聽的端口
        chunk_size 4000; #上傳文件塊的大小

        application yuchen { #創建一個名爲 yuchen 的應用
            live on; #開啓實時
            #allow publish 127.0.0.1;
            #allow play all;
            hls on; #開啓hls
            hls_path /usr/local/nginx/html/yuchen; #rtmp推流請求路徑,文件存放路徑 (切記路徑錯了會推不上流)
            hls_fragment 5s; #每個TS文件包含5秒的視頻內容
        }
   }
}

修改完成後,使用命令重啓nginx

/usr/local/src/nginx/sbin/nginx –s reload

推拉流

打開obs推流,右下角變爲綠色方塊則推流成功。
nginxrtmp5.jpg

在potplayer中播放http的m3u8地址。或者是使用支持rtmp協議的播放器拉流。(打開軟件後右鍵,打開,打開鏈接,輸入地址)

 

轉自:https://blog.tomhuang2000.com/archives/572/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章