nginx在使用过程中,有时需要在不影响当前业务的情况下,进行升级或新增模块。nginx的升级有两种方法:1.半自动化升级;2.手动升级

  不过都需要先查看安装的nginx版本和配置信息,然后前往官网下载所需的版本,并上传

[root@youxi1 ~]# nginx -V
nginx version: nginx/1.14.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module
--with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.41 --user=nginx --group=nginx

  下载地址:http://nginx.org/en/download.html

一、半自动化升级

  半自动化升级,其实就是在最后迁移的时候不使用make install,而使用源码自带的升级命令make upgrade来自动完成。

(1).解压文件,并编译(只编译不安装)

  只编译不安装。./configure后面的参数可以保持一致,也可以改动;另外我这里指定了--with-pcre,需要保证后面的参数存在。

[root@youxi1 ~]# tar zxf nginx-1.16.0.tar.gz -C /usr/local/src/
[root@youxi1 ~]# cd /usr/local/src/nginx-1.16.0/
[root@youxi1 nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.41 --user=nginx --group=nginx
[root@youxi1 nginx-1.16.0]# make -j 4  //这里指定的是CPU内核数量,加快编译速度
[root@youxi1 nginx-1.16.0]# echo $?
0

(2).备份旧的二进制文件,复制新的二进制文件到nginx目录

[root@youxi1 nginx-1.16.0]# mv /usr/local/nginx/sbin/nginx{,.old}  //备份
[root@youxi1 nginx-1.16.0]# cp objs/nginx /usr/local/nginx/sbin/  //复制

(3).执行升级语句

[root@youxi1 nginx-1.16.0]# make upgrade
/usr/local/nginx/sbin/nginx -t  //查看配置文件是否正确,这里使用的是刚复制过来的nginx二进制文件
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
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`  //发送平滑迁移信号给旧的nginx进程
sleep 1  //等待1秒
test -f /usr/local/nginx/logs/nginx.pid.oldbin  //检测旧的nginx.pid进程是否变为nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`  //结束工作进程,完成此次升级

  test -f [文件]如果为一个普通文件,则为真。这里用来判断文件是否存在。

  手动升级其实就是使用打印出来的这些语句,加上kill –WINCH `cat /usr/local/nginx/log/nginx.pid.oldbin`(从容关闭nginx.pid.oldbin)和kill –HUP `cat /url/local/nginx/log/nginx.pid.oldbin`(不重启旧的nginx进程)。

(4).检测是否升级成功

  首先看看是否正在运行

[root@youxi1 nginx-1.16.0]# ps aux | grep nginx  //查看是否正常运行,如果之前就能使用systemctl,也可以使用systemctl查看
nginx 1338 0.0 0.1 216972 6244 ? S 13:08 0:00 php-fpm: pool www
nginx 1340 0.0 0.1 216972 6244 ? S 13:08 0:00 php-fpm: pool www
root 7556 0.0 0.0 18252 1728 ? S 17:05 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 7557 0.0 0.0 18624 1360 ? S 17:05 0:00 nginx: worker process
root 7563 0.0 0.0 112724 988 pts/0 S+ 17:06 0:00 grep --color=auto nginx

  接着看看配置文件是否有错,还有nginx的版本和配置选项信息。我能直接使用nginx是因为配置了环境变量。

[root@youxi1 nginx-1.16.0]# 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@youxi1 nginx-1.16.0]# nginx -V  //查看版本和配置选项信息
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.41 --user=nginx --group=nginx

  最后使用Windows查看

二、手动升级

  手动升级和半自动化升级大同小异,只是在执行升级语句时,手动输入打印的命令

(1).解压文件并编译

  只编译不安装。./configure后面的参数可以保持一致,也可以改动;另外我这里指定了--with-pcre,需要保证后面的参数存在。

[root@youxi1 ~]# tar zxf nginx-1.16.0.tar.gz -C /usr/local/src/
[root@youxi1 ~]# cd /usr/local/src/nginx-1.16.0/
[root@youxi1 nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.41 --user=nginx --group=nginx
[root@youxi1 nginx-1.16.0]# make -j 4  //这里指定的是CPU内核数量,加快编译速度
[root@youxi1 nginx-1.16.0]# echo $?
0

(2).备份旧的二进制文件,复制新的二进制文件到nginx目录

[root@youxi1 nginx-1.16.0]# mv /usr/local/nginx/sbin/nginx{,.old}  //备份
[root@youxi1 nginx-1.16.0]# ls /usr/local/nginx/sbin/
nginx.old
[root@youxi1 nginx-1.16.0]# cp objs/nginx /usr/local/nginx/sbin/  //复制
[root@youxi1 nginx-1.16.0]# ls /usr/local/nginx/sbin/
nginx nginx.old

(3).执行取代make upgrade的命令

  注意:这里的nginx.pid(nginx进程文件)所在地址不是固定的,需要查看nginx目录下的conf/nginx.conf配置文件

[root@youxi1 nginx-1.16.0]# /usr/local/nginx/sbin/nginx -t  //查看配置文件是否正确,这里使用的是刚复制过来的nginx二进制文件
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@youxi1 nginx-1.16.0]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`    //发送平滑迁移信号给旧的nginx
[root@youxi1 nginx-1.16.0]# test -f /usr/local/nginx/logs/nginx.pid.oldbin  //我们判断是否平滑迁移到nginx.pid.oldbin,test -f与echo $?的组合
[root@youxi1 nginx-1.16.0]# echo $?
0
[root@youxi1 nginx-1.16.0]# ls /usr/local/nginx/logs/nginx.pid*  //判断是否平滑迁移也可以ls命令查看是否存在nginx.pid.oldbin文件
/usr/local/nginx/logs/nginx.pid /usr/local/nginx/logs/nginx.pid.oldbin
[root@youxi1 nginx-1.16.0]# kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`  //从容关闭nginx进程
[root@youxi1 nginx-1.16.0]# kill -HUP `cat /usr/local/nginx/logs/nginx.pid.oldbin`  //不重启旧的nginx进程
[root@youxi1 nginx-1.16.0]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`  //结束工作进程,完成此次升级

  test -f [文件]和echo $?组合判断平滑迁移,与直接ls [文件]判断平滑迁移只要使用一个就可以了。

(4).检测是否升级成功

  首先看看是否正在运行

[root@youxi1 nginx-1.16.0]# ps aux | grep nginx
nginx 1307 0.0 0.1 216972 6244 ? S 10:34 0:00 php-fpm: pool www
nginx 1308 0.0 0.1 216972 6244 ? S 10:34 0:00 php-fpm: pool www
root 7476 0.0 0.0 18252 1728 ? S 10:45 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 7477 0.0 0.0 18624 1360 ? S 10:45 0:00 nginx: worker process
nginx 7493 0.0 0.0 18600 1344 ? S 10:47 0:00 nginx: worker process
root 7571 0.0 0.0 112724 988 pts/0 S+ 11:08 0:00 grep --color=auto nginx

  接着看看配置文件是否有错,还有nginx的版本和配置选项信息。我能直接使用nginx是因为配置了环境变量。

[root@youxi1 nginx-1.16.0]# nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module
--with-http_flv_module --with-http_mp4_module --with-pcre=/usr/local/src/pcre-8.41 --user=nginx --group=nginx

  最后使用Windows查看

参考:https://blog.csdn.net/xiaolong20081/article/details/82871878

   https://www.cnblogs.com/happlyp/p/6090409.html

Nginx在线服务状态下平滑升级或新增模块的更多相关文章

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

    今天应开发的需求,需要在Nginx增加一个模块,并不能影响现有的业务,所以就必须要平滑升级Nginx,好了,不多说了 1:查看现有的nginx编译参数 /usr/local/nginx/sbin/ng ...

  2. Nginx在线服务状态下平滑升级及ab压力测试【转】

    今天,产品那边发来需求,说有个 APP 的 IOS 版本下载包需要新增 https 协议,在景安购买了免费的 SSL 证书.当我往 nginx 上新增 ssl 时,发现服务器上的 nginx 居然没编 ...

  3. Linux下平滑升级nginx

    一.升级前准备 1.对nginx的配置文件nginx.conf做备份: 2.新建目录/root/nginx,将安装包和脚本上传到该目录下: 二.平滑升级nginx 1.开始编译新版本的nginx cd ...

  4. Nginx编译安装和平滑升级

    一.Nginx的编译安装 1.安装依赖包gcc,gcc-c++,pcre,openssl-devel 命令:yum -y install gcc gcc-c++ pcre-devel openssl- ...

  5. nginx : TCP代理和负载均衡的stream模块

    一直以来,Nginx 并不支持tcp协议,所以后台的一些基于TCP的业务就只能通过其他高可用负载软件来完成了,比如Haproxy. 这算是一个nginx比较明显的缺憾.不过,在1.90发布后这个认知将 ...

  6. Nginx版本平滑升级方案

    背景:由于负载均衡测试服务器中nginx版本过低,存在安全漏洞,查询相关修复漏洞资料,需要采取nginx版本升级形式对漏洞进行修复. Nginx平滑升级方案 1.案例采用版本介绍 旧版本 nginx- ...

  7. 源码安装nginx以及平滑升级

                                                           源码安装nginx以及平滑升级                               ...

  8. Nginx服务器的平滑启动、平缓停止、平滑升级

    注:Nginx服务在运行时,会保持一个主进程(master process)和一个或多个工作进程(worker process). 每一个进程都会有一个PID进程号,可以通过向主进程的PID进程号发送 ...

  9. 让你的网站免费支持 HTTPS 及 Nginx 平滑升级

    为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上加入了 SSL 层,在传输层对网络连接进行加密.简单点说在 ...

随机推荐

  1. 牛客练习赛6 C 手铐

    手铐 思路: 缩环+树形dp 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include& ...

  2. P1313 计算系数[二项式定理]

    题目描述 给定一个多项式\((by+ax)^k\),请求出多项式展开后\(x^n \times y^m\)项的系数. 解析 一道水题,二项式定理搞定.注意递推组合数时对其取模. 参考代码 #inclu ...

  3. EntityFramework 事物引发的问题

    前记 还是最近做的日志模块,今天做最后的入库工作.在测试入库日志记录时,总是出现怪异的问题. 开启服务开始接收 Kafka 的消息,第一条数据没有问题,后面的都如不了库.很是懵~~~ 调试了很久定位在 ...

  4. 《hello-world团队》第七次作业:团队项目设计完善&编码

    项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十一 团队作业7:团队项目设计完善&编码 团队名称 <hello--w ...

  5. 前端学习笔记--CSS样式--背景和超链接

    1.背景 2.超链接: 举例:

  6. 基于pg_qualstats和hypopg的自动索引调优

    pg-qualstats的安装和配置 1.安装pg-qualstats -pg-qualstats 2.将pg_qualstats和pg_stat_statements添加到shared_preloa ...

  7. unity里blit的load store action设置

    做blit的 load store action时 用 setrendertarget做 之后blit 参数用 BuiltinRenderTextureType.CurrentActive https ...

  8. jQuery相关方法10

    一.链式编程的原理 <script> //构造函数 function Person(age){ this.age=age; this.sayHi=function(txt){ if(txt ...

  9. BP神经网络原理及在Matlab中的应用

    一.人工神经网络 关于对神经网络的介绍和应用,请看如下文章 ​ 神经网络潜讲 ​ 如何简单形象又有趣地讲解神经网络是什么 二.人工神经网络分类 按照连接方式--前向神经网络.反馈(递归)神经网络 按照 ...

  10. unbuntu16.04安装geoserver运行环境

    1.下载并上传 在windows下载geoserver 2.15.1Platform Independent Binary版本, 是zip文件,然后使用xfile将zip上传到/usr/geoserv ...