zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    C#中 类的多态
    字段与属性
    C# ASCII与字符串间相互转换
    TextBox控件常用方法总结
    使用hadoop mapreduce分析mongodb数据:(2)
    使用hadoop mapreduce分析mongodb数据:(1)
    Linux MPI集群配置
    VIM文本替换
    怎么解决python中TypeError: can't pickle instancemethod objects的这个错误
    LeetCode ZigZag problem
  • 原文地址:https://www.cnblogs.com/cljhfy/p/11006256.html
Copyright © 2011-2022 走看看