[CentOS7] nginx rtmp 伺服器架設

前陣子在玩貴參參的 wirecast 測試版. 就想要自己架設串流伺服器. 後來意外發現 rtmp 架設蠻容易的 但還是記錄一下.

先下載 nginx 原始碼 自行編譯. 其實我蠻想要找 yum or rpm 安裝 可惜好像沒有辦法這樣就直接安裝好包含 rtmp 模組. 我是到 http://nginx.org/packages/mainline/centos/7/SRPMS/ 下載 rpm 然後把 nginx-1.11.5.tar.gz 取出來用

# rpm -ivh http://nginx.org/packages/mainline/centos/7/SRPMS/nginx-1.11.5-1.el7.ngx.src.rpm
# cd /usr/local/src
# tar zxvf ~/rpmbuild/SOURCES/nginx-1.11.5.tar.gz

然後再用 git 把 nginx-rtmp-module 抓回來

# git clone https://github.com/arut/nginx-rtmp-module.git

還要額外安裝 下列套件

# yum install pcre-devel openssl-devel -y

之後就可以準備 組態及編譯

# cd nginx-1.11.5
# ./configure –with-http_ssl_module –add-module=/usr/local/src/nginx-rtmp-module
# make
# make install

在 /usr/local/nginx/conf/nginx.conf 最後一行, 設定一下 rtmp

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

record off;
# publish only from localhost
allow publish xxx.xxx.xxx.xxx;
deny publish all;

allow play all;
}
}
}

基本上這樣就完成基本安裝了 啟動 nginx rtmp 伺服器

# systemctl start nginx

複製 nginx.service 到對的位置

# cp ~/rpmbuild/SOURCES/nginx.service /usr/lib/systemd/system/nginx.service

然後編輯 /usr/lib/systemd/system/nginx.service 檔案 更改pid & 執行檔路徑

# PIDFile=/run/nginx.pid
PIDFile=/usr/local/nginx/logs/nginx.pid
# ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
# ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

最後啟動 nginx

# systemctl start nginx

收工

Leave a Reply

Your email address will not be published. Required fields are marked *