百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

技术分享|如何搭建直播场景下的推拉流媒体服务器

nanshan 2024-12-06 17:58 24 浏览 0 评论

介绍

本文使用的流媒体服务器的搭建是基于rtmp(Real Time Message Protocol)协议的,rtmp协议是应用层的协议,要依靠底层的传输层协议,比如tcp协议来保证信息传输的可靠性。

相关服务: Nginx、srs、MediaServer等三种推流服务

系统: CentOS Linux release 7.9.2009

推流工具:OBS 27.1.3

拉流工具:PotPlayer 1.7.21564

注意事项:由于内网测试 关闭防火墙与SElinux

Nginx部署

Nginx需要nginx-rtmp-module模块,yum安装没有此模块,所以本次使用源码安装

## 安装Nginx所需依赖
[root@localhost ~]# yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel git

## 下载所需安装包
[root@localhost ~]# cd  /home/artc
[root@localhost artc]# mkdir Nginx #创建源码目录 后面的源码都放在这个目录
[root@localhost artc]# cd Nginx
[root@localhost Nginx]# git clone https://github.com/nginx/nginx.git #从github服务器上将nginx的源代码下载下来
[root@localhost Nginx]# git clone https://github.com/arut/nginx-rtmp-module.git #将rtmp模块的源码下载下来
## 编译安装Nginx
[root@localhost ~]# cd /home/artc/Nginx/nginx
[root@localhost nginx]# ./auto/configure --prefix=/usr/local/nginx \
        --with-http_v2_module \
        --with-http_flv_module \
        --with-http_mp4_module \
        --add-module=../nginx-rtmp-module/
[root@localhost nginx]# make && make install 
## 更改配置文件
[root@localhost nginx]# cd /usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf
#在http模块外添加
rtmp  {
    server  {
        listen 1915;
        timeout 20s;

        application live  {
            live on;
            record off;
        }

## 一个音视频模块
        application anyrtc  {
            live on;
            hls  on;
            hls_path temp/zyh;
            hls_playlist_length 5s;
            hls_fragment 1s;
        }

        application vod  {
            play /var/flvs;
        }

        application vod_http  {
            play http://服务器IP/vod;
        }

## 一个音视频模块
        application hls  {
            live on;
            hls on;
            record off;
            hls_path /tmp/hls;
            hls_playlist_length 5s;
            hls_fragment 1s;
        }
    }
}

## 启动Nginx
[root@localhost nginx]# /usr/local/nginx/sbin/nginx

rtmp地址: rtmp://192.168.1.13:1915/anyrtc

OSB推流

确定———>开始推流

PotPlayer拉流

右键——>打开链接

拉取成功

SRS部署

下载地址:http://ossrs.net/releases/download.html

## 安装依赖
[root@localhost artc]# yum install -y redhat-lsb

## 部署
[root@localhost artc]# unzip SRS-CentOS7-x86_64-3.0.168
[root@localhost artc]# cd SRS-CentOS7-x86_64-3.0.168/
[root@localhost SRS-CentOS7-x86_64-3.0.168]# ./INSTALL 
[root@localhost SRS-CentOS7-x86_64-3.0.168]# systemctl start srs.service

## 配置文件在/usr/local/srs
[root@localhost SRS-CentOS7-x86_64-3.0.168]# cd /usr/local/srs/conf
[root@localhost conf]# vim srs.conf
# main config for srs.
# @see full.conf for detail config.

