1.查看nginx支持的模塊
nginx -V
[root@www ~]# /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
2.nginx平滑升級
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.備份二進制文件,用新版的替換
新的nginx 二進制文件在objs目錄下
3確保配置文件正確(-t)
4.發送USR2信號,Nginx會啟動一個新版本的master進程和對應工作進程
[root@www 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
[root@www sbin]# kill -USR2 3737
[root@www 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處理
[root@www sbin]# kill -WINCH 3737
[root@www 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信息
[root@www sbin]# kill -QUIT 3737
[root@www 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之前操作)
[root@localhost ~]# kill -HUP 3737