直播搭建

https://blog.youkuaiyun.com/boonya/article/details/52210576

https://www.nihaoshijie.com.cn/index.php/archives/615


RTMP 
RTMP是Real Time Messaging Protocol(实时消息传输协议) 
RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进行音视频和数据通信。支持该协议的软件包括Adobe Media Server/Ultrant Media Server/red5等。

nginx 
毛子开发的服务器,很强,很轻

nginx-rtmp-module 

相关文档:

https://github.com/arut/nginx-rtmp-module/wiki/

1、下载nginx  rtmp模块

[php]  view plain  copy
  1. wget https://codeload.github.com/arut/nginx-rtmp-module/zip/master  

2、解压zip包

如果下载后文件为  master  执行命令

mv master master.zip

[php]  view plain  copy
  1. unzip master.zip  

3、找到nginx源码包,添加 rtmp模块   (指定路径)

[php]  view plain  copy
  1. ./configure --add-module=/home/nginx-rtmp-module-master

4、编译 编译安装

[php]  view plain  copy
  1. make  
  2. make install   

5、添加配置 rtmp与nginx.conf同级;然后在http中配置server

[php]   view plain  copy
  1. rtmp {  
  2.   
  3.         server {  
  4.   
  5.   
  6.              listen 2018;  #监听的端口    
  7.   
  8.             chunk_size 4000; #块大小      
  9.   
  10.   
  11.             application hls {  #rtmp推流请求路径    
  12.                 live on;  
  13.                 hls on;  
  14.                 hls_path /var/www/html/zhibo_rtmp;  
  15.                 hls_fragment 5s;  
  16.             }  
  17.         }  
  18.     }  


[php]  view plain  copy
  1. server {  
  2.         listen       81;  
  3.         server_name  _;  
  4.         root /var/www/html/zhibo_rtmp;  
  5.         #charset koi8-r;  
  6.   
  7.         access_log  logs/81.access.log  main;  
  8.         error_log  logs/81.error.log;  
  9.   
  10.         location / {  
  11.             index  index.html index.htm index.php;  
  12.         autoindex on;  
  13.         }  
  14.   
  15.         #error_page  404              /404.html;  
  16.   
  17.         # redirect server error pages to the static page /50x.html  
  18.         #  
  19.         error_page   500 502 503 504  /50x.html;  
  20.         location = /50x.html {  
  21.         }  
  22.   
  23.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  24.         #  
  25.         #location ~ \.php$ {  
  26.         #    proxy_pass   http://127.0.0.1;  
  27.         #}  
  28.   
  29.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  30.         #  
  31.         location ~ \.php$ {  
  32.             fastcgi_pass   127.0.0.1:9000;  
  33.             fastcgi_index  index.php;  
  34.             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
  35.             include        fastcgi_params;  
  36.         }  
  37.   
  38.         # deny access to .htaccess files, if Apache's document root  
  39.         # concurs with nginx's one  
  40.         #  
  41.         #location ~ /\.ht {  
  42.         #    deny  all;  
  43.         #}  
  44.     }  

6、下载obs,用obs软件进行推流


点击设置进入设置页面



串流类型选择: 自定义流媒体服务器

URL: rtmp://47.94.150.11:2018/hls

流秘钥 : test

      自己定义,注意后边在拉直播流的时候 和这里保持一致

7、拉取直播流

[php]  view plain  copy
  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.   
  5.     <title>Video.js | HTML5 Video Player</title>  
  6.   
  7.     <link href="http://vjs.zencdn.net/5.20.1/video-js.css" rel="stylesheet">  
  8.     <script src="http://vjs.zencdn.net/5.20.1/videojs-ie8.min.js"></script>  
  9.       
  10. </head>  
  11. <body>  
  12.   
  13.   <video id="example_video_1" class="video-js vjs-default-skin" controls preload="auto" width="1280" height="720" poster="http://vjs.zencdn.net/v/oceans.png" data-setup="{}">  
  14.     <!-- <source src="1.mp4" type="video/mp4"> -->  
  15. #  这个地方修改为自己的流媒体服务器  如何访问直播流  
  16. <source src="http://47.94.150.11:8088/test.m3u8" type='application/x-mpegURL'>  
  17.     <p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>  
  18.   </video>  
  19.   
  20.   <script src="http://vjs.zencdn.net/5.20.1/video.js"></script>  
  21. </body>  
  22.   
  23. </html>  