listen              1935;               ##rtmp默认端口
max_connections     1000;
srs_log_tank        file;
srs_log_file        ./objs/srs.log;
daemon              on;
http_api {
    enabled         on;
    listen          1985;
}
http_server {
    enabled         on;
    listen          9090;               ## srs管理平台端口  默认是8080 这里端口冲突改为9090
    dir             ./objs/nginx/html;
}
stats {
    network         0;
    disk            sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
    hls {
        enabled         on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
}

rtmp地址: rtmp://192.168.1.13:1935

OSB推流

确定———>开始推流

PotPlayer拉流

右键——>打开链接

拉取成功

ZLMediaKit部署

下载地址: git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit

## 准备环境
[root@localhost artc]# yum -y update

## gcc和yasm需要高版本  小编用的是gcc4.8.5 yasm1.2.0
[root@localhost artc]# yum -y update   yasm  gcc* 
[root@localhost artc]# yum -y install  openssl-devel  SDL-devel

## 编译安装cmake 3.8.2
[root@localhost ~]# cd /home/artc
[root@localhost artc]# wget https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz
[root@localhost artc]# tar zxvf cmake-3.8.2.tar.gz
[root@localhost artc]# cd cmake-3.8.2
[root@localhost cmake-3.8.2]# ./bootstrap
[root@localhost cmake-3.8.2]# gmake
[root@localhost cmake-3.8.2]# gmake install

## 国内库比较快
[root@localhost ~]# cd  /home/artc 
[root@localhost artc]# git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
[root@localhost artc]# cd ZLMediaKit
#千万不要忘记执行这句命令
[root@localhost ZLMediaKit]# git submodule update --init

## 编译安装
[root@localhost ZLMediaKit]# mkdir build
[root@localhost ZLMediaKit]# cmake .
[root@localhost ZLMediaKit]# make -j4

## ZLMediaKit服务目录
[root@localhost ZLMediaKit]# cd release/linux/Debug

## 配置文件
[root@localhost Debug]# vim config.ini 
[rtmp]  ##228行左右
handshakeSecond=15
keepAliveSecond=15
modifyStamp=0
port=1955                   ## 默认1935   端口冲突 修改了1955
sslport=0

## 程序启动
[root@localhost Debug]# ./MediaServer      ## 前台启动
[root@localhost Debug]# ./MediaServer -d & ## 后台启动

## 软连接
[root@localhost Debug]# ln -sf /home/ZLMediaKit/release/linux/Debug/MediaServer /usr/bin/

rtmp地址: rtmp://192.168.1.13:1955

OSB推流

确定———>开始推流

PotPlayer拉流

右键——>打开链接

拉取成功

rtsp推流地址: rtsp://192.168.1.13

ffmpeg推流

ffmpeg    -re  -i  yace.mp4    -vcodec h264 -acodec aac -strict -2   -f rtsp -rtsp_transport tcp  rtsp://192.168.1.13/anyrtc/ZLMediaKit

PotPlayer拉流

右键——>打开链接

拉取成功

相关推荐

Let’s Encrypt免费搭建HTTPS网站

HTTPS(全称:HyperTextTransferProtocoloverSecureSocketLayer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入...

使用Nginx配置TCP负载均衡(nginx tcp负载)

假设Kubernetes集群已经配置好,我们将基于CentOS为Nginx创建一个虚拟机。以下是实验种设置的详细信息:Nginx(CenOS8Minimal)-192.168.1.50Kube...

Nginx负载均衡及支持HTTPS与申请免费SSL证书

背景有两台minio文件服务器已做好集群配置,一台是192.168.56.41:9000;另一台是192.168.56.42:9000。应用程序通过Nginx负载均衡调用这两台minio服务,减轻单点...

HTTPS配置实战(https配置文件)

原因现在网站使用HTTPS是规范操作之一,前些日子买了腾讯云服务,同时申请了域名http://www.asap2me.top/,目前该域名只支持HTTP,想升级为HTTPS。关于HTTPS的链接过程大...

只有IP地址没有域名实现HTTPS访问方法

一般来说,要实现HTTPS,得有个注册好的域名才行。但有时候呢,咱只有服务器的IP地址,没注册域名,这种特殊情况下,也能照样实现HTTPS安全访问,按下面这些步骤来就行:第一步,先确认公网...

超详解:HTTPS及配置Django+HTTPS开发环境

众所周知HTTP协议是以TCP协议为基石诞生的一个用于传输Web内容的一个网络协议,在“网络分层模型”中属于“应用层协议”的一种。在这里我们并不研究该协议标准本身,而是从安全角度去探究使用该协议传输数...

Godaddy购买SSL之后Nginx配置流程以及各种错误的解决

完整流程:参考地址:https://sg.godaddy.com/zh/help/nginx-generate-csrs-certificate-signing-requests-3601生成NGI...

Nginx从安装到高可用,一篇搞定(nginx安装与配置详解)

一、Nginx安装1、去官网http://nginx.org/下载对应的nginx包,推荐使用稳定版本2、上传nginx到linux系统3、安装依赖环境(1)安装gcc环境yuminstallgc...

阿里云免费证书申请,配置安装,使用tomcat,支持http/https访问

参数说明商品类型默认已选择云盾证书服务(无需修改)。云盾证书服务类型SSL证书服务的类型。默认已选择云盾SSL证书(无需修改),表示付费版SSL证书。如果您需要免费领取或付费扩容DV单域名证书【免费试...

你试过两步实现Nginx的规范配置吗?极速生成Nginx配置小工具

NGINX是一款轻量级的Web服务器,最强大的功能之一是能够有效地提供HTML和媒体文件等静态内容。NGINX使用异步事件驱动模型,在负载下提供可预测的性能。是当下最受欢迎的高性能的Web...

从零开始搭建HTTPS服务(搭建https网站)

搭建HTTPS服务的最初目的是为了开发微信小程序,因为wx.request只允许发起HTTPS请求,并且还必须和指定的域名进行网络通信。要从零开始搭建一个HTTPS的服务需要下面4...

群晖NAS使用官网域名和自己的域名配置SSL实现HTTPS访问

安全第一步,群晖NAS使用官网域名和自己的域名配置SSL实现HTTPS访问【新手导向】NAS本质还是一个可以随时随地访问的个人数据存储中心,我们在外网访问的时候,特别是在公网IP下,其实会面临着很多安...

让网站快速升级HTTPS协议提高安全性

为什么用HTTPS网络安全越来越受到重视,很多互联网服务网站,都已经升级改造为https协议。https协议下数据包是ssl/tcl加密的,而http包是明文传输。如果请求一旦被拦截,数据就会泄露产生...

用Https方式访问Harbor-1.9版本(https访问流程)

我上周在头条号写过一篇原创文章《Docker-Harbor&Docker-kitematic史上最详细双系统配置手册》,这篇算是它的姊妹篇吧。这篇文章也将用到我在头条写的另一篇原创文章的...

如何启用 HTTPS 并配置免费的 SSL 证书

在Linux服务器上启用HTTPS并配置免费的SSL证书(以Let'sEncrypt为例)可以通过以下步骤完成:---###**一、准备工作**1.**确保域名已解析**...

取消回复欢迎 发表评论: