If you want to upgrade the current Nginx server version, apply the new module, if the user access is relatively large, if you need to upgrade without impacting the customer, then you have to consider a smooth upgrade.
The process of smooth upgrade, the Nginx server received the USR2 signal, First add the old nginx.pid file suffix. oldbin, into the Nginx.pid.oldbin file, and then perform a new version of the Nginx server's binary file startup service, this time need to advance the compiled new version of the binary implementation to the Sbin folder. If the new service starts successfully, the system will have the new and old two Nginx services together to provide the Web services. After that, it is necessary to send the winch signal to the old Nginx server process, so that the old Nginx service is stopped smoothly and the Nginx.pid.oldbin file is deleted. You can stop the new Nginx service at any time before sending the winch signal, if you find anything wrong.
The naginx1.8.0 was previously compiled and installed. When compiling, only specified by path--prefix=/nginx/. Here is a demonstration of upgrading from nginx1.8.0 to Nginx 1.9.6
[Email protected] ~]#/nginx/sbin/nginx-vnginx version:nginx/1.8.0built by gcc 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) c Onfigure arguments:--prefix=/nginx/[[email protected] ~]# Ss-tnllisten 0 12 *:80 *:*
Here in order to test the upgrade process, the web is not interrupted, providing a script to request the page service every second. and record it in the log.
[Email protected] test]# vim http.sh #!/bin/bash#url= "http://192.168.0.66/" http_code= ' Curl-o/dev/null-s-W "%{http_ Code} "${url}" ' If [$HTTP _code = =];then echo Success. $HTTP _code >>/tmp/ping.httpelse echo failure.404 & Gt;>/tmp/ping.httpfi# Request HTTP service, send request success and failure to ping.http file [[email protected] test]# vim cron.sh #!/bin/bash#while True ;d o/test/http.shsleep 1done# provides execution service per second for cron service [[email protected] test]# crontab-e* * * * */bin/bash/test/cron.sh# definition per minute execution C ron.sh Tasks
Download compile nginx-1.9.6, and smooth upgrade, in order to achieve the smooth upgrade of Nginx server, the new service installation path should be consistent with the old service installation path. If for some reason it is inconsistent, you need to change the installation path of the old service to the installation path of the new service, and modify the method to (Nginx-p Newinstallpath)
[[email protected] ~]# wget http://nginx.org/download/nginx-1.9.6.tar.gz[[email protected] ~]# tar xf nginx-1.9.6.tar.gz[[email protected] ~]# cd Nginx-1.9.6[[email protected] nginx-1.9.6]# ./configure --prefix=/nginx/ [[email protected] nginx-1.9.6]# make[[email protected] mv /nginx/sbin/nginx{,.bak}# Back up the old nginx here, on the one hand is to wait for the new nginx to copy over, on the other hand if the new nginx has problems, can also be restored [[EMAIL PROTECTED] NGINX-1.9.6]# CP objs/nginx /nginx/sbin/#把编译好的新的nginx文件服务到指定的安装目录中 [[email protected] sbin]# /nginx/ sbin/nginx -tnginx: the configuration file /nginx//conf/nginx.conf syntax is oknginx: configuration file /nginx//conf/nginx.conf test is successful# Test whether the newly compiled nginx detection configuration file is normal [[email protected] nginx-1.9.6]# kill -usr2 ' cat /nginx/ Logs/nginx.pid ' #使用新版本的Nginx文件启动服务, theAfter gently stopping the original nginx process [[email protected] nginx-1.9.6]# cd /nginx/logs/access.log error.log nginx.pid nginx.pid.oldbin# can be seen here automatically named before the Nginx.pid Nginx.pid.oldbin, and for the new Nginx generated nginx.pid[[email protected] logs]# kill -winch ' Cat /nginx/logs/nginx.pid.oldbin ' #平缓停止旧服务的worker process[[email protected] logs]# nginx -vnginx version: nginx/1.9.6built by gcc 4.8.3 20140911 (red hat 4.8.3-9) (GCC) configure arguments: -- prefix=/nginx/[[email protected] logs]# ps -aux |grep nginxroot 990 0.0 0.2 24316 1880 ? s 11:25 0:00 nginx: master process nginxnobody 992 0.9 0.2 24724 1712 ? s 11:25 0:03 nginx: worker processroot 2357 0.0 0.1 24308 896 ? Ss 11:20 0:00 nginx: master process Nginx# can see that there are two master process processes
Test results
[Email protected] ~]# Sort/tmp/ping.http | Uniq-c 32822 success.200# can see the service is not aborted
This section of the content reference "Nginx high-performance Web server detailed"
Fast Stop Nginx service: Fast stop means stop all network requests being processed by the current Nginx service immediately, discard the connection immediately, stop working
[Email protected] ~]# kill-term ' cat/nginx/logs/nginx.pid ' [[email protected] ~]# kill-int ' cat/nginx/logs/nginx.pid '
Flat stop Nginx Service: Flat stop is the Allow Nginx service to complete the processing of the network request currently being processed, but no longer accept new requests, then close the connection and stop working
[Email protected] ~]# kill-quit ' cat/nginx/logs/nginx.pid '
Gentle Restart Nginx Service: The Nginx service process receives the signal, first read the new nginx configuration file, if the configuration syntax is correct, then start the new Nginx service, and then gently shut down the old service process, if the new nginx configuration file has a problem, will display an error, Service is still available using the old Nginx process
[Email protected] ~]# kill-hup ' cat/nginx/logs/nginx.pid '
Log cut: Reopen log file, often used for log cutting
[Email protected] ~]# kill-usr1 ' cat/nginx/logs/nginx.pid '
Flat upgrade Nginx Service: Start the service with a new version of Nginx file, then gently stop the original nginx process
[Email protected] ~]# KILL-USR2 ' cat/nginx/logs/nginx.pid '
Gentle stop worker process: For a flat upgrade of Nginx service
[Email protected] ~]# kill-winch ' cat/nginx/logs/nginx.pid '
This article is from the "Ma Gao" blog, please make sure to keep this source http://kgdbfmwfn.blog.51cto.com/5062471/1708258
Nginx smooth upgrade and smooth restart