当前位置: 首页 > news >正文

【nginx平滑升级演示】

目录

1 、Nginx平滑升级原理

2 、Nginx信号

2.1、主进程支持的信号

2.2、 工作进程支持的信号

3、 平滑升级

3.1 、Nginx添加新模块

1 、Nginx平滑升级原理

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

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

  • 新进程接受新请求。

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

2 、Nginx信号

2.1、主进程支持的信号

TERM,INT:立刻退出;

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

KILL:强制终止进程;

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

USR1:重新打开日志文件;

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

WINCH:逐步关闭工作进程。

2.2、 工作进程支持的信号

TERM,INT:立刻退出;

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

USR1:重新打开日志文。

3、 平滑升级

案例:

3.1 、Nginx添加新模块

在已编译安装Nginx的基础上添加/home/nginx_upstream_check_module-master模块。

(1)进入Nginx解压目录

[root@localhost ~]# cd nginx-1.25.3/

(2)查看Nginx已安装的模块

[root@localhost nginx-1.25.3]# nginx -V
nginx version: nginx/1.25.3
built by gcc 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC) 
built with OpenSSL 3.0.7 1 Nov 2022
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx25 --user=nginx --group=nginx --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-openssl-opt=yes --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug

(3)添加新模块

[root@localhost nginx-1.27.3]# ./configure --prefix=/usr/local/nginx25 --user=nginx --group=nginx --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-openssl-opt=yes --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --add-module=/home/nginx_upstream_check_module-master && make

(4)进行make操作

按照原来的编译参数安装 nginx 的方法进行安装,只需要到 make,千万不要 make install 。如果make install 会将原来的配置文件覆盖。

(5)备份原Nginx二进制文件

[root@localhost nginx-1.27.3]# mv /usr/local/nginx25/sbin/nginx /usr/local/nginx25/sbin/nginx.bak

(6)复制新的nginx二进制文件,进入新的nginx源码包

[root@localhost nginx-1.27.3]# cp objs/nginx /usr/local/nginx25/sbin

(7)测试新版本的nginx是否正常

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

(8)给nginx发送平滑迁移信号

若不清楚Nginx.pid的路径,可查看nginx配置文件,里面有对应的路径。

[root@localhost nginx-1.27.3]# kill -USR2 `cat /usr/local/nginx25/logs/nginx.pid `
[root@localhost nginx-1.27.3]# ps -aux | grep nginx
root       88555  0.0  0.1  10112  2572 ?        Ss   20:52   0:00 nginx: master process /usr/local/nginx25/sbin/nginx
nginx      88556  0.0  0.2  13864  5260 ?        S    20:52   0:00 nginx: worker process
root       88948  0.0  0.3  10112  6656 ?        S    20:54   0:00 nginx: master process /usr/local/nginx25/sbin/nginx
nginx      88949  0.0  0.2  13864  5260 ?        S    20:54   0:00 nginx: worker process
root       89341  0.0  0.1 221680  2432 pts/1    S+   20:56   0:00 grep --color=auto nginx

(9)查看nginx pid,会出现一个nginx.pid.oldbin

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

[root@localhost nginx-1.27.3]# ll /usr/local/nginx25/logs/
总用量 12
-rw-r--r--. 1 root root   0  9月 29 20:00 access.log
-rw-r--r--. 1 root root 879  9月 29 20:55 error.log
-rw-r--r--. 1 root root   6  9月 29 20:54 nginx.pid
-rw-r--r--. 1 root root   6  9月 29 20:52 nginx.pid.oldbin

(10)关闭旧的Nginx进程

[root@localhost nginx-1.27.3]# kill -WINCH `cat /usr/local/nginx25/logs/nginx.pid.oldbin`
[root@localhost nginx-1.27.3]# !ps
ps -aux | grep nginx
root       88555  0.0  0.1  10112  2572 ?        Ss   20:52   0:00 nginx: master process /usr/local/nginx25/sbin/nginx
root       88948  0.0  0.3  10112  6656 ?        S    20:54   0:00 nginx: master process /usr/local/nginx25/sbin/nginx
nginx      88949  0.0  0.2  13864  5260 ?        S    20:54   0:00 nginx: worker process
root       90196  0.0  0.1 221680  2432 pts/1    S+   20:59   0:00 grep --color=auto nginx

(11)结束工作进程,完成此次升级

[root@localhost nginx-1.27.3]# kill -QUIT `cat /usr/local/nginx25/logs/nginx.pid.oldbin`
[root@localhost nginx-1.27.3]# !ps
ps -aux | grep nginx
root       88948  0.0  0.3  10112  6656 ?        S    20:54   0:00 nginx: master process /usr/local/nginx25/sbin/nginx
nginx      88949  0.0  0.2  13864  5260 ?        S    20:54   0:00 nginx: worker process
root       90592  0.0  0.1 221680  2432 pts/1    S+   21:01   0:00 grep --color=auto nginx

(12)验证Nginx是否升级成功

[root@localhost nginx-1.27.3]# nginx -v
nginx version: nginx/1.27.3

http://www.dtcms.com/a/423104.html

相关文章:

  • 桥梁缺陷检测数据集:腐蚀、剥落、渗透等5类,3k+图像,yolo标注
  • 上交提出单图生成3D场景方法SceneGen:单图输入,多资源输出,3D 合成性能飙升的“秘密武器”!
  • 百度验证网站济南网络科技公司
  • NO5.硼:火箭专家
  • 细化处理refinement process
  • 第四部分:VTK常用类详解(第120章 vtkWarpTo变形到类)
  • Day01_Linux移植基础
  • 工控网做网站维护吗免费网站建站申请
  • kcwebplus可视化框架
  • JVM如何管理直接内存?
  • 【完整源码+数据集+部署教程】医疗设备显示器图像分割系统: yolov8-seg-C2f-SCConv
  • PyCharm项目依赖库的备份与还原方法
  • OpenSSL 3.0对某些加密算法增加了限制
  • git fatal:Server aborted the SSL handshake
  • 深入理解 Python `ssl` 库:安全通信的基石
  • 江门网页建站模板临沂网站建设费用
  • 网站手机模板和pc模板要分开做网站首页需求
  • 国内 huggingfaces 仓下载
  • 基因组学发展史
  • 论文阅读(第4章,page55)
  • java设计模式:适配器模式
  • 做微商网站制作迪虎科技网站建设
  • Cobalt Strike 学习笔记(1)
  • 学习React-20-useId
  • 掌中智汇,运筹帷幄 - 全新ASUS华硕智汇商擎小程序上线
  • 如何查询网站开发奔牛网络推广
  • 企业网站开发的功能百度seo优
  • 设计模式(C++)详解——备忘录模式(2)
  • 学习:uniapp全栈微信小程序vue3后台(30)
  • centos建设网站推广软文怎么写