CentOS7.9搭建Nginx+RTMP流媒体服务

1.安装Nginx依赖库

检查系统是否安装了gcc,pcre,zlib,openssl.
a.检查gcc

[root@3slartrmskwuaydn ~]# gcc -v
#系统安装了gcc会输出版本号.
#未安装:yum install -y gcc gcc-c++ 
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

b.检查pcre

#检查是否安装
方法一:
[root@3slartrmskwuaydn ~]# rpm -qa pcre
pcre-8.32-17.el7.x86_64
#查看安装目录.
[root@3slartrmskwuaydn local]# rpm -ql pcre-8.32-17.el7.x86_64
#系统安装了pcre会输出版本号.
#未安装:yum install -y pcre pcre-devel 
方法二:
下载pcre:wget http://downloads.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz
解压:tar zxvf pcre-8.45.tar.gz
切换到目录:cd pcre-8.45
编译:./configure
安装:make && make install
测试:使用pcre-config --version命令查看版本号验证是否安装成功

c.检查zlib

[root@3slartrmskwuaydn ~]# yum list installed | grep zlib*
zlib.x86_64                             1.2.7-18.el7                   @anaconda
#系统安装了zlib会输出版本号.
#未安装:yum install -y zlib zlib-devel 

d.检查openssl

[root@3slartrmskwuaydn ~]# rpm -qa openssl
openssl-1.0.2k-19.el7.x86_64
#系统安装了openssl会输出版本号.
#未安装:yum install -y openssl openssl-devel
2.安装Nginx

官网下载https://nginx.org/en/download.html,这边选择 nginx-1.22.0,复制下载地址.https://nginx.org/download/nginx-1.22.0.tar.gz

//进入目录
[root@3slartrmskwuaydn /]# cd usr/local

[root@3slartrmskwuaydn local]# wget https://nginx.org/download/nginx-1.22.0.tar.gz

[root@3slartrmskwuaydn local]# tar -zxvf nginx-1.22.0.tar.gz

[root@3slartrmskwuaydn local]# rm nginx-1.22.0.tar.gz

[root@3slartrmskwuaydn nginx-1.22.0]# ./configure --prefix=/usr/local/nginx

[root@3slartrmskwuaydn nginx-1.22.0]# make 
[root@3slartrmskwuaydn nginx-1.22.0]# make install

//配置环境变量
vim /etc/profile

在export下添加:
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin

//查看启动状态,80端口是否是listen
[root@3slartrmskwuaydn sbin]# netstat -antp|grep  80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      26380/nginx: master

注意:这个出现了一个问题

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

//安装zlib
yum install -y zlib-devel
3.安装Nginx-RTMP拓展

nginx-rtmp拓展包github地址:https://github.com/arut/nginx-rtmp-module,可以使用git clone下拉或者直接下载,我这边下载解压放到:/opt/module/下.

cd /usr/local/nginx-1.22.0
./configure --add-module=/opt/module/nginx-rtmp-module
make
make install

配置Nginx-rtmp

  • 1.修改配置文件
vim /usr/local/nginx-1.22.0/conf/nginx.conf
  • 2.底部添加
rtmp {
    
    
    server {
    
    
        listen 1935; #监听的端口 
        chunk_size 4000;
        application tv_file {
    
    
            live on; #开启实时
            hls on; #开启hls
            hls_path /usr/local/nginx/html/tv_file; #rtmp推流请求路径,文件存放路径
            hls_fragment 5s; #每个TS文件包含5秒的视频内容
        }
    }
}

  • 3.重启nginx
nginx -s reload

猜你喜欢

转载自blog.csdn.net/qq_35193677/article/details/127387362