泥淖 2020-07-19
nginx -V
[ ~]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.16.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
1.重新编译nginx
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_slice_module&&make
2.备份二进制文件,用新版的替换
3确保配置文件正确(-t)
4.发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程
[ sbin]# ps aux|grep nginx root 3737 0.0 0.1 46116 2324 ? Ss May22 0:00 nginx: master process /usr/local/nginx/sbi root 6262 0.0 0.0 112712 992 pts/1 R+ 21:58 0:00 grep --color=auto nginx www 31013 0.0 0.2 49340 4656 ? S Jun03 0:06 nginx: worker process [ sbin]# kill -USR2 3737 [ sbin]# ps aux|grep nginx root 3737 0.0 0.1 46116 2324 ? Ss May22 0:00 nginx: master process /usr/local/nginx/sbin/nginx root 6373 0.0 0.1 45984 3728 ? S 21:58 0:00 nginx: master process /usr/local/nginx/sbin/nginx www 6374 0.0 0.1 48476 2028 ? S 21:58 0:00 nginx: worker process root 6400 0.0 0.0 112712 992 pts/1 R+ 21:59 0:00 grep --color=auto nginx www 31013 0.0 0.2 49340 4656 ? S Jun03 0:06 nginx: worker process
5.向旧的Nginx主进程(master)发送WINCH信号,它会逐步关闭自己的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理
[ sbin]# kill -WINCH 3737 [ sbin]# ps aux|grep nginx root 3737 0.0 0.1 46116 2324 ? Ss May22 0:00 nginx: master process /usr/local/nginx/sbin/nginx root 6373 0.0 0.1 45984 3728 ? S 21:58 0:00 nginx: master process /usr/local/nginx/sbin/nginx www 6374 0.0 0.1 48476 2028 ? S 21:58 0:00 nginx: worker process root 6758 0.0 0.0 112712 988 pts/1 R+ 22:00 0:00 grep --color=auto nginx
6.发送QUIT信息
[ sbin]# kill -QUIT 3737 [ sbin]# ps aux|grep nginx root 6373 0.0 0.1 45984 3728 ? S 21:58 0:00 nginx: master process /usr/local/nginx/sbin/nginx www 6374 0.0 0.1 48476 2028 ? S 21:58 0:00 nginx: worker process root 7045 0.0 0.0 112712 992 pts/1 R+ 22:02 0:00 grep --color=auto nginx
7.如果需要回滚,发送HUP信号(在6之前操作)
[ ~]# kill -HUP 3737