CentOS7.9 builds Nginx+RTMP streaming media service

1. Install Nginx dependency library

Check whether the system has installed gcc, pcre, zlib, openssl.
a. Check 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. Check 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. Check 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. Check openssl

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

Download https://nginx.org/en/download.html from the official website, select nginx-1.22.0 here , and copy the download address. 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

NOTE: A problem arises with this

./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. Install Nginx-RTMP extension

The github address of the nginx-rtmp expansion package: https://github.com/arut/nginx-rtmp-module , you can use git clone to drop down or download it directly. I download and decompress it here and put it under: /opt/module/.

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

Configure Nginx-rtmp

  • 1. Modify the configuration file
vim /usr/local/nginx-1.22.0/conf/nginx.conf
  • 2. Add at the bottom
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. Restart nginx
nginx -s reload

Guess you like

Origin blog.csdn.net/qq_35193677/article/details/127387362