线上系统nginx版本为1.14.0版本,因等保扫描,该版本存在漏洞,故须要对其升级到1.17.3版本,升级需保障线上业务平稳运行,需升级须要平滑升级,不对线上服务形成影响,如下记录本次升级过程nginx
# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.14.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=../fastdfs-nginx-module/src
# cd /home/software # wget http://nginx.org/download/nginx-1.17.3.tar.gz
# cd /home/program # tar -zxvf /home/software/nginx-1.17.3.tar.gz
# cd /home/program/nginx-1.17.3 # ./configure --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=../fastdfs-nginx-module/src # make
cp -rf /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx14.bak
cp -rf objs/nginx /usr/local/nginx/sbin/
# cd /usr/local/nginx/logs/ [root@Gene-redis 2021-04-12 18:38:28 /usr/local/nginx/logs] # ls access.log error.log nginx.pid # kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
此时查看nginx进程就会有两个nginx的主进程,此时老的还在运行以前待处理的请求,新的请求将由新的进程处理请求redis
# ps -ef|grep nginx root 27154 1 0 Mar25 ? 00:00:00 nginx: master process ./nginx nobody 27492 27154 0 Mar25 ? 00:04:42 nginx: worker process root 28681 27154 0 17:20 ? 00:00:00 nginx: master process ./nginx nobody 28682 28681 0 17:20 ? 00:00:00 nginx: worker process root 28684 28533 0 17:20 pts/1 00:00:00 grep --color=auto nginx
而且logs目录下会生成nginx.pid.oldbin文件,里面存放了老版本的pid号ui
# ll total 1417008 -rw-r--r--. 1 root root 1234085629 Apr 12 17:21 access.log -rw-r--r--. 1 root root 82733488 Apr 12 17:21 error.log -rw-r--r-- 1 root root 6 Apr 12 17:20 nginx.pid -rw-r--r-- 1 root root 6 Mar 25 14:59 nginx.pid.oldbin
# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
此时能够看到主进程的状态改变了code
# ps -ef|grep nginx root 27154 1 0 Mar25 ? 00:00:00 nginx: master process ./nginx nobody 27492 27154 0 Mar25 ? 00:04:42 nginx: worker process is shutting down root 28681 27154 0 17:20 ? 00:00:00 nginx: master process ./nginx nobody 28682 28681 0 17:20 ? 00:00:00 nginx: worker process root 28720 28533 0 17:21 pts/1 00:00:00 grep --color=auto nginx
再过一会就只剩一个主进程提供服务了blog
# ps -ef|grep nginx root 28681 27154 0 17:20 ? 00:00:00 nginx: master process ./nginx nobody 28682 28681 0 17:20 ? 00:00:00 nginx: worker process root 28720 28533 0 17:21 pts/1 00:00:00 grep --color=auto nginx
# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.17.3 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=../fastdfs-nginx-module/src