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. 日常2018/4/9---b/s和c/s架构分别是什么?区别?

    b/s和c/s架构分别是什么?区别? b/s是指前后端分别是 Browser/Server的模式.(3层c/s模式) c/s是指前后端分别是 Client/Server的模式.(2层c/s模式) c/ ...

  2. 1203 forms组件

    目录 昨日内容 多对多三种创建方式 1.全自动 好处 缺点 2.纯手动 好处 缺点 3.半自动through='',through_fields=(外键字段) 好处 缺点 forms组件 1.简单引入 ...

  3. 在vue中使用css预编辑器

    vue中使用less 安装less依赖,npm install less less-loader --save vue中使用sass npm install --save-dev sass-loade ...

  4. 使用 IDEA 打包spring cloud 成 jar在ubuntu 中运行

    1.  打开终端 termial   ,  使用 mvn  install  . 如果提示  mvn 不是xx 命令 ; 2 则需要配置环境变量  :  path :     C:\Program F ...

  5. myeclipse不同版本共存破解办法

    我自己破解的是myeclipse10+myeclipse2018: 方法是:先破解myeclipse10.7,使用破解工具,到最后一步不关闭破解工具,再进行替换文件那一步,路径不选择10版本的,换成M ...

  6. 案例(拖拽对话框、高清放大镜、自制滚动条、元素的隐藏方式、表格隔行变色、tab切换效果、字符串拼接、刷新评论)

    一.拖拽对话框 <style> .of{ width: 500px; } #link,#close{ text-decoration: none; margin: 0 10px; font ...

  7. xfce 快捷键 命令整理

    本文链接:https://blog.csdn.net/cFarmerReally/article/details/53375956 转载自:https://my.oschina.net/u/56535 ...

  8. Word 有哪些神奇的功能?

    作者:秦阳链接:https://www.zhihu.com/question/27035859/answer/621742048来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  9. HDU 6129 Just do it ——(找规律)

    思路见:http://blog.csdn.net/qq_32506797/article/details/77206167. 利用二进制讲m次转化成log次然后进行转移. 代码如下: #include ...

  10. Js 之生成二维码插件(jquery.qrcode.js)

    一.下载 链接:https://pan.baidu.com/s/1cMjaCYQ_buZNT5XRRjuNTA提取码:myqm 二.效果图 三.代码 <!DOCTYPE html> < ...