Environment description
The current server is running Nginx service, now want to upgrade the version of the currently running Nginx service, (from 1.6 to 1.8, the version of the span is not too large, easy to cause the service crash), and the service does not stop the premise of the row upgrade.
1. Start a new process without losing the old process.
2. The old process is responsible for processing requests that are still not processed, but is no longer accepting processing requests.
3. The new process accepts new requests.
4. The old process finishes processing all requests, closes all connections, and then stops.
Implementation steps
1. Compile and install nginx-1.6
yum -y install pcre-devel Zlib-devel #安装依赖包useradd -m-s/sbin/nologin nginx #添加程序运行用户
tar -zxvf nginx-1.6 . 0 . tar . Gz-c/usr/src/ #解包cd /usr/src/nginx-< Span style= "COLOR: #800080" >1.6 . 0 / /configure--prefix=/usr/local/nginx--user=nginx--group=nginx && make && make install #配置编译并且安装 /usr/local/nginx/sbin/nginx #启动nginx服务
2. Compile nginx-1.8 (compile-only not installed)
tar -zxvf nginx-1.8. 1. tar. gz-c/usr/src/ /usr/src/nginx-1.8. 1/. make #配置编译并且安装
3. View previous versions of the upgrade
#/usr/local/nginx/sbin/nginx-Vnginx version:nginx/1.6. 0
4. Back up the old version of Nginx execution program
MV /usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.old
5. Replace the old Nginx execution program
CP /usr/src/nginx-1.8. 1/objs/nginx/usr/local/nginx/sbin/
6. Make the old version of Nginx Stop the request, there is a new version of Nginx replacement, and the old process to complete all requests, close all connections, stop
kill -USR2 'cat /usr/local/nginx/logs/nginx.pid '
7. View Nginx Log directory will generate a Nginx.pid.oldbin file, storing the old version of Nginx PID number
#ls /usr/local/nginx/logs/access.log error.log nginx.pid nginx.pid.oldbin
8. View the upgraded version of the upgrade
#/usr/local/nginx/sbin/nginx-Vnginx version:nginx/1.8. 1
9. View service health status
grep nginxgetnameinfo failedtcp 0 0 *:http *:* LISTEN 6963
10. Use the client to verify that the Nginx service can continue to access
[Linux]-nginx Smooth Upgrade