NGINX动态增加模块,平滑升级

Nginx 添加第三方模块

众所周知Nginx是分成一个个模块的,比如core模块,gzip模块,proxy模块,每个模块负责不同的功能,除了基本的模块,有些模块可以选择编译或不编译进Nginx。官网文档中的Modules reference部分列出了nginx源码包的所有模块。我们可以按照自己服务器的需要来定制出一个最适合自己的Nginx服务器。

除了Nginx官网源码包提供了各种模块,Nginx还有各种各样的第三方模块。官方文档NGINX 3rd Party Modules也列出了Nginx的很多第三方模块,除此官网列出的之外,还有很多很有用的模块也能在Github等网站上找到。

这些模块提供着各种各样意想不到的功能,灵活使用Nginx的第三方模块,可能会有非常大的意外收获。
本篇文章以GitHub上的nginx-module-vts作为例子,此模块可以监控Nginx虚拟主机流量以及状态,下面我们来看一下第三模块的安装以及简单的使用。

下载第三方模块
下载的模块存放在/home/nginx_conf/中

cd /home/nginx_conf/
git clone git://github.com/vozlt/nginx-module-vts.git

添加模块编译Nginx

查看当前Nginx编译参数
shell> nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
添加模块编译
在获取的编译参数中再添加需要的模块

 --add-module= PATH
 # 这里具体路径为
 --add-module=/home/nginx_conf/module/nginx-module-vts

最终的配置如下

shell>./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=/home/nginx_conf/module/nginx-module-vts

执行编译命令:make,注意编译之后千万不能执行make install

编译完后,当前nginx源码目录下生成objs目录则说明编译成功

覆盖Nginx执行脚本

  • 备份当前nginx执行脚本,命令:cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak。如果拷贝出错,则将nginx进行杀掉再进行,命令:killall nginx 或者 nginx -s stop
  • 拷贝上一步骤编译后的新nginx脚本,命令:cp /home/software/nginx-1.14.0/objs/nginx /usr/local/nginx/sbin/
  • 在 home/software/nginx-1.14.0/下载执行make upgrade 平滑升级Nginx
  • 查看编译参数,命令:nginx -V,如果编译参数中存在刚添加的模块,则说明编译成功

使用第三方模块

http {
    vhost_traffic_status_zone;

    ...

    server {

        ...

        location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
    }
}

浏览器输入http://your_ip/status

nginx平滑升级

1 下载更新版本的nginx

wget http://nginx.org/download/nginx-1.16.1.tar.gz

2 查看老版本的配置

nginx -V

nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

复制nginx -V的结果进行输出编译

./configure --prefix=/usr/local/nginx1.15.1 --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

//编译
make && make install

3 重启Nginx的进程

ngins -s stop

/usr/local/nginx1.15.1/sbin/nginx -tc /usr/local/nginx/conf/nginx.conf

/usr/local/nginx1.15.1/sbin/nginx -s start -c /usr/local/nginx/conf/nginx.conf

原文地址:https://www.cnblogs.com/lhanghang/p/12148262.html

时间: 2024-08-29 07:10:47

NGINX动态增加模块,平滑升级的相关文章

nginx重载配置文件及平滑升级

Nginx命令行选项 启动.停止.重启nginx命令 如何重新加载nginx配置文件 nginx程序不重启平滑升级可执行文件 一.Nginx命令行选项 不像许多其他软件系统,Nginx 仅有几个命令行参数,完全通过配置文件来配置 -c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的. -t 不运行,而仅仅测试配置文件.nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件. -v 显示 nginx 的版本. -V 显示 nginx 的版

Nginx 动态添加模块

Nginx动态添加模块 1.首先查看现在已经编译的模块 /usr/local/nginx/sbin/nginx -V 2.下载需要编译的模块 wget https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip 新模块:--add-module=/data/package/nginx_tcp_proxy_module-master/ #模块存放路径 3.进入nginx安装目录 进行重新编译,需要加上之前已经编译过的

Nginx为已安装nginx动态添加模块

本篇文章主要介绍了Nginx之为已安装nginx动态添加模块的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧这里以安装第三方ngx_http_google_filter_module模块为例 nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so 下载第三方扩展模块ngx_http_google_filter_module cd /data/software/ # git clone https://github.com/cuber

Nginx在线服务状态下平滑升级或新增模块的详细操作

今天应开发的需求,需要在Nginx增加一个模块,并不能影响现有的业务,所以就必须要平滑升级Nginx,好了,不多说了 1:查看现有的nginx编译参数 /usr/local/nginx/sbin/nginx -V 2:按照安装nginx的方法进行安装,只需要到make,千万不要make install 3: 备份旧版本的nginx可执行文件(期间nginx不会停止服务) mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

Nginx服务器 安装 与平滑升级详细介绍 &nbsp; 简单使用1

#nginx -V (-V 可以显示出当时的标准,添加了什么模块) [[email protected] nginx-1.8.0]# ./configure --help |grep proxy --without-http_proxy_module        disable ngx_http_proxy_module --http-proxy-temp-path=PATH        set path to store http proxy temporary files --with-

nginx编译安装和平滑升级

1.1.1  本文档为nginx安装及配置文档,主要实现http反向代理功能:作用是将nginx作为前端服务器,通过访问规则代理转发至后端对应的tomcat服务器 部署环境: 系统版本:Linux version 2.6.32-431.el6.x86_64(`cat /proc/version`) 安装及配置: 1安装nginx依赖环境 安装pcre库 #wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.ta

nginx通过shell脚本平滑升级版本

1.简介 有时候nginx发布了新BUG或者添加了新的功能时,想要更新的时候服务又不能中断,这时候就要用到nginx的平滑升级了. 该脚本同样适用于添加新扩展,添加新扩展的时候只需要把更新的版本修改为当前版本,更新的时候把需要添加的扩展加上去即可.我这里nginx安装目录为/usr/local/nginx当前系统,阿里云ECS CentOS 7 64位 2.查看nginx版本与编译信息/usr/local/nginx/sbin/nginx -V 注:这里的扩展要记录下来(重要),等下升级的时候用

Nginx在线服务状态下平滑升级或新增模块

nginx在使用过程中,有时需要在不影响当前业务的情况下,进行升级或新增模块.nginx的升级有两种方法:1.半自动化升级:2.手动升级 不过都需要先查看安装的nginx版本和配置信息,然后前往官网下载所需的版本,并上传 [[email protected] ~]# nginx -V nginx version: nginx/1.14.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --pre

已安装nginx动态添加模块

说明:已经安装好的nginx,需要添加一个未被编译安装的模块,需要怎么弄呢? 具体:这里以安装第三方ngx_http_google_filter_module模块为例nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so1. 下载第三方扩展模块ngx_http_google_filter_module # cd /data/software/# git clone https://github.com/cuber/ngx_http_google_filter_mod