SRS流媒體服務器安裝


一、安裝工具包

1、安裝wget下載文件

yum -y install wget

2、安裝 unzip

yum install -y unzip zip

二、安裝SRS

下載srs

#wget http://ossrs.net/srs.release/releases/files/SRS-CentOS6-x86_64-2.0.263.zip
wget http://ossrs.net/srs.release/releases/files/SRS-CentOS7-x86_64-3.0.139.zip

解壓srs

#unzip SRS-CentOS6-x86_64-2.0.263.zip
unzip SRS-CentOS7-x86_64-3.0.139.zip

進入解壓目錄

#cd SRS-CentOS6-x86_64-2.0.263
cd SRS-CentOS7-x86_64-3.0.139

執行安裝,如果出現No package lsb_release available. 的錯誤提示(centos 7上容易出現這個錯誤),可嘗試先安裝

yum install -y redhat-lsb

sudo ./INSTALL

啟動

sudo /etc/init.d/srs start

停止

sudo /etc/init.d/srs stop

從新初始化

sudo /etc/init.d/srs reload

srs.config 配置

vim /usr/local/srs/conf/srs.conf
# http-flv設置
http_remux{
    enabled    on;
    mount      [vhost]/[app]/[stream].flv;
    hstrs      on;
}

# hls設置
hls{
    enabled       on;
    hls_path      ./objs/nginx/html;
    hls_fragment  10;
    hls_window    60;
}

​ 關閉防火牆

systemctl stop firewalld.service
systemctl disable firewalld.service

firewall-cmd --state

用ffmpeg 推流,window cmd

ffmpeg -re -i source.200kbps.768x320.flv -vcodec copy -acodec copy -f flv -y rtmp://192.168.66.30:1935/live/lives0001

http://192.168.66.30:8080/live/lives0001.flv

​ web播放m3u8,http-flv時,如果h5頁面與.m3u8的視頻源不在同一個域名,瀏覽器會遇到跨域問題。網上有一種解決辦法,是修改srs的源碼,增加Access-Control-Alow-Orogin:*,但個人不推薦這種做法,一來把安全性降低了,容易造成盜播等安全問題。二是如果官網以后fix bug了,自己又得改一次。
更好的辦法,是在srs前面放一個nginx,做轉發來解決跨域問題。通常h5頁面,是通過nginx來訪問的,可以在nginx里,把特定視頻源路徑,轉發到后端srs服務器上,nginx參考以下配置:

location /srs/ {
    proxy_pass http://srs服務IP:端口/;
    add_header Cache-Control no-cache;
    add_header Access-Control-Allow-Origin *;
}

SRS 3.0以后應該沒有這個問題了,不用下面 安裝Nginx了。

三、CentOS 7 下安裝 Nginx

(一)安裝所需環境

Nginx 是 C語言 開發,建議在 Linux 上運行,當然,也可以安裝 Windows 版本,本篇則使用 CentOS 7 作為安裝環境。

1、gcc 安裝
安裝 nginx 需要先將官網下載的源碼進行編譯,編譯依賴 gcc 環境,如果沒有 gcc 環境,則需要安裝:

yum install gcc-c++

2、PCRE pcre-devel 安裝
PCRE(Perl Compatible Regular Expressions) 是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,所以需要在 linux 上安裝 pcre 庫,pcre-devel 是使用 pcre 開發的一個二次開發庫。nginx也需要此庫。命令:

yum install -y pcre pcre-devel

3、zlib 安裝
zlib 庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,所以需要在 Centos 上安裝 zlib 庫。

yum install -y zlib zlib-devel

4、OpenSSL 安裝
OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及 SSL 協議,並提供豐富的應用程序供測試或其它目的使用。
nginx 不僅支持 http 協議,還支持 https(即在ssl協議上傳輸http),所以需要在 Centos 安裝 OpenSSL 庫。

yum install -y openssl openssl-devel

5、官網下載nginx

直接下載.tar.gz安裝包,地址:https://nginx.org/en/download.html

wget -c https://nginx.org/download/nginx-1.18.0.tar.gz

6、解壓

tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0

7、配置
1)使用默認配置

./configure

默認設置的路徑如下:

​ nginx path prefix: "/usr/local/nginx"
​ nginx binary file: "/usr/local/nginx/sbin/nginx"
​ nginx modules path: "/usr/local/nginx/modules"
​ nginx configuration prefix: "/usr/local/nginx/conf"
​ nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
​ nginx pid file: "/usr/local/nginx/logs/nginx.pid"
​ nginx error log file: "/usr/local/nginx/logs/error.log"
​ nginx http access log file: "/usr/local/nginx/logs/access.log"
​ nginx http client request body temporary files: "client_body_temp"
​ nginx http proxy temporary files: "proxy_temp"
​ nginx http fastcgi temporary files: "fastcgi_temp"
​ nginx http uwsgi temporary files: "uwsgi_temp"
​ nginx http scgi temporary files: "scgi_temp"

2)自定義配置(不推薦)

./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

注:將臨時文件目錄指定為/var/temp/nginx,需要在/var下創建temp及nginx目錄

8、編譯安裝

make
make install

​ 查找安裝路徑:

whereis nginx

9、啟動、停止nginx

cd /usr/local/nginx/sbin/
./nginx 
./nginx -s stop
./nginx -s quit
./nginx -s reload

​ 啟動時報80端口被占用:

​ nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

​ 修改配置文件

cd /usr/local/nginx/conf
vim nginx.conf


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM