zoukankan      html  css  js  c++  java
  • Nginx 平滑升级

     1、上传新版本的源码包(旧版本是1.14.2,新版本是1.16.0)

    [root@localhost ~]# ls
    anaconda-ks.cfg  nginx-1.14.2.tar.gz  nginx-1.16.0.tar.gz

    2、解压,解压到原路径

    [root@localhost ~]# tar -xf nginx-1.16.0.tar.gz -C /usr/src/

    3、获取旧版本的编译安装信息

    [root@localhost ~]# nginx -V
    nginx version: nginx/1.14.2
    built by gcc 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) 
    built with OpenSSL 1.0.1e-fips 11 Feb 2013
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module

    4、切换到解压路径下编译新版本的源码包,不需要执行安装(不需要执行make  install)

    [root@localhost ~]# cd /usr/src/nginx-1.16.0/
    [root@localhost nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module && make

    5、备份二进制文件,用新版nginx替换旧版nginx

    [root@localhost ~]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
    [root@localhost ~]# ls /usr/local/nginx/sbin/
    nginx.old
    [root@localhost ~]# cp /usr/src/nginx-1.16.0/objs/nginx /usr/local/nginx/sbin/
    [root@localhost ~]# ls /usr/local/nginx/sbin/
    nginx  nginx.old

    6、查看配置文件,确保正确

    [root@localhost ~]# nginx -t
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

    7、发送USR2信号

    向主进程(master)发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程,和旧版一起处理请求

    复制代码
    [root@localhost ~]# ps aux | grep nginx | grep -v grep
    
    root 4108 0.0 0.2 45028 1152 ? Ss 16:58 0:00 nginx: master process /usr/local/nginx/sbin/nginx
    nginx      4109  0.0  0.4  45456  2012 ?        S    16:58   0:00 nginx: worker process 
    [root@localhost ~]# kill -USR2 4108
    [root@localhost ~]# ps aux | grep nginx | grep -v grep
    root       4108  0.0  0.2  45028  1316 ?        Ss   16:58   0:00 nginx: master process /usr/local/nginx/sbin/nginx
    nginx      4109  0.0  0.4  45456  2012 ?        S    16:58   0:00 nginx: worker process      
    root       6605  0.5  0.6  45196  3364 ?        S    17:02   0:00 nginx: master process /usr/local/nginx/sbin/nginx
    nginx      6607  0.0  0.3  45624  1756 ?        S    17:02   0:00 nginx: worker process
    复制代码

    8、发送WINCH信号

    向旧的Nginx主进程(master)发送WINCH信号,它会逐步关闭自己的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理

    [root@localhost ~]# kill -WINCH 4108
    [root@localhost ~]# ps aux | grep nginx | grep -v grep
    root       4108  0.0  0.2  45028  1320 ?        Ss   16:58   0:00 nginx: master process /usr/local/nginx/sbin/nginx
    root       6605  0.0  0.6  45196  3364 ?        S    17:02   0:00 nginx: master process /usr/local/nginx/sbin/nginx
    nginx      6607  0.0  0.3  45624  1756 ?        S    17:02   0:00 nginx: worker process

    9、发送QUIT信号

    升级完毕,可向旧的Nginx主进程(master)发送(QUIT、TERM、或者KILL)信号,使旧的主进程退出

    [root@localhost ~]# kill -QUIT 4108
    [root@localhost ~]# ps aux | grep nginx | grep -v grep
    root       6605  0.0  0.6  45196  3364 ?        S    17:02   0:00 nginx: master process /usr/local/nginx/sbin/nginx
    nginx      6607  0.0  0.4  45624  2056 ?        S    17:02   0:00 nginx: worker process

    10、验证nginx版本号,并访问测试

    复制代码
    [root@localhost ~]# curl -I 127.0.0.1
    HTTP/1.1 200 OK
    Server: nginx/1.16.0
    Date: Sun, 18 Aug 2019 13:34:07 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Sun, 18 Aug 2019 13:26:08 GMT
    Connection: keep-alive
    ETag: "5d5951f0-264"
    Accept-Ranges: bytes
    复制代码
  • 相关阅读:
    Backbone中的model和collection在做save或者create操作时, 如何选择用POST还是PUT方法 ?
    Spring boot: Request method 'DELETE' not supported, Request method 'PUT' not supported, Request method 'POST' not supported
    Backbone.js 中的Model被Destroy后,不能触发success的一个原因
    eclipse里打开SWT项目找不到source/design的图形UI设计界面
    RHEL5.6配置本地yum源
    Linux环境下Apache反向代理金蝶中间件Apusic集群
    Linux环境下源码安装Apache2.2.25
    WIN7中Beyond Compare报错误“应用程序发生错误” 无法启动
    使用Navicat迁移MySQL数据至Oracle时大小写原因报“表或视图不存在”问题处理
    -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match问题处理
  • 原文地址:https://www.cnblogs.com/2567xl/p/11571298.html
Copyright © 2011-2022 走看看