<think>好的,用户想了解如何在云服务器上部署和配置直播平台。首先,我需要回忆一下之前处理类似问题的步骤和相关知识。直播服务通常涉及视频采集、编码、传输、分发和播放这几个主要环节。云服务器在这里主要承担流媒体服务器和存储的角色。 首先,用户的需求是在云服务器上搭建直播平台,可能包括推流、转码、分发等步骤。根据用户提供的引用内容,特别是引用[2]中提到在华为云Flexus云服务器X实例上成功部署了File Browser应用,说明用户可能对华为云的环境比较熟悉,或者倾向于使用华为云服务。因此,在回答中可以推荐使用华为云的实例,并参考其控制台操作。 接下来,需要考虑直播平台的基本架构。通常,直播系统需要以下几个组件:流媒体服务器(如Nginx-rtmp-module、SRS)、推流工具(如OBS)、播放器(如VLC、H5播放器)以及可能的转码服务。用户可能需要详细的步骤指导,包括环境准备、软件安装、配置、测试等。 然后,我需要确保回答符合用户提供的系统级指令,比如正确使用LaTeX格式,生成相关问题,引用标记等。例如,在提到技术参数时,如果有数学表达式,需要用$符号包裹,但在这个问题中可能涉及的数学内容较少,但如果有转码相关的参数,可能需要涉及。不过直播部署更多是配置步骤,可能数学公式较少,但需要注意独立公式的格式。 另外,用户提供的引用[3]提到了Ubuntu 24.04作为Linux服务器的环境,因此在步骤中可以建议使用Ubuntu系统,并给出相应的命令。例如,安装Nginx和rtmp模块可能需要使用apt-get命令,配置Nginx的rtmp模块需要编辑nginx.conf文件。 还要注意用户提到的引用[2]中强调华为云Flexus云服务器的高性能、稳定性和安全性,因此在推荐服务器配置时,可以建议选择适合流媒体处理的实例类型,比如高带宽、高计算能力的配置,并提到安全组设置需要开放相关端口,如1935(RTMP)、80(HTTP)、443(HTTPS)等。 在步骤中,可能包括: 1. 购买并配置云服务器实例(推荐华为云Flexus,参考引用[1]和[2])。 2. 安装必要的依赖和流媒体服务器软件,如Nginx with RTMP模块。 3. 配置服务器的安全组规则,开放相应端口。 4. 配置Nginx的RTMP模块,设置推流和拉流的参数。 5. 测试推流和播放流程,使用OBS推流,VLC或网页播放器测试。 6. 可选的高级配置,如HLS/DASH支持、转码、录制功能等。 7. 部署前端页面,供用户访问直播流。 此外,需要生成相关问题,可能包括如何优化直播延迟、如何扩展直播服务器、如何实现直播录制和回放等,这些可以作为后续问题。 最后,确保回答结构清晰,分步骤说明,并正确引用提供的参考文献,特别是在提到云服务器配置时引用[1]和[2],环境设置时引用[3]中的Ubuntu系统。同时,代码块需要用正确的语法高亮,比如在配置Nginx的部分使用shell或nginx的代码块。</think>### 如何在云服务器上部署和配置直播平台 #### 一、环境准备 1. **选择云服务器实例** 推荐使用华为云Flexus云服务器X实例(参考控制台部署流程[^1]),建议配置: - **操作系统**:Ubuntu 24.04(与引用[3]环境一致) - **实例规格**:4核8G以上,带宽≥50Mbps(应对高并发流媒体传输) - **安全组规则**:开放端口`1935`(RTMP协议)、`80/443`(HTTP/HTTPS)、`8000-9000`(备用推流端口) 2. **安装依赖工具** 登录服务器后执行以下命令: ```bash sudo apt update && sudo apt install -y build-essential libpcre3 libpcre3-dev libssl-dev zlib1g-dev ``` --- #### 二、部署流媒体服务器 推荐使用**Nginx + RTMP模块**作为直播服务核心[^3]。 1. **编译安装Nginx with RTMP** ```bash # 下载源码 wget https://nginx.org/download/nginx-1.25.3.tar.gz git clone https://github.com/arut/nginx-rtmp-module.git # 解压并编译 tar -zxvf nginx-1.25.3.tar.gz cd nginx-1.25.3 ./configure --add-module=../nginx-rtmp-module --with-http_ssl_module make && sudo make install ``` 2. **配置RTMP服务** 编辑`/usr/local/nginx/conf/nginx.conf`,添加以下内容: ```nginx rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; # 转码配置(可选) exec ffmpeg -i rtmp://localhost/live/$name -c:v libx264 -preset ultrafast -c:a aac -f flv rtmp://localhost/hls/$name; } application hls { live on; hls on; hls_path /tmp/hls; hls_fragment 3s; } } } ``` 3. **启动服务** ```bash sudo /usr/local/nginx/sbin/nginx ``` --- #### 三、推流与播放测试 1. **推流端配置(以OBS为例)** - 服务器地址:`rtmp://<云服务器IP>/live` - 流密钥:自定义(如`test`) 2. **播放端配置** - **RTMP协议**:`rtmp://<云服务器IP>/live/test` - **HLS协议**:`http://<云服务器IP>/hls/test.m3u8` (可通过VLC或HTML5播放器测试) --- #### 四、高级功能扩展 1. **负载均衡** 通过华为云弹性负载均衡(ELB)分配多台流媒体服务器的流量,配置健康检查策略。 2. **存储与回放** 使用华为云OBS存储直播录像,通过API实现回放列表管理(参考File Browser的文件管理逻辑[^2])。 3. **安全加固** - 推流鉴权:在Nginx配置中添加`on_publish`回调验证 - HTTPS加密:通过Let's Encrypt申请免费SSL证书 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值