首页 > 系统相关 >yum安装nginx没有某一模块,该如何添加第三方模块

yum安装nginx没有某一模块,该如何添加第三方模块

时间:2024-09-08 17:52:15浏览次数:6  
标签:http stream -- module nginx yum 模块 path

本文将以添加--with-stream模块为例,演示如何去添加新的模块进去。

需求:生产有个接口是通过socket通信。nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信。

实现方法:Centos7.5下yum直接安装的nginx,添加新模块支持tcp转发;重新编译Nginx并添加--with-stream参数。

1.查看nginx版本模块

nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.1.1g FIPS  21 Apr 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log 
--http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi 
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat 
--with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module 
--with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module 
--with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic 
--with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads 
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' 
--with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

2.下载一个同版本可编译的nginx源码

cd /opt 
wget http://nginx.org/download/nginx-1.20.1.tar.gz 
tar xf nginx-1.20.1.tar.gz && cd nginx-1.20.1

3.备份原nginx文件

mv /usr/sbin/nginx /usr/sbin/nginx.bak
cp -r /etc/nginx{,.bak}

4.重新编译nginx

检查模块是否支持,比如这次添加 limit 限流模块 和 stream 模块:

./configure --help | grep limit

--without-http_limit_conn_module disable ngx_http_limit_conn_module

--without-http_limit_req_module disable ngx_http_limit_req_module

--without-stream_limit_conn_module disable ngx_stream_limit_conn_module

ps:-without-http_limit_conn_module disable 表示已有该模块,编译时,不需要添加

./configure –help | grep stream
  --without-http_upstream_hash_module
                                     disable ngx_http_upstream_hash_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_random_module
                                     disable ngx_http_upstream_random_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_module
  --without-http_upstream_zone_module
                                     disable ngx_http_upstream_zone_module
  --with-stream                      enable TCP/UDP proxy module
  --with-stream=dynamic              enable dynamic TCP/UDP proxy module
  --with-stream_ssl_module           enable ngx_stream_ssl_module
  --with-stream_realip_module        enable ngx_stream_realip_module
  --with-stream_geoip_module         enable ngx_stream_geoip_module
  --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
  --with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module
  --without-stream_limit_conn_module disable ngx_stream_limit_conn_module
  --without-stream_access_module     disable ngx_stream_access_module
  --without-stream_geo_module        disable ngx_stream_geo_module
  --without-stream_map_module        disable ngx_stream_map_module
  --without-stream_split_clients_module
                                     disable ngx_stream_split_clients_module
  --without-stream_return_module     disable ngx_stream_return_module
  --without-stream_set_module        disable ngx_stream_set_module
  --without-stream_upstream_hash_module
                                     disable ngx_stream_upstream_hash_module
  --without-stream_upstream_least_conn_module
                                     disable ngx_stream_upstream_least_conn_module
  --without-stream_upstream_random_module
                                     disable ngx_stream_upstream_random_module
  --without-stream_upstream_zone_module
                                     disable ngx_stream_upstream_zone_module

ps:–with-stream enable 表示不支持,编译时要自己添加该模块

根据第1步查到已有的模块,加上本次需新增的模块:--with-stream

cd /opt/nginx-1.20.1
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log 
--http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi 
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio 
--with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic 
--with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module 
--with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module 
--with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug  --with-stream

添加模块nginx-http-flv-module为例

./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=./nginx-http-flv-module

以上编译时,如出现缺少依赖,一般需要安装以下模块,安装完再次编译:

yum -y install libxml2 libxml2-dev libxslt-devel

yum -y install gd-devel

yum -y install perl-devel perl-ExtUtils-Embed

yum -y install GeoIP GeoIP-devel GeoIP-data

yum -y install pcre-devel

yum -y install openssl openssl-devel

yum -y install gcc

yum -y install gperftools

yum install google-perftools

yum install epel-release

碰到错误缺少那个就用yum安装那个 然后继续编译完成

5.编译通过,继续验证

继续输入:make

make完成后不要继续输入make install,以免现在的nginx出现问题。

上完成后,会在objs目录下生成一个nginx文件,先验证:

/opt/test/nginx-1.20.1/objs/nginx -t

/opt/test/nginx-1.20.1/objs/nginx -v

6.替换Nginx文件并重启

cp /opt/test/nginx-1.20.1/objs/nginx /usr/sbin/

