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
posted @ 2020-08-07 13:35  燕马越空  阅读(1744)  评论(0编辑  收藏  举报