centos7+nginx+rtmp+ffmpeg搭建流媒体服务器

1.安装前需要的工具

#net-tool 查本地IP
#wget 下载安装包
#unzip 解压zip包
#gcc gcc-c++ perl 编译软件包用
yum install -y net-tools wget unzip gcc gcc-c++ perl

2. 将Centos的yum源更换为国内的阿里云源

#备份yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 
#下载阿里源 
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
#清空缓存 
yum makecache

3. 安装nginx及rtmp

#切换的homme目录
cd /home
下载并解压pcre
#下载pcre包
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
#解压pcre包
tar -zxvf pcre-8.41.tar.gz
下载并解压zlib
#下载zlib包
wget http://www.zlib.net/zlib-1.2.11.tar.gz
#解压zlib包
tar -zxvf zlib-1.2.11.tar.gz
下载并安装openssl
#下载openssl包 
wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1i.tar.gz 
#解压openssl包 
tar -zxvf openssl-1.0.1i.tar.gz 
#切换到openssl里 
cd openssl-1.0.1i 
#生成配置文件 默认配置 
./config
#编译程序 
make 
#安装程序 
make install
下载并解压nginx-rtmp-model
#下载rtmp包
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
#解压下载包
unzip -o master.zip
#修改文件夹名
mv master nginx-rtmp-module
安装nginx
#下载
nginx wget http://nginx.org/download/nginx-1.12.2.tar.gz 
#解压
nignx tar -zxvf nginx-1.12.2.tar.gz 
#切换到nginx中 
cd nginx-1.12.2 
#生成配置文件,将上述下载的文件配置到configure中 
./configure --prefix=/usr/local/nginx --with-pcre=/home/pcre-8.41 --with-zlib=/home/zlib-1.2.11 --with-openssl=/home/openssl-1.0.1i --add-module=/home/nginx-rtmp-module 
#编译程序 
make 
#安装程序 
make install 
#查看nginx模块 
nginx -V

安装ffmpeg

#安装epel包
yum install -y epel-release 
#导入签名 
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 
#导入签名 
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro 
#升级软件包 
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm 
#更新软件包 
yum update -y 
#安装ffmpeg 
yum install -y ffmpeg 
#检查版本 
ffmpeg -version

4. 修改配置运行服务

修改nginx配置
vi /usr/local/nginx/conf/nginx.conf

修改之后的配置

#user nobody;
worker_processes 1;
#
##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{
server{
listen 1935;
application myapp{
live on;
}
application hls{
live on;
hls on;
hls_path /tmp/hls;
}
}
}
#
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;
#
sendfile on;
##tcp_nopush on;
#
##keepalive_timeout 0;
keepalive_timeout 65;
#
gzip on;
#include /usr/local/nginx/conf.d/*.conf;
server {
listen 80;
server_name localhost;
#
##charset koi8-r;
#
##access_log logs/host.access.log main;
#
location / {
root html;
index index.html index.htm;
}
location /hls {
types{
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
##error_page 404 /404.html;
#
## redirect server error pages to the static page /50x.html
##
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
#
## proxy the PHP scripts to Apache listening on 127.0.0.1:80
##
##location ~ \.php$ {
## proxy_pass http://127.0.0.1;
##}
#
## pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
##
##location ~ \.php$ {
## root html;
## fastcgi_pass 127.0.0.1:9000;
## fastcgi_index index.php;
## fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
## include fastcgi_params;
##}
#
## deny access to .htaccess files, if Apache's document root
## concurs with nginx's one
##
##location ~ /\.ht {
## deny all;
##}
#
#
## another virtual host using mix of IP-, name-, and port-based configurati
##error_page 404 /404.html;
#
## redirect server error pages to the static page /50x.html
##
执行nginx
/usr/local/nginx/sbin/nginx
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
测试功能
ffmpeg -re -i ychx.mp4 -vcodec copy -codec copy -f flv rtmp://192.168.199.145/hls/cctv
测试访问
视频切片保存位置:/tmp/hls/
m3u8视频访问地址:http://192.168.199.145/hls/cctv.m3u8

 重启nginx

/usr/local/nginx/sbin/nginx -s reload

 

转载于:https://www.cnblogs.com/alexliuzw/p/9792074.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值