最近搭建了一個rtmp直播服務器, 因為nginx的rtmp服務器本身需要一些http的控制辞色, 所以選用了openresty這個nginx+lua的http框架, 再其中包含rtmp服務器, 這樣既可以充當rtmp直播服務器靠粪,也可以充當http震桶,還可以直接在其中用lua腳本完成相關控制休傍!
現(xiàn)具體說明:
系統(tǒng)環(huán)境:linux centos6.5
環(huán)境附屬安裝:
yum install gcc
yum install pcre-devel
yum install openssl-devel
yum install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev
yum install libxml2 libxml2-devel libxslt libxslt-devel
yum install perl? perl-devel perl-ExtUtils-Embed
openresty 下載地址: https://openresty.org/en/download.html
里面有widnows, linux各種版本蹲姐, 選取好自己所用的版本尊残, 本博客用的是linux最新的版本
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
tar xzvf openresty-1.13.6.2.tar.gz
cd openresty-1.13.6.2/bundle/LuaJIT-2.1-20180420
make && make install
ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit
以上是單獨安裝luajit,這是以前的版本安裝方法淤堵, 現(xiàn)在最新的版本安裝luajit已經(jīng)合并到./configure里面自動編譯寝衫, 以上的步驟可以跳過, 不過我喜歡按這個方法來拐邪, 如果出現(xiàn)問題可以很好的知道哪出現(xiàn)問題慰毅,純屬個人喜好。
? 在budlle目錄下執(zhí)行
? wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
? tar xzvf 2.3.tar.gz
? wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz
? tar xzvf v0.3.0.tar.gz
nginx rtmp module? 下載最新的版本? 地址:? https://github.com/arut/nginx-rtmp-module
解壓到該目錄
到現(xiàn)在扎阶,準備工作已經(jīng)完成汹胃, 現(xiàn)可以編譯
cd openresty-1.13.6.2
./configure --prefix=/opt/openresty --with-luajit --with-http_ssl_module --user=root --group=root --with-http_realip_module --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ --add-module=./bundle/nginx-rtmp-module-master **--with-cc-opt="-I/usr/local/ssl/include" --with-ld-opt="-L/usr/local/ssl/lib"**? --with-http_xslt_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_perl_module --with-mail
說明 加粗的這段是因為執(zhí)行./configure時, 一直找不到本機的openssl庫东臀, 所以手動添加該庫的地址着饥, 所包含的參數(shù)具體都是干什么用的, 請自行百度谷歌惰赋。
如果出現(xiàn) :bin/sh^M: bad interpreter: No such file or directory? 或者 : No such file or directory
則 vim configure? ? 使用命令 :set ff? 來查看文件是dos還是unix
如果是dos? 則? :set ff=unix完成之后保存就解決問題了?
make && make install
就安裝完成了宰掉,
現(xiàn)貼出所使用的conf配置, 一些常用的功能都已經(jīng)添加赁濒, 在需要別的功能的時候轨奄, 我會更新本博客
=================nginx.conf=====================================================
user? root;
worker_processes? 1;
#daemon off;
#error_log? logs/error.log;
#error_log? logs/error.log? notice;
#error_log? logs/error.log? info;
#pid? ? ? ? logs/nginx.pid;
events {
? ? worker_connections? 1024;
}
rtmp {
#設置rtmp的日志記錄, 該記錄只有在直播流結束后過顯示在日志里拒炎, 不能connect的階段記錄挪拟, 該問題暫未解決
log_format rtmp_main '$remote_addr [$time_local] $command "$app" "$name" "$args"? '
'$bytes_received $bytes_sent "$pageurl" "$flashver" ($session_readable_time) $connection $session_time ';
access_log logs/rtmp_access.log rtmp_main;
? ? ? ? server{
? ? ? ? listen 1935;
? ? ack_window 5000;#窗口大小
? ? chunk_size 1024;
? ? ? ? application live {
? ? ? ? ? ? live on;
? ? ? ? ? ? wait_key on;
? ? ? ? ? ? drop_idle_publisher 10s;
? ? ? ? ? ? wait_video on;
? ? interleave on;
sync 10ms;
? ? ? ? }
? ? }
}
http {
? ? include? ? ? mime.types;
? ? default_type? application/octet-stream;
? ? log_format? main? '$remote_addr - $remote_user [$time_local] "$request" '
? ? ? ? ? ? ? ? ? ? ? '$status $body_bytes_sent "$http_referer" '
? ? ? ? ? ? ? ? ? ? ? '"$http_user_agent" "$http_x_forwarded_for"';
? ? access_log? logs/access.log? main;
? ? sendfile? ? ? ? on;
? ? #tcp_nopush? ? on;
? ? #keepalive_timeout? 0;
? ? keepalive_timeout? 65;
? ? #gzip? on;
? ? server {
? ? ? ? listen? ? ? 80;
? ? ? ? server_name? localhost;
? ? ? ? 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;#將stat.xsl文件放置到安裝目錄里的html文件夾中
? ? ? ? }
? ? ? ? location /stat.xsl {
? ? ? ? ? ? root html;
? ? ? ? }
location /nclients {?
proxy_pass http://127.0.0.1/stat;? #將nclients.xsl文件放置到安裝目錄里的html文件夾中, nclients.xsl具體內(nèi)容在下面
xslt_stylesheet html/nclients.xsl app='$arg_app' name='$arg_name';?
add_header Refresh "3; $request_uri";?
}
location /test{
content_by_lua_file conf/lua/test.lua;#測試lua執(zhí)行的helloworld
} ?
location /control{
rtmp_control all;#rtmp的http控制api生效
}
? ? }
}
-------------nclients.xsl-----------------------------------------------------------------------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">?
<xsl:output method="html"/>?
<xsl:param name="app"/>?
<xsl:param name="name"/>?
<xsl:template match="/">?
? ? <xsl:value-of select="count(//application[name=$app]/live/stream[name=$name]/client[not(publishing) and flashver])"/>?
</xsl:template>?
</xsl:stylesheet>?
以上就可以啟動nginx击你, 生效我們自己的rtmp服務器玉组!
如果覺得有用谎柄, 請關注我的博客!9喏ā9仁摹!
做專注最接地氣流媒體相關內(nèi)容6执铡:赐帷!鸵钝!
我以后也會盡可能糙臼,盡自己最大水平持續(xù)更新!6魃獭1涮印!