1. Before you start, first look the current usage version and compile time parameters:
1 2 3 4 5 6 |
[root@ ~]#/usr/local/nginx/sbin/nginx -V nginx version: nginx/1.12.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module |
or
1 2 3 4 5 6 |
[root@ ~]#nginx -V nginx version: nginx/1.12.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module |
Copy the compilation parameters, we will use them when compiling the new version.
2. download the new version: http://nginx.org/en/download.html
1 2 3 |
cd nginx-1.14.0 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make |
3. after the completion of the implementation, we do not need make install, backup the original binary startup file, and then copy the new version of the startup file
1 2 |
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak [root@www nginx-1.14.0]# cp objs/nginx /usr/local/nginx/sbin/nginx |
4. Test if the copied file is valid:
1 2 3 |
[root@www nginx-1.14.0]# /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. Send the USR2 signal to the nginx master process. After receiving the USR2 signal, the nginx service first changes the nginx.pid file to nginx.pid.oldbin, and then executes the new version of the binary file to start the service. If the new service starts successfully, There will be two new Nginx services in the system to provide web services together)
1 2 3 4 5 6 7 |
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid` [root@www nginx-1.14.0]# ps -ef | grep nginx root 22644 1 0 23:30 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx www 22648 22644 0 23:30 ? 00:00:00 nginx: worker process root 25784 22644 0 23:47 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx www 25789 25784 0 23:47 ? 00:00:00 nginx: worker process |
6. Stop the old Nginx service process by sending WINCH signal (slow stop worker process) and QUIT signal (slow stop Nginx service)
1 2 |
kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin` kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin` |
7. the final upgrade is complete, finally check the nginx version:
1 2 |
/usr/local/nginx/sbin/nginx -v nginx version: nginx/1.14.0 |
or
1 2 |
nginx -v nginx version: nginx/1.14.0 |
1 2 3 4 5 6 |
[root@ ~]#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.2l 25 May 2017 TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module |
This article was first published by V on 2018-10-03 and can be reprinted with permission, but please be sure to indicate the original link address of the article :http://www.nginxer.com/records/nginx-smooth-upgrade/