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.csdn.net/Student_xx/article/details/104373747

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS 7是一种流行的Linux操作系统,适用于搭建服务器。以下是CentOS 7搭建服务器的基本步骤: 1. 下载和安装CentOS 7:从CentOS官方网站下载CentOS 7的ISO镜像文件,并将其安装到服务器上。 2. 更新系统:安装完成后,使用以下命令更新系统软件包: ``` sudo yum update ``` 3. 安装所需软件:根据你的服务器需求,安装所需的软件包,例如Apache、Nginx、MySQL、PHP等。可以使用以下命令进行安装: ``` sudo yum install <package_name> ``` 4. 配置防火墙:CentOS 7默认启用了防火墙,需要配置允许访问的端口。可以使用以下命令打开指定端口: ``` sudo firewall-cmd --zone=public --add-port=<port_number>/tcp --permanent sudo firewall-cmd --reload ``` 5. 配置网络:根据你的网络环境,配置服务器的网络设置,包括IP地址、网关、DNS等。可以编辑`/etc/sysconfig/network-scripts/ifcfg-<interface_name>`文件进行配置。 6. 配置服务:根据你安装的软件,配置相应的服务。例如,如果安装了Apache,可以编辑`/etc/httpd/conf/httpd.conf`文件进行配置。 7. 启动和管理服务:使用以下命令启动和管理服务: ``` sudo systemctl start <service_name> # 启动服务 sudo systemctl stop <service_name> # 停止服务 sudo systemctl restart <service_name> # 重启服务 sudo systemctl enable <service_name> # 设置开机自启动 ``` 8. 配置安全性:为了增强服务器的安全性,可以配置防火墙规则、使用SSH密钥登录、禁用不必要的服务等。 9. 监控和维护:定期监控服务器的性能和运行状态,及时处理问题和进行维护。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值