CentOS obs直播RTMP协议推流到Nginx流媒体服务器到VUE使用HLS直播
1. 发布打包前端管理平台(ant-design-vue)
2. 发布打包后端(.NET6-WebApi)
.NET6 webAPI
orm: free sql
数据库:mysql5.7
3. 发布打包H5端(uni)
播放器使用:
import Player from 'xgplayer'; // npm install xgplayer
import HlsJsPlayer from "xgplayer-hls.js"; // 直播流m3u8(hls) npm install xgplayer-hls.js
4. 服务器安装.NET6环境:https://learn.microsoft.com/zh-cn/dotnet/core/install/linux-centos
- sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
- sudo yum install dotnet-sdk-6.0
- sudo yum install aspnetcore-runtime-6.0
5. 服务器安装宝塔:https://www.bt.cn/new/download.html
- yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec
6. 服务器安装supervisor进程守护
supervisord是服务相关的命令
supervisorctl是客户端相关的命令
安装命令:
- yum install -y supervisor
查看状态:
- supervisord -v
卸载:
- yum -y remove supervisor
在/etc创建文件目录supervisor
在/etc/supervisor下创建文件目录supervisord.d
在/etc/supervisor下上传文件supervisord.conf,内容如下:


- ; Sample supervisor config file.
- [unix_http_server]
- file=/run/supervisor/supervisor.sock ; (the path to the socket file)
- ;chmod=0700 ; sockef file mode (default 0700)
- ;chown=nobody:nogroup ; socket file uid:gid owner
- ;username=user ; (default is no username (open server))
- ;password=123 ; (default is no password (open server))
- [inet_http_server] ; inet (TCP) server disabled by default
- port=*:9001 ; (ip_address:port specifier, *:port for all iface)
- ;username=user ; (default is no username (open server))
- ;password=123 ; (default is no password (open server))
- [supervisord]
- logfile=/www/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
- logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
- logfile_backups=10 ; (num of main logfile rotation backups;default 10)
- loglevel=info ; (log level;default info; others: debug,warn,trace)
- pidfile=/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
- nodaemon=false ; (start in foreground if true;default false)
- minfds=1024 ; (min. avail startup file descriptors;default 1024)
- minprocs=200 ; (min. avail process descriptors;default 200)
- ;umask=022 ; (process file creation umask;default 022)
- ;user=chrism ; (default is current user, required if root)
- ;identifier=supervisor ; (supervisord identifier, default is 'supervisor')
- ;directory=/tmp ; (default is not to cd during start)
- ;nocleanup=true ; (don't clean up tempfiles at start;default false)
- ;childlogdir=/tmp ; ('AUTO' child log dir, default $TEMP)
- ;environment=KEY=value ; (key value pairs to add to environment)
- ;strip_ansi=false ; (strip ansi escape codes in logs; def. false)
- ; the below section must remain in the config file for RPC
- ; (supervisorctl/web interface) to work, additional interfaces may be
- ; added by defining them in separate rpcinterface: sections
- [rpcinterface:supervisor]
- supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
- [supervisorctl]
- serverurl=unix:///run/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
- serverurl=http://*:9001 ; use an http:// url to specify an inet socket
- ;username=chris ; should be same as http_username if set
- ;password=123 ; should be same as http_password if set
- ;prompt=mysupervisor ; cmd line prompt (default "supervisor")
- ;history_file=~/.sc_history ; use readline history if available
- ; The below sample program section shows all possible program subsection values,
- ; create one or more 'real' program: sections to be able to control them under
- ; supervisor.
- ;[program:theprogramname]
- ;command=/bin/cat ; the program (relative uses PATH, can take args)
- ;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
- ;numprocs=1 ; number of processes copies to start (def 1)
- ;directory=/tmp ; directory to cwd to before exec (def no cwd)
- ;umask=022 ; umask for process (default None)
- ;priority=999 ; the relative start priority (default 999)
- ;autostart=true ; start at supervisord start (default: true)
- ;autorestart=true ; retstart at unexpected quit (default: true)
- ;startsecs=10 ; number of secs prog must stay running (def. 1)
- ;startretries=3 ; max # of serial start failures (default 3)
- ;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
- ;stopsignal=QUIT ; signal used to kill process (default TERM)
- ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
- ;user=chrism ; setuid to this UNIX account to run the program
- ;redirect_stderr=true ; redirect proc stderr to stdout (default false)
- ;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
- ;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
- ;stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
- ;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
- ;stdout_events_enabled=false ; emit events on stdout writes (default false)
- ;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
- ;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
- ;stderr_logfile_backups=10 ; # of stderr logfile backups (default 10)
- ;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
- ;stderr_events_enabled=false ; emit events on stderr writes (default false)
- ;environment=A=1,B=2 ; process environment additions (def no adds)
- ;serverurl=AUTO ; override serverurl computation (childutils)
- ; The below sample eventlistener section shows all possible
- ; eventlistener subsection values, create one or more 'real'
- ; eventlistener: sections to be able to handle event notifications
- ; sent by supervisor.
- ;[eventlistener:theeventlistenername]
- ;command=/bin/eventlistener ; the program (relative uses PATH, can take args)
- ;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
- ;numprocs=1 ; number of processes copies to start (def 1)
- ;events=EVENT ; event notif. types to subscribe to (req'd)
- ;buffer_size=10 ; event buffer queue size (default 10)
- ;directory=/tmp ; directory to cwd to before exec (def no cwd)
- ;umask=022 ; umask for process (default None)
- ;priority=-1 ; the relative start priority (default -1)
- ;autostart=true ; start at supervisord start (default: true)
- ;autorestart=unexpected ; restart at unexpected quit (default: unexpected)
- ;startsecs=10 ; number of secs prog must stay running (def. 1)
- ;startretries=3 ; max # of serial start failures (default 3)
- ;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
- ;stopsignal=QUIT ; signal used to kill process (default TERM)
- ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
- ;user=chrism ; setuid to this UNIX account to run the program
- ;redirect_stderr=true ; redirect proc stderr to stdout (default false)
- ;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
- ;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
- ;stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
- ;stdout_events_enabled=false ; emit events on stdout writes (default false)
- ;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
- ;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
- ;stderr_logfile_backups ; # of stderr logfile backups (default 10)
- ;stderr_events_enabled=false ; emit events on stderr writes (default false)
- ;environment=A=1,B=2 ; process environment additions
- ;serverurl=AUTO ; override serverurl computation (childutils)
- ; The below sample group section shows all possible group values,
- ; create one or more 'real' group: sections to create "heterogeneous"
- ; process groups.
- ;[group:thegroupname]
- ;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions
- ;priority=999 ; the relative start priority (default 999)
- ; The [include] section can just contain the "files" setting. This
- ; setting can list multiple files (separated by whitespace or
- ; newlines). It can also contain wildcards. The filenames are
- ; interpreted as relative to this file. Included files *cannot*
- ; include files themselves.
- [include]
- files = supervisord.d/*.conf ;这行默认是加载/etc/supervisord.d/目录内所有conf后缀的配置,喜欢用ini的可以改成ini
supervisord.conf
在/etc/supervisor/supervisord.d下上传文件xx.conf,内容如下:
- [program:appname]
- command=dotnet appname.dll --urls=http://*:5000 ;要执行的命令
- directory=/www/api ;命令执行的目录
- environment=ASPNETCORE__ENVIRONMENT=Production ;环境变量
- user=root ;进程执行的用户身份
- stopsignal=INT
- autostart=true ;是否自动启动
- autorestart=true ;是否自动重启
- startsecs=3 ;自动重启间隔
- stderr_logfile=/www/log/appname.err.log ;标准错误日志
- stdout_logfile=/www/log/appname.out.log ;标准输出日志
- [supervisord]
- [supervisorctl]
执行启动命令:
- supervisord -c /etc/supervisor/supervisord.conf
启动成功后:执行下面命令查看,会出现一个
- ps aux|grep supervisord
- root 11589 0.0 0.0 112828 988 pts/0 S+ 16:57 0:00 grep --color=auto supervisord
- root 30510 0.0 0.4 245472 17220 ? Ss 16:12 0:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
启动程序:
- supervisorctl start appname
- supervisorctl stop appname
查看状态:
- supervisorctl status
- appname RUNNING pid 20538, uptime 0:24:24
查看状态:浏览器输入:http://*:9001/
查看端口以及appanme运行进程
- lsof -i:5000
- ps -f |grep appname
- systemctl enable supervisord.service
- systemctl is-enabled supervisord
如果启动错误,查看日志
- supervisorctl tail dcapi stdout
log日志地址:/www/log/supervisor/supervisord.log
遇到错误:Unlinking stale socket /run/supervisor/supervisor.sock
解决办法:
执行命令:
- nlink /run/supervisor/supervisor.sock
7. 宝塔安装Mysql5.7
8. 服务器安装Nginx(基于RTMP模式的)
没有git请输入以下命令
- yum -y install git
开始下载nginx-rtmp,记住cd到一个盘符进行下载,建议cd ~,也可以直接从git下载了然后复制上去/www/server/nginx/nginx-rtmp-module
- git clone https://github.com/arut/nginx-rtmp-module.git
修改配置文件:添加内容:--add-module=/root/nginx-rtmp-module
- vim /www/server/panel/install/nginx.sh
可以下载到本地修改,然后上传到服务器路径下:/www/server/panel/install/nginx.sh
修改位置:./configure --add-module=/root/nginx-rtmp-module --user=www ........................
使用sh命令安装
- sh /www/server/panel/install/nginx.sh install1.22
9. Nginx配置 ,修改宝塔》软件管理》Nginx1.22管理》配置修改如下:


- user www www;
- worker_processes auto;
- error_log /www/wwwlogs/nginx_error.log crit;
- pid /www/server/nginx/logs/nginx.pid;
- worker_rlimit_nofile 51200;
- stream {
- log_format tcp_format '$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|$upstream_connect_time';
- access_log /www/wwwlogs/tcp-access.log tcp_format;
- error_log /www/wwwlogs/tcp-error.log;
- include /www/server/panel/vhost/nginx/tcp/*.conf;
- }
- events
- {
- use epoll;
- worker_connections 51200;
- multi_accept on;
- }
- #RTMP服务,新增部分:
- rtmp_auto_push on;
- rtmp{
- server{
- listen 1935; #服务端口
- chunk_size 4096; #数据传输块的大小
- application vod{
- play ./vod; #视频文件存放位置
- }
- application live{
- live on; #开启直播
- hls on;
- hls_path /www/m3u8File;
- hls_fragment 5s; #每个视频切片的时长
- hls_playlist_length 16s;
- recorder myRecord {
- record_path /rec;
- record all manual;
- record_suffix -%Y-%m-%d-%H_%M_%S.flv;
- }
- hls_continuous on; #连续模式
- hls_cleanup on; #对多余的切片进行删除
- hls_nested on; #嵌套模式
- }
- }
- }
- #RTMP服务,新增完毕
- http
- {
- include mime.types;
- #include luawaf.conf;
- include proxy.conf;
- default_type application/octet-stream;
- server_names_hash_bucket_size 512;
- client_header_buffer_size 32k;
- large_client_header_buffers 4 32k;
- client_max_body_size 50m;
- sendfile on;
- tcp_nopush on;
- keepalive_timeout 60;
- tcp_nodelay on;
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- fastcgi_buffer_size 64k;
- fastcgi_buffers 4 64k;
- fastcgi_busy_buffers_size 128k;
- fastcgi_temp_file_write_size 256k;
- fastcgi_intercept_errors on;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 16k;
- gzip_http_version 1.1;
- gzip_comp_level 2;
- gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
- gzip_vary on;
- gzip_proxied expired no-cache no-store private auth;
- gzip_disable "MSIE [1-6]\.";
- limit_conn_zone $binary_remote_addr zone=perip:10m;
- limit_conn_zone $server_name zone=perserver:10m;
- server_tokens off;
- access_log off;
- server
- {
- listen 888;
- server_name phpmyadmin;
- index index.html index.htm index.php;
- root /www/server/phpmyadmin;
- #error_page 404 /404.html;
- include enable-php.conf;
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
- {
- expires 30d;
- }
- location ~ .*\.(js|css)?$
- {
- expires 12h;
- }
- location ~ /\.
- {
- deny all;
- }
- access_log /www/wwwlogs/access.log;
- }
- include /www/server/panel/vhost/nginx/*.conf;
- }
RTMP-Nginx配置
找到某个80端口的Nginx配置,修改:


- server
- {
- listen 80;
- server_name xxxxxxx;
- index index.php index.html index.htm default.php default.htm default.html;
- root /www/wwwroot/live;
- #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
- #error_page 404/404.html;
- #SSL-END
- #ERROR-PAGE-START 错误页配置,可以注释、删除或修改
- #error_page 404 /404.html;
- #error_page 502 /502.html;
- #ERROR-PAGE-END
- #PHP-INFO-START PHP引用配置,可以注释或修改
- include enable-php-00.conf;
- #PHP-INFO-END
- try_files $uri $uri/ /index.html;
- #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
- include /www/server/panel/vhost/rewrite/www.live.com.conf;
- #REWRITE-END
- #禁止访问的文件或目录
- location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
- {
- return 404;
- }
- #一键申请SSL证书验证目录相关设置
- location ~ \.well-known{
- allow all;
- }
- #禁止在证书验证目录放入敏感文件
- if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
- return 403;
- }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
- {
- expires 30d;
- error_log /dev/null;
- access_log /dev/null;
- }
- location ~ .*\.(js|css)?$
- {
- expires 12h;
- error_log /dev/null;
- access_log /dev/null;
- }
- #新增部分
- location /live{
- types{
- #m3u8 type设置
- application/vnd.apple.mpegurl m3u8;
- #ts分片文件设置
- video/mp2t ts;
- }
- #访问权限开启,否则访问这个地址会报403
- autoindex on;
- #指向访问m3u8文件目录
- alias /www/m3u8File;
- expires -1;
- add_header Cache-Control no-cache;
- #防止跨域问题
- add_header 'Access-Control-Allow-Origin' '*';
- add_header 'Access-Control-Allow-Credentials' 'true';
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
- add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
- }
- location /control{
- rtmp_control all;
- }
- location /stat{
- rtmp_stat all;
- rtmp_stat_stylesheet stat.xsl;
- }
- location /stat.xsl{
- root ./nginx-rtmp-module;
- }
- #新增完毕
- access_log /www/wwwlogs/www.live.com.log;
- error_log /www/wwwlogs/www.live.com.error.log;
- }
拉流配置
在Nginx服务器位置创建一个目录:/www/server/panel/m3u8File
10. 开始直播及推流
OBS推流配置服务地址:rtmp://127.0.0.1:1935/live
串流密钥:001
然后开始推流,在服务器地址/www/server/panel/m3u8File下面会生成001的文件目录,然后001文件目录里面会出现很多*.ts文件,以及一个index.mu38文件
拉流地址: http://127.0.0.1/live/001/index.m3u8
拉流地址:rtmp://127.0.0.1:1935/live/001
拉流地址注意端口
本地测试可以使用VLC media player软件
CentOS obs直播RTMP协议推流到Nginx流媒体服务器到VUE使用HLS直播的更多相关文章
- RTMP协议推流交互流程
目录 RTMP协议推流交互流程 RTMP协议推流流程 RTMP握手 RTMP建立连接 RTMP建流&Play Wireshark抓个RTMP流 RTMP协议推流交互流程 想了解下直播常见协议R ...
- 推流协议 支持RTMP协议推流
Stream Type Stream play domain nameStreaming Domain Name 播流 推流 推流协议 支持RTMP协议推流
- HLS-搭建Nginx流媒体服务器
Nginx本身是一个非常出色的HTTP服务器,FFMPEG是非常好的音视频解决方案.这两个东西通过一个nginx的模块nginx-rtmp-module,组合在一起即可以搭建一个功能相对比较完善的流媒 ...
- 用nginx搭建http/rtmp/hls协议的MP4/FLV流媒体服务器
前前后后搭建了两三个星期,终于可以告一段落,nginx实在是有点强大.写一篇笔记来记录一下这个过程中的思路和解决方案. 一.搭建nginx平台: 基本是基于http://blog.csdn.net/x ...
- 极速搭建RTMP直播流服务器+webapp (vue) 简单实现直播效果
在尝试使用webRTC实现webapp直播失败后,转移思路开始另外寻找可行的解决方案.在网页上尝试使用webRTC实现视频的直播与看直播,在谷歌浏览器以及safari浏览器上测试是可行的.但是基于基座 ...
- EasyDSS高性能RTMP、HLS(m3u8)、HTTP-FLV、RTSP流媒体服务器解决方案之多方式虚拟直播
EasyDSS流媒体解决方案之虚拟直播 虚拟直播相对于传统的实时直播的差别在于,实时的直播在于播放的是一个实时的直播流,而虚拟直播,可能适应范围更加的广.虚拟直播,不仅仅可以播放实时的视频直播流,也可 ...
- 基于阿里云直播实现视频推流(ffmpeg)/拉流(Django2.0)以及在线视频直播播放(支持http/https)功能
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_146 由于5g网络的光速推广,视频业务又被推上了风口浪尖,在2019年初我们还在谈论照片,短视频等关键字,而进入2020年,我们津 ...
- 在CentOS上搭建最^1024基本的Nginx反向服务器
昨天有过去的同事突然问我,他在CentOS7上试验搭建反向服务器死活不成功.现将最简单的搭建步骤分享下: 0. 环境介绍 本次搭建的集群包括以下服务器 192.168.1.107:nginx反向服务器 ...
- 搭建nginx流媒体服务器(支持HLS)
环境搭建 (一)下载源代码 nginx,地址:http://nginx.org/可以选择需要的版本下载 nginx_mod_h264_streaming-2.2.7.tar.gz ,支持MP4流,具体 ...
随机推荐
- 2022-07-15/16 第一小组 田龙月 管理系统javaSE
JavaSE小项目(基础语法:二分查找:冒泡排序)--还是存在bug:删除一个数组内一组数据后面只有一组后面数据能向前移位 (YY:使用"方法"应该会好很多,代码架构会清晰一点)未 ...
- 【线性DP】数字三角形
题目链接 原题链接 题目描述 给定一个如下图所示的数字三角形,从顶部出发,在每一结点可以选择移动至其左下方的结点或移动至其右下方的结点,一直走到底层,要求找出一条路径,使路径上的数字的和最大. 7 3 ...
- jdbc 12: 悲观锁
jdbc连接mysql,简单演示行级锁 通过debug模式进行演示 在Test1程序设置断点,让程序1,查询并锁定数据,且程序不执行完(此时停在debug断点处) 这时启动Test2程序,去修改已经被 ...
- 谷歌邮箱使用python自动化发送邮件出现smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted.的解决
今天学习使用邮箱自动化办公的过程中run时一直出现如下错误;smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password n ...
- NOI / 2.1基本算法之枚举题解-1(3861字)制作不易
目录 1.15 Counterfeit Dollarhttp://noi.openjudge.cn/ch0201/15/ 2.1749 数字方格
- 0202年,您真的需要Thrift这样一个RPC微服务框架来拯救一下传统HTTP接口(api)了
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_104 目前市面上类似Django的drf框架基于json的http接口解决方案大行其道,人们也热衷于在接口不多.系统与系统交互较少 ...
- Odoo 14 升级模块后为什么template不生效?
# 升级模块后为什么template不生效? # 直接原因是因为你在record标签的父级data标签标签中设置了noupdate为true.这就导致你后面无论你怎么修改data下面的子标签内容,都不 ...
- 套接字传输(TCP简单使用)
- k8s手动扩缩容
1. 查询deploy副本数,ready数表示副本数 kubectl get deploy 2.通过命令直接扩容或者缩容,--replicas=1表示把my-dep缩容到副本数1,--replicas ...
- atcoder beginner contest 251(D-E)
Tasks - Panasonic Programming Contest 2022(AtCoder Beginner Contest 251)\ D - At Most 3 (Contestant ...