首页 > 用户投稿

二进制文件更新程序(Nginx升级)

二进制文件更新程序(nginx升级)

一、前言

nginx在使用过程中,有时需要在不影响当前业务的情况下,进行升级或新增模块。

nginx实现了平滑升级。其原理简单概括,就是:

二进制文件更新程序(Nginx升级)

①在不停掉老进程的情况下,启动新进程。

②老进程负责处理仍然没有处理完的请求,但不再接受处理请求。

③新进程接受新请求。

④老进程处理完所有请求,关闭所有连接后,停止。

这样就很方便可在不中断服务的情况下,实现nginx平滑升级。

nginx信号简介

主进程支持的信号

term,int:立刻退出

quit:等待工作进程结束后再退出

kill:强制终止进程

hup:重新加载配置文件,使用新的配置启动工作进程,并逐步关闭旧进程。

usr1:重新打开日志文件

usr2:启动新的主进程,实现热升级

winch:逐步关闭工作进程

工作进程支持的信号

term,int:立刻退出

quit:等待请求处理结束后再退出

usr1:重新打开日志文件

注:如果是yum安装的nginx,升级就很简单了,使用nginx官方yum源直接yumupdatenginx即可升级最新版。

本文介绍nginx从1.18.0版本升级至1.20.0版本,不新增模块。不赘述nginx-v1.18.0版本的编译安装,只描述升级过程。

二、查看当前版本及编译参数

本文nginx安装目录路径为:/usr/local/nginx/

/usr/local/nginx/sbin/nginx-v

##详细编译参数如下

--user=nginx--group=nginx--prefix=/usr/local/nginx--error-log-path=/data/logs/nginx/error.log--lock-path=/usr/local/nginx/var/nginx.lock--with-http_v2_module--with-http_ssl_module--with-http_flv_module--with-http_addition_module--with-http_stub_status_module--with-http_gzip_static_module--with-http_degradation_module--without-http_memcached_module--with-file-aio--with-http_image_filter_module--with-http_realip_module--with-pcre=/data/tools/pcre-8.44--with-pcre-jit--with-ld-opt=-ljemalloc

##访问测试

三、手动升级

1.下载新版本软件包解压并编译

只编译不安装。./configure后面的参数保持一致;另外本文中指定了--with-pcre,需要保证后面的参数路径存在。

cd/data/toolswgethttp://nginx.org/download/nginx-1.20.0.tar.gztarxfnginx-1.20.0.tar.gzcdnginx-1.20.0/./configure--user=nginx--group=nginx--prefix=/usr/local/nginx--error-log-path=/data/logs/nginx/error.log--lock-path=/usr/local/nginx/var/nginx.lock--with-http_v2_module--with-http_ssl_module--with-http_flv_module--with-http_addition_module--with-http_stub_status_module--with-http_gzip_static_module--with-http_degradation_module--without-http_memcached_module--with-file-aio--with-http_image_filter_module--with-http_realip_module--with-pcre=/data/tools/pcre-8.44--with-pcre-jit--with-ld-opt="-ljemalloc"make-j4  //make这里指定的是cpu内核数量,加快编译速度(根据实际情况修改)

2.备份旧的二进制文件,复制新的二进制文件

//备份mv/usr/local/nginx/sbin/nginx{,.old}//复制cpobjs/nginx/usr/local/nginx/sbin/

3.执行取代makeupgrade的命令

注意:nginx.pid(nginx进程文件)所在目录路径请根据实际情况填写。需要查看nginx目录下的conf/nginx.conf配置文件

//查看配置文件是否正确,使用的是刚复制过来的nginx二进制文件/usr/local/nginx/sbin/nginx-t//发送平滑迁移信号给旧的nginxkill-usr2`cat/usr/local/nginx/logs/nginx.pid`//判断是否平滑迁移到nginx.pid.oldbin,test-f与echo$?的组合test-f/usr/local/nginx/logs/nginx.pid.oldbinecho$?//判断是否平滑迁移也可以ls命令查看是否存在nginx.pid.oldbin文件ls/usr/local/nginx/logs/nginx.pid*//从容关闭nginx进程kill-winch`cat/usr/local/nginx/logs/nginx.pid.oldbin`//不重启旧的nginx进程kill-hup`cat/usr/local/nginx/logs/nginx.pid.oldbin`//结束工作进程,完成此次升级kill-quit`cat/usr/local/nginx/logs/nginx.pid.oldbin`

4.检测是否升级成功

##查看版本和配置选项信息

/usr/local/nginx/sbin/nginx-v

##访问测试

四、使用makeupgrade升级

在最后迁移的时候不使用makeinstall,而使用源码自带的升级命令makeupgrade来自动完成。

1.下载新版本软件包解压并编译

只编译不安装。./configure后面的参数保持一致;另外本文中指定了--with-pcre,需要保证后面的参数路径存在。

cd/data/toolswgethttp://nginx.org/download/nginx-1.20.0.tar.gztarxfnginx-1.20.0.tar.gzcdnginx-1.20.0/./configure--user=nginx--group=nginx--prefix=/usr/local/nginx--error-log-path=/data/logs/nginx/error.log--lock-path=/usr/local/nginx/var/nginx.lock--with-http_v2_module--with-http_ssl_module--with-http_flv_module--with-http_addition_module--with-http_stub_status_module--with-http_gzip_static_module--with-http_degradation_module--without-http_memcached_module--with-file-aio--with-http_image_filter_module--with-http_realip_module--with-pcre=/data/tools/pcre-8.44--with-pcre-jit--with-ld-opt="-ljemalloc"make-j4  //make这里指定的是cpu内核数量,加快编译速度(根据实际情况修改)

2.备份旧的二进制文件,复制新的二进制文件

//备份mv/usr/local/nginx/sbin/nginx{,.old}//复制cd/data/tools/nginx-1.20.0/cpobjs/nginx/usr/local/nginx/sbin/

3.执行升级语句

makeupgrade

##升级过程如下图所示

4.检测是否升级成功

##查看版本和配置选项信息

/usr/local/nginx/sbin/nginx-v

##页面访问测试

原文标题:二进制文件更新程序(Nginx升级),如若转载,请注明出处:https://www.goodstylecd.com/tougao/13945.html
免责声明:此资讯系转载自合作媒体或互联网其它网站,「格调佳」登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,文章内容仅供参考。