centos7 搭建nginx伺服器
阿新 • • 發佈:2019-01-07
下載ffmpeg推流工具
http://www.ffmpeg.org/download.html
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
zlib、PCRE、OpenSSL
Nginx、rtmp、openssl
nginx下載地址
http://nginx.org/en/download.html
下載版本
http://nginx.org/download/nginx-1.12.2.tar.gz
下載命令
wget http://nginx.org/download/nginx-1.12.2.tar.gz
openssl下載網頁
https://www.openssl.org/source/
下載地址
https://www.openssl.org/source/openssl-1.0.2n.tar.gz
下載命令
wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
rtmp地址
https://github.com/arut/nginx-rtmp-module
下載地址
wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.tar.gz
解壓檔案
tar -xzf OpenSSL_1_1_0g.tar.gz
編譯openssl
找到openssl資料夾下config檔案;指定生成檔案目錄,為當前目錄下bin資料夾下,生成Makefile
./config —prefix=`pwd`/bin
編譯Makefile
make install
編譯openssl得到 libcrypto.so 和 libsso.so
https://github.com/arut/nginx-rtmp-module
編譯nginx
#編譯nginx-rtmp-module
#./configure —add-module=/path/to/nginx-rtmp-module 官方預設編譯地址
#我的環境編譯地址 ,生成makefile檔案
#./configure —prefix=`pwd`/xieyuhai —add-module=/Users/xieyuhai/Documents/DN/nginx/nginx-rtmp-module-1.2.1
第二次編譯centos7
./configure --prefix=`pwd`/xieyuhai --add-module=//root/newnginx/nginx-rtmp-module-1.2.0
——————————————————在/Users/xieyuhai/Documents/DN/nginx/nginx-1.12.2/auto/lib/openssl/config檔案中新增下面指令碼,相關地址酌情修改
if [ $ngx_found = no ]; then
# 自定義Mac路徑
ngx_feature="OpenSSL library in /opt/local/"
#標頭檔案路徑
ngx_feature_path="/Users/xieyuhai/Documents/DN/nginx/openssl-1.0.2n/xieyuhai/include"
#標頭檔案路徑
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/Users/xieyuhai/Documents/DN/nginx/openssl-1.0.2n/xieyuhai/lib -L/Users/xieyuhai/Documents/DN/nginx/openssl-1.0.2n/bin/lib -lssl -lcrypto $NGX_LIBDL"
else
ngx_feature_libs="-L/Users/xieyuhai/Documents/DN/nginx/openssl-1.0.2n/xieyuhai/lib -lssl -lcrypto $NGX_LIBDL"
fi
. auto/feature
fi
在nginx-1.12.2目錄下,重新編譯,生成Makefile
1、沒有狀態
./configure —prefix=`pwd`/xieyuhai —add-module=/Users/xieyuhai/Documents/DN/nginx/nginx-rtmp-module-1.2.1
2、添加了狀態
./configure --prefix=`pwd`/xieyuhai --add-module=/root/nginx/nginx-rtmp-module-1.2.1 --with-http_stub_status_module
3、生成makefile後執行
make install
問題一、
安裝Nginx時報錯
./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel
問題二、
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.
安裝openssl-devel解決問題
yum -y install openssl openssl-devel
執行Makefile
make install
執行成功會在當前目錄生成xieyuhai資料夾
在這個目錄下有一個nginx可執行檔案
/root/nginx/nginx-1.12.2/xieyuhai/sbin/
在/etc/ld.so.conf檔案中新增nginx生成的目錄
#/root/nginx/nginx-1.12.2/xieyuhai
/root/newnginx/openssl-OpenSSL_1_1_0f/bin/lib
呼叫ldconfig命令,是上一步修改生效
啟動nginx,
執行./nginx
停止nginx
./nginx -s stop
/root/nginx/nginx-1.12.2/xieyuhai/sbin
解決端口占用
sudo fuser -k 80 / tcp
開啟nginx
./nginx
配置阿里雲安全組
新增埠1935
將/root/newnginx/nginx-rtmp-module-1.2.0/test 目錄下的nginx.conf 拷貝到nginx-1.12.2/xieyuhai/conf/目錄下
cp nginx.conf /root/newnginx/nginx-1.12.2/xieyuhai/conf/
使用ffmpeg模擬推流
ffmpeg -re -i /Users/xieyuhai/Downloads/3d.mp4 -f flv rtmp://47.94.215.45/myapp/mystream
http://czmmiao.iteye.com/blog/1733722
建立檔案,並編譯
vim /etc/init.d/nginx
授權
chmod 755 /etc/init.d/nginx
chkconfig /etc/init.d/nginx
問題
nginx: [warn] 1024 worker_connections exceed open file resource limit: 256
ulimit -a,顯示如下,將紅色字的變數改為1024即可,使用命令ulimit -u 1024。
檢視程序號
ps -ef|grep nginx
殺死程序
kill -QUIT 2072
強制停止
pkill -9 nginx
測試是否成功
./nginx -t
重啟
./nginx -s reload
重啟nginx服務
kill -HUP 程序號
檢視nginx配置檔案目錄
nginx -t
新增狀態開啟
location /ngx_status{
stub_status on;
access_log off;
#allow 127.0.0.1;
#deny all;
}
配置完成後的nginx.conf檔案
worker_processes 5;
user root;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
application myapp {
live on;
#record keyframes;
#record_path /tmp;
#record_max_size 128K;
#record_interval 30s;
#record_suffix .this.is.flv;
#on_publish http://localhost:8080/publish;
#on_play http://localhost:8080/play;
#on_record_done http://localhost:8080/record_done;
}
}
}
http {
server {
listen 8089;
fastcgi_intercept_errors on;
#location / {
# root html;
# index index.html index.htm;
#}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# root /root/nginx/nginx-1.12.2/html;
root /root/nginx/nginx-rtmp-module-1.2.1;
#stat stat.xsl;
}
location /control {
rtmp_control all;
}
#location /publish {
# return 201;
#}
#location /play {
# return 202;
#}
#location /record_done {
# return 203;
#}
location /rtmp-publisher {
root /root/nginx/nginx-rtmp-module-1.2.1/test;
}
location / {
root /root/nginx/nginx-rtmp-module-1.2.1/test/www;
index index.html record.html;
}
#location /record {
# root /root/nginx/nginx-rtmp-module-1.2.1/test/www;
# record record.html;
#}
location /ngx_status{
stub_status on;
access_log off;
#allow 127.0.0.1;
#deny all;
}
}
}
http://www.ffmpeg.org/download.html
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
zlib、PCRE、OpenSSL
Nginx、rtmp、openssl
nginx下載地址
http://nginx.org/en/download.html
下載版本
http://nginx.org/download/nginx-1.12.2.tar.gz
下載命令
wget http://nginx.org/download/nginx-1.12.2.tar.gz
openssl下載網頁
https://www.openssl.org/source/
下載地址
https://www.openssl.org/source/openssl-1.0.2n.tar.gz
下載命令
wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
rtmp地址
https://github.com/arut/nginx-rtmp-module
下載地址
wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.tar.gz
解壓檔案
tar -xzf OpenSSL_1_1_0g.tar.gz
編譯openssl
找到openssl資料夾下config檔案;指定生成檔案目錄,為當前目錄下bin資料夾下,生成Makefile
./config —prefix=`pwd`/bin
編譯Makefile
make install
編譯openssl得到 libcrypto.so 和 libsso.so
https://github.com/arut/nginx-rtmp-module
編譯nginx
#編譯nginx-rtmp-module
#./configure —add-module=/path/to/nginx-rtmp-module 官方預設編譯地址
#我的環境編譯地址 ,生成makefile檔案
#./configure —prefix=`pwd`/xieyuhai —add-module=/Users/xieyuhai/Documents/DN/nginx/nginx-rtmp-module-1.2.1
第二次編譯centos7
./configure --prefix=`pwd`/xieyuhai --add-module=//root/newnginx/nginx-rtmp-module-1.2.0
——————————————————在/Users/xieyuhai/Documents/DN/nginx/nginx-1.12.2/auto/lib/openssl/config檔案中新增下面指令碼,相關地址酌情修改
if [ $ngx_found = no ]; then
# 自定義Mac路徑
ngx_feature="OpenSSL library in /opt/local/"
#標頭檔案路徑
ngx_feature_path="/Users/xieyuhai/Documents/DN/nginx/openssl-1.0.2n/xieyuhai/include"
#標頭檔案路徑
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/Users/xieyuhai/Documents/DN/nginx/openssl-1.0.2n/xieyuhai/lib -L/Users/xieyuhai/Documents/DN/nginx/openssl-1.0.2n/bin/lib -lssl -lcrypto $NGX_LIBDL"
else
ngx_feature_libs="-L/Users/xieyuhai/Documents/DN/nginx/openssl-1.0.2n/xieyuhai/lib -lssl -lcrypto $NGX_LIBDL"
fi
. auto/feature
fi
在nginx-1.12.2目錄下,重新編譯,生成Makefile
1、沒有狀態
./configure —prefix=`pwd`/xieyuhai —add-module=/Users/xieyuhai/Documents/DN/nginx/nginx-rtmp-module-1.2.1
2、添加了狀態
./configure --prefix=`pwd`/xieyuhai --add-module=/root/nginx/nginx-rtmp-module-1.2.1 --with-http_stub_status_module
3、生成makefile後執行
make install
問題一、
安裝Nginx時報錯
./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問題
yum -y install pcre-devel
問題二、
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.
安裝openssl-devel解決問題
yum -y install openssl openssl-devel
執行Makefile
make install
執行成功會在當前目錄生成xieyuhai資料夾
在這個目錄下有一個nginx可執行檔案
/root/nginx/nginx-1.12.2/xieyuhai/sbin/
在/etc/ld.so.conf檔案中新增nginx生成的目錄
#/root/nginx/nginx-1.12.2/xieyuhai
/root/newnginx/openssl-OpenSSL_1_1_0f/bin/lib
呼叫ldconfig命令,是上一步修改生效
啟動nginx,
執行./nginx
停止nginx
./nginx -s stop
/root/nginx/nginx-1.12.2/xieyuhai/sbin
解決端口占用
sudo fuser -k 80 / tcp
開啟nginx
./nginx
配置阿里雲安全組
新增埠1935
將/root/newnginx/nginx-rtmp-module-1.2.0/test 目錄下的nginx.conf 拷貝到nginx-1.12.2/xieyuhai/conf/目錄下
cp nginx.conf /root/newnginx/nginx-1.12.2/xieyuhai/conf/
使用ffmpeg模擬推流
ffmpeg -re -i /Users/xieyuhai/Downloads/3d.mp4 -f flv rtmp://47.94.215.45/myapp/mystream
http://czmmiao.iteye.com/blog/1733722
建立檔案,並編譯
vim /etc/init.d/nginx
授權
chmod 755 /etc/init.d/nginx
chkconfig /etc/init.d/nginx
問題
nginx: [warn] 1024 worker_connections exceed open file resource limit: 256
ulimit -a,顯示如下,將紅色字的變數改為1024即可,使用命令ulimit -u 1024。
檢視程序號
ps -ef|grep nginx
殺死程序
kill -QUIT 2072
強制停止
pkill -9 nginx
測試是否成功
./nginx -t
重啟
./nginx -s reload
重啟nginx服務
kill -HUP 程序號
檢視nginx配置檔案目錄
nginx -t
新增狀態開啟
location /ngx_status{
stub_status on;
access_log off;
#allow 127.0.0.1;
#deny all;
}
配置完成後的nginx.conf檔案
worker_processes 5;
user root;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
application myapp {
live on;
#record keyframes;
#record_path /tmp;
#record_max_size 128K;
#record_interval 30s;
#record_suffix .this.is.flv;
#on_publish http://localhost:8080/publish;
#on_play http://localhost:8080/play;
#on_record_done http://localhost:8080/record_done;
}
}
}
http {
server {
listen 8089;
fastcgi_intercept_errors on;
#location / {
# root html;
# index index.html index.htm;
#}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# root /root/nginx/nginx-1.12.2/html;
root /root/nginx/nginx-rtmp-module-1.2.1;
#stat stat.xsl;
}
location /control {
rtmp_control all;
}
#location /publish {
# return 201;
#}
#location /play {
# return 202;
#}
#location /record_done {
# return 203;
#}
location /rtmp-publisher {
root /root/nginx/nginx-rtmp-module-1.2.1/test;
}
location / {
root /root/nginx/nginx-rtmp-module-1.2.1/test/www;
index index.html record.html;
}
#location /record {
# root /root/nginx/nginx-rtmp-module-1.2.1/test/www;
# record record.html;
#}
location /ngx_status{
stub_status on;
access_log off;
#allow 127.0.0.1;
#deny all;
}
}
}