openresty +rtmp 搭建視頻直播服務器

最近搭建了一個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涮印!

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末怠堪,一起剝皮案震驚了整個濱河市揽乱,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌粟矿,老刑警劉巖凰棉,帶你破解...
    沈念sama閱讀 222,627評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異陌粹,居然都是意外死亡撒犀,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,180評論 3 399
  • 文/潘曉璐 我一進店門掏秩,熙熙樓的掌柜王于貴愁眉苦臉地迎上來或舞,“玉大人,你說我怎么就攤上這事蒙幻∮车剩” “怎么了?”我有些...
    開封第一講書人閱讀 169,346評論 0 362
  • 文/不壞的土叔 我叫張陵邮破,是天一觀的道長诈豌。 經(jīng)常有香客問我,道長决乎,這世上最難降的妖魔是什么队询? 我笑而不...
    開封第一講書人閱讀 60,097評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮构诚,結果婚禮上,老公的妹妹穿的比我還像新娘铆惑。我一直安慰自己范嘱,他們只是感情好送膳,可當我...
    茶點故事閱讀 69,100評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著丑蛤,像睡著了一般叠聋。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上受裹,一...
    開封第一講書人閱讀 52,696評論 1 312
  • 那天碌补,我揣著相機與錄音,去河邊找鬼棉饶。 笑死厦章,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的照藻。 我是一名探鬼主播袜啃,決...
    沈念sama閱讀 41,165評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼幸缕!你這毒婦竟也來了群发?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 40,108評論 0 277
  • 序言:老撾萬榮一對情侶失蹤发乔,失蹤者是張志新(化名)和其女友劉穎熟妓,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體栏尚,經(jīng)...
    沈念sama閱讀 46,646評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡滑蚯,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,709評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了抵栈。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片告材。...
    茶點故事閱讀 40,861評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖古劲,靈堂內(nèi)的尸體忽然破棺而出斥赋,到底是詐尸還是另有隱情,我是刑警寧澤产艾,帶...
    沈念sama閱讀 36,527評論 5 351
  • 正文 年R本政府宣布疤剑,位于F島的核電站,受9級特大地震影響闷堡,放射性物質(zhì)發(fā)生泄漏隘膘。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,196評論 3 336
  • 文/蒙蒙 一杠览、第九天 我趴在偏房一處隱蔽的房頂上張望弯菊。 院中可真熱鬧,春花似錦踱阿、人聲如沸管钳。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,698評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽才漆。三九已至牛曹,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間醇滥,已是汗流浹背黎比。 一陣腳步聲響...
    開封第一講書人閱讀 33,804評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留鸳玩,地道東北人阅虫。 一個月前我還...
    沈念sama閱讀 49,287評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像怀喉,于是被迫代替她去往敵國和親书妻。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,860評論 2 361

推薦閱讀更多精彩內(nèi)容