openresty Development Series 3 - nginx smooth upgrade

openresty Development Series 3 - nginx smooth upgrade

nginx server upgrade from a lower version to higher version, if forced out of service, will affect the running processes.

Smooth upgrade process is not stopped running, these processes will continue to process the request. But will not accept new requests, the old process will stop after processing the request. This smooth upgrade process, the new open process will be processed.

A) smooth upgrade
into the nginx executable directory
     # cd / usr / local / nginx / sbin /
     # sbin / nginx -v
       nginx Version: nginx / View nginx version 1.13.0 #

1) Download high version nginx
wget HTTP: / /nginx.org/download/nginx-1.13.2.tar.gz

executes instructions to generate binary version of Nginx
# ./configure
# # can not execute the make install the make
# cd objs
nginx high version of this directory
backup version of the low nginx
cd / usr / local / nginx / sbin /
cp nginx nginx.old
the mandatory coverage, nginx will replace the low version is just compiled version of the high nginx
[root @ Node5 objs] -rfp # cp / usr / local / src / nginx-1.13.2 / objs / nginx / usr / local / nginx / sbin /
? cp: overwrite '/ usr / local / nginx / sbin / nginx' y

test the new files copied Coming into effect:
# / usr / local / nginx / sbin / nginx -t
[root @ Node5 objs] # PS -ef | nginx grep
? root 43151 1 0 19:40 00:00:00 nginx: Master Process / usr / local // nginx / sbin / nginx
the nobody 43152 43151 0 19:40 00:00:00 nginx:? Process worker
the nobody 43153 43151 ? 0 19:40 00:00:00 nginx: Process worker
? the nobody 43154 43151 0 19:40 00:00:00 nginx: Process worker
? the nobody 43 155 43151 0 19:40 00:00:00 nginx: Process worker
root 45585 PTS 0 19:46 43080 / grep --color 00:00:00. 1 = Auto Nginx
[@ Node5 the root OBJS] /usr/local/nginx/logs/nginx.pid CAT #
43 151

2) performs signal smoothing upgrade
# Kill -USR2 `cat / usr / local / nginx / logs / nginx.pid` update the configuration file

[root @ node5 objs] # kill -USR2` cat / usr / local / nginx / logs / nginx.pid`

sent to nginx after USR2 signal, will nginx logs / nginx.pid rename the file to nginx.pid.oldbin, and then start a new process and corresponding main nginx worker processes with a new executable file, and create a new nginx.pid hold the new primary process ID

[root @ Node5 objs] # CAT /usr/local/nginx/logs/nginx.pid
45589


3) the kill -WINCH old master process ID
after the old master process ID signal received WINCH, old the old worker process process ID management graceful close. That is, after a while the old worker processes all closed, only the new work processes in handling requests a connection. At this point, you can still revert to the old process serving, listening socket because the old process has not stopped.
After processing, the work process will automatically shut down
[root @ Node5 objs] # PS -ef | grep nginx
root 43 151 1 0 19:40 00:00:00 nginx:? Master Process / usr / local // nginx / sbin / nginx
nobody 43152 43151 0 19:40 00:00:00 nginx: ? worker process
nobody    43153  43151  0 19:40 ?        00:00:00 nginx: worker process
nobody    43154  43151  0 19:40 ?        00:00:00 nginx: worker process
nobody    43155  43151  0 19:40 ?        00:00:00 nginx: worker process
root      45589  43151  0 19:46 ?        00:00:00 nginx: master process /usr/local//nginx/sbin/nginx
nobody    45590  45589  0 19:46 ?        00:00:00 nginx: worker process
nobody    45591  45589  0 19:46 ?        00:00:00 nginx: worker process
nobody    45592  45589  0 19:46 ?        00:00:00 nginx: worker process
nobody    45593  45589  0 19:46 ?        00:00:00 nginx: worker process
root      45595  43080  0 19:46 pts/1    00:00:00 grep --color=auto nginx

4) # kill -QUIT `cat / usr / local / nginx / logs / nginx.pid.oldbin` elegant close
to the old master process send QUIT signal, the old master process exits, and remove logs / nginx.pid .oldbin file, nginx the upgrade is complete.

The upgrade is complete, the last look at the upgraded version

to view
[root @ Node5 objs] # / usr / local / nginx / sbin / nginx -v
nginx Version: nginx / 1.13.2

has been a smooth upgrade successfully

two) midway stop the upgrade, roll back to the old nginx

in step (3), if you want to return to the old upgrade nginx is no longer

the case (1) to the old master process ID to send HUP command, then nginx does not re-read the configuration file restart Worker process former team process.
kill -HUP 43151 - the old master process ID
restart the worker process

(2) closed elegant new master process
kill -QUIT 45589 - the new primary process ID

Guess you like

Origin www.cnblogs.com/reblue520/p/11428939.html