流媒体搭建

一、安装操作系统(Centos 74)

二、下载软件

yum install  -y  wget 

三、配置yum源

1、阿里云镜像站

https://developer.aliyun.com/mirror/

2、备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

CentOS7

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

四、上传安装扩展模块

Nginx本身只是一个服务器,对流媒体并没有支持,所以我们要下载对应的模块来扩展其功能。
MP4模块:http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
FLV模块:http://sourceforge.net/projects/yamdi/files/yamdi/yamdi-1.9.tar.gz
直播流模块:https://github.com/adwpc/nginx-rtmp-module
FastDFS模块:https://github.com/happyfish100/fastdfs-nginx-module

上传所有模块

mkdir /opt/nginx
cd /opt/nginx
rz nginx-1.8.1.tar.gz
rz nginx_mod_h264_streaming-2.2.7.tar.gz
rz yamdi-1.9.tar.gz
rz nginx-rtmp-module-master

安装依赖(c语言的环境)

yum install -y gcc-c++ zlib pcre openssl openssl-devel 

安装FLV模块

tar -zxvf  yamdi-1.9.tar.gz

cd yamdi

make && make install

解压MP4模块

tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz

mp4模块有个bug需要处理一下

cd /opt/nginx/nginx_mod_h264_streaming-2.7.7/src

vim ngx_http_streaming_module.c

注释157~161行(尾行模式set nu显示行数)

解压HLS模块

为方便先改个名字

mv nginx-rtmp-module-master_(1).zip  nginx-rtmp-module-master.zip

下载unzip(用来解压zip包)

yum install -y unzip

解压

unzip nginx-rtmp-module-master.zip 

解压nginx

unzip nginx-rtmp-module-master.zip 

安装nginx并添加模块

cd /opt/nginx/nginx-1.8.1

./configure --add-module=/opt/nginx/nginx_mod_h264_streaming-2.2.7 --add-module=/opt/nginx/nginx-rtmp-module-master  --with-http_ssl_module   --prefix=/opt/software/nginx   --with-http_flv_module  --with-http_stub_status_module

make && make install

如果编译报错

vim objs/Makefile

(修改objs/Makefile文件, 去掉其中的"-Werror"), 然后就能够正常编译了.

mp4播放配置

cd /opt/software/nginx/conf
vim nginx.conf

添加对FLV和MP4的支持

location ~ .flv {
            flv;
}
location
~ .mp4$ { mp4; }

上传MP4格式的文件

cd /opt/software/nginx/html/

rz 你的MP4文件

开启nginx服务

 cd /opt/software/nginx/sbin/

./nginx

可以在浏览器访问MP4了(输入:主机ip/MP4的名字)

原文地址:https://www.cnblogs.com/yangy1/p/12469289.html