CentOS安装配置nginx-rtmp-module(同时支持IPv4和IPv6)

前言

  因测试须要配置IPv6环境下的rtmp流媒体服务器,想着直接使用docker镜像,搜索对比后发现这个能知足要求:nginx

       https://hub.docker.com/r/tiangolo/nginx-rtmpgit

  但后来确认目标服务器是CentOS 6.5,没办法使用docker,因此就将原做者的dockerfile转换成了shell,方便在没有docker环境的机器上使用。github

  思路整理:测试环境部署软件的时候能够优先考虑docker方案,就算是本身从无到有部署,dockerfile也会是最好的参考。docker

碰到的问题

  1. 依赖安装问题: 编译nginx的时候提示PCRE库找不到,所以加入了安装依赖的步骤,不一样的系统的系统还可能会提示其余错误,须要按提示安装依赖库。
  2. nginx rtmp配置问题:一开始是照搬原做者的配置文件(端口同样,应用同样),但实际测试中发现使用IPv4和IPv6地址推同一个流名称时,会有如下的现象:
    • 客户端不会报错。
    • 拉流的时候会混乱,可能只有其中一个地址能拉到流,而且不一样时间拉的流可能会错乱(IPv4地址拉取到IPv6地址推过来的流)。
    • 对于以上两个现象,可能须要更近一步分析才能知道缘由了。所以这里为了不混淆,直接配置了两个服务,分别配置成不用的端口及应用名。
  3. CentOS6.5环境下ipv6网络有单独的防火墙服务进行控制,服务名为ip6tables。ip6tables服务中止后网络终于通了, IPv6地址的服务探测也能够使用telnet ip port命令(windows)

脚本及配置

原做者提供nginx配置文件

 1 worker_processes auto;  2 rtmp_auto_push on;  3 events {}  4 rtmp {  5  server {  6         listen 1935;  7         listen [::]:1935 ipv6only=on;  8  application live {  9  live on; 10  record off; 11  } 12  } 13 }
View Code

最终安装配置脚本

 1 #!/bin/bash  2 # This shell is to install Nginx with nginx-rtmp-module installed and configrued for RTMP Streaming under IPV6  3 
 4 # Versions of Nginx and nginx-rtmp-module to use  5 NGINX_VERSION=nginx-1.15.0 
 6 NGINX_RTMP_MODULE_VERSION=1.2.1 
 7 
 8 # Download and decompress Nginx  9 mkdir -p /tmp/build/nginx 10 cd /tmp/build/nginx 11 wget --no-check-certificate -O ${NGINX_VERSION}.tar.gz https://nginx.org/download/${NGINX_VERSION}.tar.gz
12 tar -zxf ${NGINX_VERSION}.tar.gz 13 
14 # Download and decompress RTMP module 15 mkdir -p /tmp/build/nginx-rtmp-module 16 cd /tmp/build/nginx-rtmp-module 17 wget --no-check-certificate -O nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION}.tar.gz https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_MODULE_VERSION}.tar.gz
18 tar -zxf nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION}.tar.gz 19 cd nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION} 20 
21 # Install dependencies 22 yum -y install pcre-devel openssl openssl-devel 23 
24 # Build and install Nginx 25 # The default puts everything under /usr/local/nginx, so it's needed to change 
26 # it explicitly. Not just for order but to have it in the PATH 27 cd /tmp/build/nginx/${NGINX_VERSION} 28 ./configure \ 29     --sbin-path=/usr/local/sbin/nginx \ 30     --conf-path=/etc/nginx/nginx.conf \ 31     --error-log-path=/var/log/nginx/error.log \ 32     --pid-path=/var/run/nginx/nginx.pid \ 33     --lock-path=/var/lock/nginx/nginx.lock \ 34     --http-log-path=/var/log/nginx/access.log \ 35     --http-client-body-temp-path=/tmp/nginx-client-body \ 36     --with-http_ssl_module \ 37     --with-threads \ 38     --with-ipv6 \ 39     --add-module=/tmp/build/nginx-rtmp-module/nginx-rtmp-module-${NGINX_RTMP_MODULE_VERSION} 40 make && make install
41 mkdir /var/lock/nginx 42 rm -rf /tmp/build 43 
44 # Config RTMP Streaming and IPV6 for Nginx 45 cat >/etc/nginx/nginx.conf <<EOF 46 worker_processes auto; 47 rtmp_auto_push on; 48 events {} 49 rtmp { 50  server { 51         listen 1934; 52  application live4 { 53  live on; 54  record off; 55  } 56  } 57  server { 58         listen [::]:1936 ipv6only=on; 59  application live6 { 60  live on; 61  record off; 62  } 63  } 64 } 65 EOF 66 
67 #Show Nginx Version 68 nginx -V
View Code
相关文章
相关标签/搜索