What should I do if nginx is too low to close? One move to smooth upgrade

Keywords: Linux Nginx Red Hat OpenSSL

1. View the existing nginx compilation parameters

I'm here with 1.16.0 Upgrade to 1 for example.16.1(Compiled and installed)
[root@localhost ~]# /usr/local/nginx/sbin/nginx -V       
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream

2. Upload the new version of the source package nginx-1.16.1.tar.gz, and extract it to / usr/local/

(Note: to install nginx according to the original compilation parameters, you only need to make. Do not make install. If make install will overwrite the original configuration file, you won't have anything before)

[root@localhost ~]# ls     #I have uploaded a new version of the source package here
nginx-1.16.1.tar.gz
[root@localhost ~]# tar -xf nginx-1.16.1.tar.gz -C /usr/local/    #Extract to the specified directory
[root@localhost ~]# cd /usr/local/nginx-1.16.1/

#The parameters in this step are copied from the parameters in the first step
[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream
[root@localhost nginx-1.16.1]# make
#####Never make install 

3. Smooth upgrade

#Back up the original nginx binary
[root@localhost nginx-1.16.1]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.1.16.0.bak
#Backup binaries and nginx configuration files (during which nginx will not stop service)
[root@localhost nginx-1.16.1]# cp /usr/local/nginx-1.16.1/objs/nginx /usr/local/nginx/sbin/
#Copy the new nginx binary file and enter the new nginx source package
#Test whether the new version of nginx is normal
[root@localhost nginx-1.16.1]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost nginx-1.16.1]# ll /var/run/nginx.pid*
-rw-r--r--. 1 root root 6 3 Month 1122:12 /var/run/nginx.pid
#View nginx pid
[root@localhost nginx-1.16.1]# kill -USR2 `cat /var/run/nginx.pid`
#Send smooth migration signal to nginx (if pid path is unclear, please check nginx configuration file)
[root@localhost nginx-1.16.1]# ll /var/run/nginx.pid*
-rw-r--r--. 1 root root 6 3 Month 1122:19 /var/run/nginx.pid
-rw-r--r--. 1 root root 6 3 Month 1122:12 /var/run/nginx.pid.oldbin
#Check nginx pid and a nginx.pid.oldbin will appear
[root@localhost nginx-1.16.1]# kill -WINCH `cat /var/run/nginx.pid.oldbin`  #Calmly shut down the old Nginx process
[root@localhost nginx-1.16.1]# kill -HUP `cat /var/run/nginx.pid.oldbin`    #Do not overload the configuration to start the old worker process at this time
[root@localhost nginx-1.16.1]# kill -QUIT `cat /var/run/nginx.pid.oldbin`   #Finish the upgrade
[root@localhost nginx-1.16.1]# /usr/local/nginx/sbin/nginx -V      #View version again
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream

It will be found that the version has been upgraded, and the old process has not been closed. The smooth upgrade is successful.

Your comments and compliments are my biggest motivation for writing, crab crab.

Posted by SsirhC on Mon, 06 Apr 2020 07:48:47 -0700