CentOS 7 安装 nginx-rtmp
一、安装依赖库
1.gcc
$ gcc -v Using built-in specs. COLLECT_GCC=gcc ...... Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) # 未安装:yum install -y gcc gcc-c++
2.pcre
$ rpm -qa pcre pcre-8.32-17.el7.x86_64 # 未安装:yum install -y pcre pcre-devel
3.zlib
$ yum list installed | grep zlib* zlib.x86_64 1.2.7-21.el7_9 @updates zlib-devel.x86_64 1.2.7-21.el7_9 @updates # 未安装:yum install -y zlib zlib-devel
4.openssl
$ rpm -qa openssl openssl-1.0.2k-26.el7_9.x86_64 # 未安装:yum install -y openssl openssl-devel
二、安装nginx
1.下载nginx
官网下载https://nginx.org/en/download.html,我选择了 https://nginx.org/download/nginx-1.26.0.tar.gz 版本:
$ wget https://nginx.org/download/nginx-1.26.0.tar.gz $ tar -zxvf nginx-1.26.0.tar.gz # 下载目录 /software [root@ nginx-1.26.0]# ls CHANGES CHANGES.ru LICENSE Makefile README auto conf configure contrib html man objs src [root@ nginx-1.26.0]# pwd /software/nginx-1.26.0
2.下载nginx-rtmp
我直接下载的压缩包(地址:https://github.com/arut/nginx-rtmp-module),拷贝到centos里面解压到 /software目录
[root@ nginx-rtmp-module-master]# ls AUTHORS ngx_rtmp_access_module.c ngx_rtmp_cmd_module.h ngx_rtmp_handler.c ngx_rtmp_netcall_module.h ngx_rtmp_relay_module.c LICENSE ngx_rtmp_amf.c ngx_rtmp_codec_module.c ngx_rtmp_handshake.c ngx_rtmp_notify_module.c ngx_rtmp_relay_module.h README.md ngx_rtmp_amf.h ngx_rtmp_codec_module.h ngx_rtmp_init.c ngx_rtmp_play_module.c ngx_rtmp_send.c config ngx_rtmp_auto_push_module.c ngx_rtmp_control_module.c ngx_rtmp_limit_module.c ngx_rtmp_play_module.h ngx_rtmp_shared.c dash ngx_rtmp_bandwidth.c ngx_rtmp_core_module.c ngx_rtmp_live_module.c ngx_rtmp_proxy_protocol.c ngx_rtmp_stat_module.c doc ngx_rtmp_bandwidth.h ngx_rtmp_eval.c ngx_rtmp_live_module.h ngx_rtmp_proxy_protocol.h ngx_rtmp_streams.h hls ngx_rtmp_bitop.c ngx_rtmp_eval.h ngx_rtmp_log_module.c ngx_rtmp_receive.c ngx_rtmp_version.h ngx_rtmp.c ngx_rtmp_bitop.h ngx_rtmp_exec_module.c ngx_rtmp_mp4_module.c ngx_rtmp_record_module.c stat.xsl ngx_rtmp.h ngx_rtmp_cmd_module.c ngx_rtmp_flv_module.c ngx_rtmp_netcall_module.c ngx_rtmp_record_module.h test [root@2 nginx-rtmp-module-master]# pwd /software/nginx-rtmp-module-master
3.安装
[root@ nginx-rtmp-module-master]# cd /software/nginx-1.26.0/ [root@ nginx-1.26.0]# ls CHANGES CHANGES.ru LICENSE Makefile README auto conf configure contrib html man objs src [root@ nginx-1.26.0]# ./configure --prefix=/usr/local/nginx --add-module=/software/nginx-rtmp-module-master [root@ nginx-1.26.0]# make && make install
nginx 安装在 /usr/local/nginx/ 目录下
4.配置nginx-rtmp
$ /usr/local/nginx/conf/nginx.conf # 文件的最后面,添加下列配置(github有详细的配置示例) 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秒的视频内容 } } } # 启动nginx $ /usr/local/nginx/sbin/nginx # 重启nginx /usr/local/nginx/sbin/nginx -s reload
netstat查看nginx进程是否正常运行:
$ netstat -anlp | grep nginx tcp 0 0 0.0.0.0:1935 0.0.0.0:* LISTEN 7247/nginx: master tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 7247/nginx: master unix 3 [ ] STREAM CONNECTED 580172994 7247/nginx: master unix 3 [ ] STREAM CONNECTED 580172997 7247/nginx: master unix 3 [ ] STREAM CONNECTED 580172995 7247/nginx: master unix 3 [ ] STREAM CONNECTED 580172996 7247/nginx: master
Dockerfile安装:
FROM centos:centos7.9.2009 WORKDIR /software #安装依赖库 RUN yum install -y epel-release \ && yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel openssl openssl-devel wget git \ && yum clean all #下载nginx、nginx-rtmp源码 RUN wget https://nginx.org/download/nginx-1.26.0.tar.gz \ && tar -zxvf nginx-1.26.0.tar.gz \ && git clone https://github.com/arut/nginx-rtmp-module.git #编译安装 RUN cd /software/nginx-1.26.0 \ && ./configure --prefix=/usr/local/nginx --add-module=/software/nginx-rtmp-module \ && make && make install #复制Nginx配置文件 # COPY nginx.conf /usr/local/nginx/conf/nginx.conf EXPOSE 80 443 ENTRYPOINT /usr/local/nginx/sbin/nginx -g "daemon off;"