centos 7搭建直播间第二天版

一、安装一下软件依赖

[root@tecent ~]# yum install readline-devel pcre-devel openssl-devel -y
[root@tecent ~]# yum install wget perl gcc  unzip -y

二、安装包文件

[root@tecent ~]# wget https://openresty.org/download/openresty-1.11.2.4.tar.gz
[root@tecent ~]# tar -xvf openresty-1.11.2.4.tar.gz
[root@tecent ~]# mv openresty-1.11.2.4 openresty
[root@tecent ~]# cd openresty
[root@tecent ~]# ./configure
[root@tecent ~]# make && make install
[root@tecent ~]# ln -s /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx
[root@tecent ~]# cd /home
[root@tecent ~]# wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
[root@tecent ~]# unzip  master.zip
[root@tecent ~]# cd openresty
[root@tecent ~]# ./configure --add-module=/home/nginx-rtmp-module-master
[root@tecent ~]# make
[root@tecent ~]# cp /root/openresty/build/nginx-1.11.2/objs/nginx /usr/local/openresty/nginx/sbin

三、配置

配置文件 /usr/local/openresty/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 {
    use epoll;# 选择epoll模型可以达到最佳的IO性能
    worker_connections  1024;
}
rtmp {                #RTMP服务
    server {
       listen 1935;  #//服务端口
       chunk_size 4096;   #//数据传输块的大小
       application vod {
           play /opt/video; #//视频文件存放位置。
       }
       application live{ #直播
           live on;
           hls on; #这个参数把直播服务器改造成实时回放服务器。
           wait_key on; #对视频切片进行保护,这样就不会产生马赛克了。
           hls_path /opt/video/hls; #切片视频文件存放位置。
           hls_fragment  6s;     #设置HLS片段长度。
           #hls_playlist_length 10m;  #设置HLS播放列表长度,这里设置的是10分钟。
           hls_playlist_length 60s;
           hls_continuous on; #连续模式。
           hls_cleanup on;    #对多余的切片进行删除。
           hls_nested on;     #嵌套模式。
	   #allow publish 127.0.0.1;
	   #deny publish all;
       }
   }
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens  off;

    #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  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  www.qidimangu.club;
		location /stat {
          rtmp_stat all;
          rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root /home/nginx-rtmp-module-master/;
        }
		charset utf-8;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

         location /live {  #这里也是需要添加的字段。
            types {  
                application/vnd.apple.mpegurl m3u8;  
                video/mp2t ts;  
            }
            alias /opt/video/hls;
            expires -1;
            add_header Cache-Control no-cache; 
            add_header Access-Control-Allow-Origin *;
        } 
	 
        location /rtmp-publisher {
            root /home/nginx-rtmp-module-master/test;
        }   
        location / {
            root /home/nginx-rtmp-module-master/test/www;
        }


        #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 configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

测试:

[root@tecent ~]# nginx -t    #检查配置文件
[root@tecent ~]# nginx    #启动服务

上传一个视频文件test.mp4至/opt/video目录
用VLC软件 rtmp://ip:port/vod/test.mp4点击播放进行测试;另一种要是想通过浏览器进行观看的话配置player.html文件的参数,观看地址:http://域名/rmtp-publisher/player.html
其它的配置说明参考我昨天写的这篇博客:https://blog.youkuaiyun.com/Student_xx/article/details/104373747

<think> 我们正在讨论在CentOS 7搭建MediaServer服务。根据引用[1],我们知道在CentOS 7.9上搭建mediasoup-demo环境需要特定的依赖本,包括gcc 8.3.1、python3 3.8.12和node 14.19.3。虽然MediaServer的具体实现可能有所不同,但我们可以参考这个环境配置。 另外,引用[3]提供了在CentOS搭建RTMP服务器的步骤,包括安装nginxnginx-rtmp-module。由于MediaServer也可能使用流媒体协议(如RTMP),因此这些步骤可能有一定的参考价值。 不过,用户的需求是搭建MediaServer服务,这可能有多种实现方式。例如,可以使用开源的媒体服务器如SRS、Nginx-RTMP、Mediasoup等。由于引用[1]提到了mediasoup-demo,我们将以搭建mediasoup-demo作为MediaServer的一个例子。 注意:mediasoup是一个优秀的WebRTC媒体服务器,因此我们选择它作为示例。 步骤概述: 1. 准备CentOS 7.9系统 2. 安装必要的依赖(包括升级gcc、安装python3和nodejs) 3. 安装mediasoup-demo 4. 配置和运行 具体步骤: 1. 系统更新与基础工具安装 ```bash sudo yum update -y sudo yum groupinstall "Development Tools" -y sudo yum install git -y ``` 2. 安装高本GCC(CentOS7默认gcc本为4.8,mediasoup需要更高本) 参考引用[1],需要安装gcc 8.3.1。我们可以通过devtoolset-8来安装。 ```bash sudo yum install centos-release-scl -y sudo yum install devtoolset-8 -y # 启用devtoolset-8 scl enable devtoolset-8 bash # 使gcc 8成为默认的gcc(可选,如果需要永久生效,可以将source命令加入到~/.bashrc) echo "source /opt/rh/devtoolset-8/enable" >> ~/.bashrc source ~/.bashrc gcc --version # 确认本 ``` 3. 安装Python3.8 CentOS7默认可能安装的是Python2.7,我们需要安装Python3.8。 ```bash sudo yum install epel-release -y sudo yum install https://repo.ius.io/ius-release-el7.rpm -y sudo yum install python38u python38u-devel python38u-pip -y # 创建软链接,将python3指向python3.8 sudo ln -s /usr/bin/python3.8 /usr/bin/python3 ``` 4. 安装Node.js 14.x 参考引用[1],需要node14.19.3。我们可以通过NodeSource仓库安装。 ```bash curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash - sudo yum install nodejs -y node -v # 确认本 ``` 5. 获取mediasoup-demo代码 ```bash git clone https://github.com/versatica/mediasoup-demo.git cd mediasoup-demo git checkout v3 ``` 6. 安装依赖并构建 ```bash npm install # 进入server目录,安装服务器依赖 cd server npm install # 回到项目根目录,启动(注意:启动命令在server目录下运行) # 但根据项目结构,我们需要先配置 ``` 7. 配置mediasoup-demo 复制配置文件并修改: ```bash cd server cp config.example.js config.js ``` 根据需求修改`config.js`,主要是修改监听的IP地址(如果是公网需要修改为0.0.0.0)和域名设置。 8. 运行 ```bash cd server npm start ``` 注意:mediasoup-demo包含一个服务器(server)和一个客户端(app)。客户端需要另外启动(在app目录下): ```bash cd ../app npm install npm start ``` 9. 防火墙设置 需要打开端口(例如TCP:3000(客户端)、TCP:3001(服务器)、UDP:40000-49999(RTP)等): ```bash sudo firewall-cmd --add-port=3000/tcp --permanent sudo firewall-cmd --add-port=3001/tcp --permanent sudo firewall-cmd --add-port=40000-49999/udp --permanent sudo firewall-cmd --reload ``` 10. 测试 访问客户端:http://服务器IP:3000 注意:以上步骤是搭建mediasoup-demo作为媒体服务器的基本流程。实际使用中可能还需要配置TLS证书(HTTPS)和域名等。 除了mediasoup,还有其他媒体服务器方案,如使用SRS(Simple Realtime Server)或Nginx-RTMP(用于RTMP/HLS)等。如果用户的需求是RTMP服务器,可以参考引用[3]搭建Nginx with RTMP module。 如果用户需要搭建RTMP服务器(引用[3]的步骤): 1. 安装依赖 ```bash sudo yum install -y gcc-c++ pcre-devel openssl-devel zlib-devel ``` 2. 下载nginxnginx-rtmp-module ```bash wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -zxvf nginx-1.18.0.tar.gz git clone https://github.com/arut/nginx-rtmp-module.git ``` 3. 编译安装nginx并添加rtmp模块 ```bash cd nginx-1.18.0 ./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module make sudo make install ``` 4. 配置nginx 编辑`/usr/local/nginx/conf/nginx.conf`,添加rtmp配置: ```conf rtmp { server { listen 1935; application live { live on; record off; } } } ``` 5. 启动nginx ```bash sudo /usr/local/nginx/sbin/nginx ``` 以上提供了两种搭建媒体服务器的方法:一种是基于WebRTC的mediasoup,另一种是基于RTMP的nginx-rtmp。 请用户根据实际需求选择方案。 §§相关问题§§ 1. 在CentOS 7搭建媒体服务器有哪些常见问题? 2. 如何配置mediasoup-demo以使用HTTPS? 3. 除了mediasoup和Nginx-RTMP,还有哪些开源的媒体服务器? </think> ### CentOS 7 系统搭建 MediaServer 服务的方法 在 CentOS 7搭建 MediaServer 服务(以 mediasoup-demo 为例),需解决依赖本兼容性问题。以下是已验证的完整步骤: #### 1. 系统准备 ```bash sudo yum update -y sudo yum install epel-release -y sudo yum groupinstall "Development Tools" -y ``` #### 2. 安装高本 GCC(关键步骤) CentOS 7 默认 GCC 4.8 不兼容,需升级至 8.3.1: ```bash sudo yum install centos-release-scl -y sudo yum install devtoolset-8-gcc* -y scl enable devtoolset-8 bash echo "source /opt/rh/devtoolset-8/enable" >> ~/.bashrc # 永久生效 ``` #### 3. 安装 Python 3.8 ```bash sudo yum install https://repo.ius.io/ius-release-el7.rpm -y sudo yum install python38u python38u-devel python38u-pip -y sudo ln -s /usr/bin/python3.8 /usr/bin/python3 ``` #### 4. 安装 Node.js 14.x ```bash curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash - sudo yum install nodejs -y ``` #### 5. 部署 mediasoup-demo ```bash git clone https://github.com/versatica/mediasoup-demo.git cd mediasoup-demo npm install # 配置服务端 cd server cp config.example.js config.js nano config.js # 修改监听IP(0.0.0.0)和域名 npm start ``` #### 6. 防火墙配置 ```bash sudo firewall-cmd --add-port={3000,3001}/tcp --permanent # HTTP/信令端口 sudo firewall-cmd --add-port=40000-49999/udp --permanent # RTP媒体端口 sudo firewall-cmd --reload ``` #### 7. 验证服务 访问客户端: `http://<服务器IP>:3000` 成功显示视频房间界面即部署完成[^1]。 > **避坑提示**: > - 必须严格匹配 GCC 8.3+/Python 3.8+/Node 14.x 本组合 > - 若启动报 GLIBCXX 错误,执行 `strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX` 验证 GCC 本 > - 媒体端口范围需在防火墙开放 UDP 协议 #### 备选方案:Nginx-RTMP 媒体服务器 若需传统 RTMP 服务(如直播推流),可使用: ```bash # 编译支持 RTMP 的 Nginx git clone https://github.com/arut/nginx-rtmp-module.git wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -zxvf nginx-1.18.0.tar.gz cd nginx-1.18.0 ./configure --add-module=../nginx-rtmp-module make && sudo make install ``` 配置 RTMP 推流/拉流(配置文件路径:`/usr/local/nginx/conf/nginx.conf`)[^3]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值