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

    Nginx平滑升级
    一.上传新版本的Nginx源码包
    [root@localhost ~]# rz               #上传自己新版本的Nginx源码包
    [root@localhost ~]# ls                #查看
    nginx-1.16.1.tar.gz     
    nginx-1.17.3.tar.gz  
    [root@localhost ~]# tar xf nginx-1.17.3.tar.gz -C /usr/src/           #将软件包解包
     
    二.查看老版本的Nginx编译安装信息
    [root@localhost ~]# nginx -V                 #获取到老版本的Nginx编译安装信息
    nginx version: nginx/1.16.1
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (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-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module
     
    三.将新版本的源码包进行编译,但不执行安装(make install)
    [root@localhost ~]#cd /usr/src/nginx-1.17.3/
    [root@localhost nginx-1.17.3]# ./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  
     
    四.将二进制文件进行备份,用新版替换旧的
    [root@localhost ~]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/old.nginx
    [root@localhost ~]# ls /usr/local/nginx/sbin/
    old.nginx
    [root@localhost ~]# cp /usr/src/nginx-1.17.3/objs/nginx /usr/local/nginx/sbin/
    [root@localhost ~]# ls /usr/local/nginx/sbin/
    nginx  old.nginx
     
    五.确保文件不会进行报错
    [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
    [root@localhost ~]# /usr/local/nginx/sbin/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
     
    六.发送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
     
    七.发送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

    八.发送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

    九.验证nginx版本号,并访问测试
    [root@localhost ~]# nginx -V                                 #查看新版本信息
    nginx version: nginx/1.17.3
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (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-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module
    [root@localhost ~]# curl -I 127.0.0.1                    #进行访问测试
    HTTP/1.1 200 OK
    Server: nginx/1.17.3
    Date: Fri, 20 Sep 2019 02:06:04 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 612
    Last-Modified: Thu, 19 Sep 2019 04:59:53 GMT
    Connection: keep-alive
    ETag: "5d830b49-264"
    Accept-Ranges: bytes
     
     
  • 相关阅读:
    STM8S TIM4库函数应用
    几种更新(Update语句)查询的方法
    CentOS 配置httpd使局域网能够正常訪问
    天将降大任于斯人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为,所以动心忍性,增益其所不能
    Numeral.js 是一个用于格式化和数字四则运算的js 库
    SVN高速新手教程
    我的Android开发相关文章
    cocos2d-x游戏开发实战原创视频讲座系列1之2048游戏开发
    运动检测(前景检测)之(一)ViBe
    linux概念之分区与文件系统
  • 原文地址:https://www.cnblogs.com/ZCQ123456/p/11555256.html
Copyright © 2011-2022 走看看