nginx -s reload

7.检查

nginx -V

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)  
built with OpenSSL 1.0.2k-fips  26 Jan 2017

TLS SNI support enabled

configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=./nginx-http-flv-module

新添加的模块在最后,添加模块成功。


标签:http,stream,--,module,nginx,yum,模块,path
From: https://blog.51cto.com/u_12226796/11952451

相关文章

  • `match()`和`search()`在Python的`re`模块中的区别
    在Python的re模块中,match()和search()是两个非常重要的函数,它们都用于在字符串中搜索正则表达式的匹配项,但它们在搜索的起始位置和返回结果方面存在关键区别。一、match()函数match()函数尝试从字符串的起始位置匹配一个模式,如果不是从起始位置开始匹配的话,match()将不会成功......
  • Kubernetes各模块如何与API Server通信
    Kubernetes的架构是基于一系列的组件和模块,这些组件通过APIServer进行通信。APIServer是Kubernetes控制平面的核心,负责处理所有的RESTfulAPI请求,并与etcd(用于存储集群状态)进行交互。以下是Kubernetes各个主要模块如何与APIServer通信的详细说明:1.Kubelet功能......
  • jinja模块
     viinstallMySQL.yaml-hosts:web tasks:   -name:installMySQL    yum:      name:mariadb-server   -name:pushmy.cnf    copy:      src:/work/my.cnf      dest:/etc/my.cnf  ......
  • 搭建内网yum仓库
    1.架构图2.环境准备复制一个虚拟机,修改MAC地址,ip,主机名等[root@kylin-10-sp3~]#hostnamectlset-hostnamekylin-sp3-cllient[root@kylin-10-sp3~]#[root@kylin-sp3-cllient~]#vim/etc/sysconfig/network-scripts/ifcfg-ens33[root@kylin-sp3-cllient~]#角......
  • docker php和nginx的通信
    1安装网络dockernetworkcreatephpClassExamples_network2安装nginx2.1生成临时容器dockerrun-it--nametest_nginx-dnginx查看临时容器内部,找到关键目录1、工作目录:lsusr/share/nginx/html 2、配置目录lsetc/nginx/conf.d3、日志目录lsvar......
  • traefik对比nginx ingress优点
    Traefik和NGINXIngressController是Kubernetes中常用的反向代理和负载均衡解决方案。它们各自有其优点和适用场景。以下是Traefik相对于NGINXIngress的一些主要优点:1.动态配置优点:Traefik可以自动发现新服务,并动态更新其路由配置,而不需要重新加载配置。这使得在......
  • YOLOv8改进实战 | 注意力篇 | 引入ICCV2023顶会LSKNet:大选择性卷积注意力模块LSKA,助力
    YOLOv8专栏导航:点击此处跳转前言YOLOv8是由YOLOv5的发布者Ultralytics发布的最新版本的YOLO。它可用于对象检测、分割、分类任务以及大型数据集的学习,并且可以在包括CPU和GPU在内的各种硬件上执行。YOLOv8是一种尖端的、最先进的(SOTA)模型,它建立在以前......
  • Qt5 中常用的模块列表:
    以下是Qt5中常用的模块列表:核心模块(Core):提供了Qt核心功能,包括对象模型、信号与槽机制、事件处理等。图形模块(Gui):提供了绘图和窗口系统集成功能,包括绘图API、事件处理、窗口管理等。窗口部件模块(Widgets):包含了各种常用的用户界面控件,如按钮、文本框、列表框等。网络模块(Netwo......
  • CMake中添加Qt模块的合理方法
    https://www.jianshu.com/p/7eeb6f79a275转载自这里用CMake来组织的工程中要用Qt首先要设置、找到Qt相关模块。主要是通过find_package这个CMake命令。但网上很多教程都过时了,或者不够清晰灵活。因为这部分很常用,所以特别用一篇文章把我们目前在生产环境中使用的方法给大家介......
  • HarmoryOS 网络请求模块及Axios库的封装
            我们在使用DevEecStudio进行网络请求时,需选择一个稳定、高效的网络库作为基础,如Axios、FetchAPI、Moya等;需要对网络请求的基本配置进行统一设定,比如基础URL、超时时间、默认请求头等;要进行错误处理:封装时应该考虑各种可能的错误情况,并提供统一的错误处理逻......