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

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

nanshan 2024-12-06 17:58 27 浏览 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拉流

右键——>打开链接

拉取成功

相关推荐

0722-6.2.0-如何在RedHat7.2使用rpm安装CDH(无CM)

文档编写目的在前面的文档中,介绍了在有CM和无CM两种情况下使用rpm方式安装CDH5.10.0,本文档将介绍如何在无CM的情况下使用rpm方式安装CDH6.2.0,与之前安装C5进行对比。环境介绍:...

ARM64 平台基于 openEuler + iSula 环境部署 Kubernetes

为什么要在arm64平台上部署Kubernetes,而且还是鲲鹏920的架构。说来话长。。。此处省略5000字。介绍下系统信息;o架构:鲲鹏920(Kunpeng920)oOS:ope...

生产环境starrocks 3.1存算一体集群部署

集群规划FE:节点主要负责元数据管理、客户端连接管理、查询计划和查询调度。>3节点。BE:节点负责数据存储和SQL执行。>3节点。CN:无存储功能能的BE。环境准备CPU检查JDK...

在CentOS上添加swap虚拟内存并设置优先级

现如今很多云服务器都会自己配置好虚拟内存,当然也有很多没有配置虚拟内存的,虚拟内存可以让我们的低配服务器使用更多的内存,可以减少很多硬件成本,比如我们运行很多服务的时候,内存常常会满,当配置了虚拟内存...

国产深度(deepin)操作系统优化指南

1.升级内核随着deepin版本的更新,会自动升级系统内核,但是我们依旧可以通过命令行手动升级内核,以获取更好的性能和更多的硬件支持。具体操作:-添加PPAs使用以下命令添加PPAs:```...

postgresql-15.4 多节点主从(读写分离)

1、下载软件[root@TX-CN-PostgreSQL01-252software]#wgethttps://ftp.postgresql.org/pub/source/v15.4/postg...

Docker 容器 Java 服务内存与 GC 优化实施方案

一、设置Docker容器内存限制(生产环境建议)1.查看宿主机可用内存bashfree-h#示例输出(假设宿主机剩余16GB可用内存)#Mem:64G...

虚拟内存设置、解决linux内存不够问题

虚拟内存设置(解决linux内存不够情况)背景介绍  Memory指机器物理内存,读写速度低于CPU一个量级,但是高于磁盘不止一个量级。所以,程序和数据如果在内存的话,会有非常快的读写速度。但是,内存...

Elasticsearch性能调优(5):服务器配置选择

在选择elasticsearch服务器时,要尽可能地选择与当前业务量相匹配的服务器。如果服务器配置太低,则意味着需要更多的节点来满足需求,一个集群的节点太多时会增加集群管理的成本。如果服务器配置太高,...

Es如何落地

一、配置准备节点类型CPU内存硬盘网络机器数操作系统data节点16C64G2000G本地SSD所有es同一可用区3(ecs)Centos7master节点2C8G200G云SSD所有es同一可用区...

针对Linux内存管理知识学习总结

现在的服务器大部分都是运行在Linux上面的,所以,作为一个程序员有必要简单地了解一下系统是如何运行的。对于内存部分需要知道:地址映射内存管理的方式缺页异常先来看一些基本的知识,在进程看来,内存分为内...

MySQL进阶之性能优化

概述MySQL的性能优化,包括了服务器硬件优化、操作系统的优化、MySQL数据库配置优化、数据库表设计的优化、SQL语句优化等5个方面的优化。在进行优化之前,需要先掌握性能分析的思路和方法,找出问题,...

Linux Cgroups(Control Groups)原理

LinuxCgroups(ControlGroups)是内核提供的资源分配、限制和监控机制,通过层级化进程分组实现资源的精细化控制。以下从核心原理、操作示例和版本演进三方面详细分析:一、核心原理与...

linux 常用性能优化参数及理解

1.优化内核相关参数配置文件/etc/sysctl.conf配置方法直接将参数添加进文件每条一行.sysctl-a可以查看默认配置sysctl-p执行并检测是否有错误例如设置错了参数:[roo...

如何在 Linux 中使用 Sysctl 命令?

sysctl是一个用于配置和查询Linux内核参数的命令行工具。它通过与/proc/sys虚拟文件系统交互,允许用户在运行时动态修改内核参数。这些参数控制着系统的各种行为,包括网络设置、文件...

取消回复欢迎 发表评论: