系统相关
首页 > 系统相关> > Nginx平滑升级实操

Nginx平滑升级实操

作者:互联网

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