ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Nginx平滑升级实操

2021-06-16 11:00:20  阅读:190  来源: 互联网

标签:00 nginx 0.0 平滑 1.19 Nginx 实操 root


1.查看旧版nginx的编译参数

[root@Nginx ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
configure arguments: --with-http_stub_status_module

2.编译新版本Nginx源码包,安装路径需与旧版一致,注意:不要执行make install

[root@Nginx ~]# tar xf nginx-1.19.9.tar.gz 
[root@Nginx ~]# cd nginx-1.19.9
[root@Nginx nginx-1.19.9]# ./configure --with-http_stub_status_module
[root@Nginx nginx-1.19.9]# make

3.备份二进制文件,用新版本的替换

[root@Nginx nginx-1.19.9]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
[root@Nginx nginx-1.19.9]# cp objs/nginx /usr/local/nginx/sbin/

4.确保配置文件无报错

[root@Nginx nginx-1.19.9]# /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

5.发送USR2信号
向主进程(master)发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程,和旧版一起处理请求

[root@Nginx nginx-1.19.9]# ps aux | grep nginx
root       1050  0.0  0.0  20560   612 ?        Ss   17:57   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     1051  0.0  0.1  21012  1312 ?        S    17:57   0:00 nginx: worker process
root       3601  0.0  0.0 112824   984 pts/0    R+   17:58   0:00 grep --color=auto nginx
[root@Nginx nginx-1.19.9]# kill -USR2 1050
[root@Nginx nginx-1.19.9]# ps aux | grep nginx
root       1050  0.0  0.0  20560   796 ?        Ss   17:57   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     1051  0.0  0.1  21012  1312 ?        S    17:57   0:00 nginx: worker process
root       3602  0.0  0.1  20576  1596 ?        S    17:59   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     3603  0.0  0.1  21012  1044 ?        S    17:59   0:00 nginx: worker process
root       3605  0.0  0.0 112824   984 pts/0    R+   17:59   0:00 grep --color=auto nginx

6.发送WINCH信号
向旧的Nginx主进程(master)发送WINCH信号,它会逐步关闭自己的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理

[root@Nginx nginx-1.19.9]# kill -WINCH 1050
[root@Nginx nginx-1.19.9]# ps aux | grep nginx
root       1050  0.0  0.0  20560   796 ?        Ss   17:57   0:00 nginx: master process /usr/local/nginx/sbin/nginx
root       3602  0.0  0.1  20576  1596 ?        S    17:59   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     3603  0.0  0.1  21012  1044 ?        S    17:59   0:00 nginx: worker process
root       3607  0.0  0.0 112824   984 pts/0    R+   18:00   0:00 grep --color=auto nginx

注意:回滚步骤,发送HUP信号
如果这时需要回退继续使用旧版本,可向旧的Nginx主进程发送HUP信号,它会重新启动工作进程, 仍使用旧版配置文件。然后可以将新版Nginx进程杀死(使用QUIT、TERM、或者KILL)

7.发送QUIT信号
升级完毕,可向旧的Nginx主进程(master)发送(QUIT、TERM、或者KILL)信号,使旧的主进程退出

[root@Nginx nginx-1.19.9]# kill -QUIT 1050
[root@Nginx nginx-1.19.9]# ps aux | grep nginx
root       3602  0.0  0.1  20576  1596 ?        S    17:59   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     3603  0.0  0.1  21012  1044 ?        S    17:59   0:00 nginx: worker process
root       3623  0.0  0.0 112824   984 pts/0    S+   18:01   0:00 grep --color=auto nginx

8.验证nginx版本号,并访问测试

[root@Nginx nginx-1.19.9]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.19.9

标签:00,nginx,0.0,平滑,1.19,Nginx,实操,root
来源: https://blog.csdn.net/qq_45520784/article/details/117950047

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有