Hot deployment of nginx, and version rollback

The concept of hot deployment: When replacement from the old version to the new version of nginx time, if not hot deployment, it will need to cancel nginx service and restart the service to replace the successful, in which case the user will is available in disconnected, so in order not to affect the user experience, and the need to upgrade, you need to upgrade the version of the hot deployment
concept version rollback: problems arise when a new version on the line, need to return to the old version, this version is rolled back when you need to do, in fact, before you do version upgrade, the old version of the backup, and then replace the new version, the new version after the killing process can
experiment steps: 1: start with links to online copies of the official nginx-1.14.2 version, and need the source code the deployment of
2: Extract in / opt / directory
3: create useradd -u 998 -s / sbin / nologin nginx nginx process
4: cd /opt/nginx-1.14.2 precompiled and compiled and installed, then you need to install the compiler devlopment or install gcc, gcc-c ++, yum -y groupinstall devlopment or yum -y gcc gcc-c ++ requires a little longer time ahead, write behind a fast
5: precompiled command $ / configure = --prefix / usr / local / nginx nginx --group --user = = nginx
$ the make
$ the make install
6:? check with echo $ not installed successfully, successful control is set in the following order nginxctl
7: $ vi / usr / bin / nginxctl
#! / usr / bin / env bash
Case $ 1 in
STOP)
/usr/local/nginx/sbin/nginx -s quit
;;
start)
/usr/local/nginx/sbin/nginx
;;
reload)
/usr/local/nginx/sbin/nginx -s reload
;; *)
echo "please input (start|stop|reload)"
;;
esac

~ 8: chmod a + execute permissions x / usr / bin / nginxctl # settings file
9: nginxctl start # start nginx Services
10: At this time enter the ip address from your browser, visit the home page is displayed nginx
11: start now hot deployment, the upgrade version to nginx-16.0.1, copy the download link from the official website
12: before installation with the same, but then to make not the case, do not need to install make
13: [root @ web3 nginx-1.16.1 ] # mv /usr/local/nginx/sbin/{nginx,nginx.old}# back up what nginx-14.0.2 version, the version required to prevent rollback
[root @ web3 nginx-1.16.1] # LS
Auto CHANGES.ru HTML Makefile src objs the configure
the CHANGES conf contrib LICENSE man the README
[root @ web3 nginx-1.16.1] # # cd objs new version of nginx command objs in
nginx ngx_auto_config.h ngx_modules.c
nginx.8 ngx_auto_headers.h ngx_modules.o
[ root @ web3 nginx-1.16.1] # cp objs / nginx / usr / local / nginx / sbin / nginx # needs to be a new version of nginx command to replace the original version
[root @ web3 nginx-1.16.1] # ps aux | grep nginx # at this time to see nginx processes, see nginx processes running, or the old version of the process
? root 51891 0.0 0.0 20544 600 Ss 21:49 0:00 Nginx: Process Master / usr / local / Nginx / sbin / Nginx
? Nginx 51893 20988 1560 0.0 0.1 21:49 0:00 Nginx S: Process worker
the root PTS 984 112 708 0.0 66 744 0.0 / 0 R & lt grep + 22:06 0:00 - = Auto nginx -color
[root @ web3 nginx-1.16.1] # # 51 891 -USR2 the kill off the old version of the elegant process, hot deployment mainly rely on this command, the user is visiting still access the old version, the new user access will have access to the new version of nginx
[root @ web3 nginx-1.16.1] # PS the AUX | grep # nginx this time look at the process found four processes, old and new versions have
root 51891 0.0 0.0 20544 792 Ss 21:49 ? nginx 0:00: Master Process / usr / local / nginx / sbin / nginx
nginx 51893 20988 1560 0.0 0.1 S 21:49 0:00 nginx:? Process worker
? root 67798 0.1 0.1 20552 S 1588 22:07 0:00 nginx: Master Process / usr / local / nginx / sbin / nginx
nginx 67 799 0.0 1328 0.1 21004 S 22:07 0:00 nginx:? worker Process
root 68006 0.0 0.0 PTS 984 112 708/0 R + 22:07 0:00 grep --color = Auto nginx
[root @ web3 nginx-1.16.1] the kill -WINCH 51 891 # # this command means that older versions do not allow to detect new users response
[root @ web3 nginx-1.16.1] # PS the AUX | grep nginx
root 51 891 0.0 792 0.0 20544 Ss 21:49 0:00 nginx:? Master Process / usr / local / nginx / sbin / nginx
root 67798 0.0 0.1 ? 20552 S 1588 22:07 0:00 nginx: Master Process / usr / local / nginx / sbin / nginx
nginx 67799 21004 1328 0.0 0.1 S 22:07 0:00 nginx:? worker Process
root 69 592 0.0 0.0 112 708 980 PTS / 0 R + 22:09 0:00 grep --color = auto nginx
[root @ web3 nginx-1.16.1] # / usr / local / nginx / sbin / nginx -v # This version is the time to detection 1.16.1
nginx Version: nginx / 1.16.1
2 version rollback:
version rollback and before almost, but there is a need to pay attention, because the new version will not do so directly with the kill command like, if we need to upgrade the version, and then hot-deploy it again
[root @ web3 nginx-1.16.1] # vi / usr / bin / nginxctl
[@ Web3 Nginx the root-1.16.1] # Music Videos /usr/local/nginx/sbin/{nginx,nginx.old-1.16.1}
[@ Web3 Nginx the root-1.16.1] PS # AUX | grep Nginx
the root 21161 0.0 0.0 112 708 984 PTS / 0 + 23:37 0:00 grep R & lt --color = Auto Nginx
the root Ss 792 51 891 0.0 20544 0.0 21:49 0:00 Nginx:? Master Process / usr / local / Nginx / sbin / nginx
root 67798 0.0 0.1 20552 S 1588 22:07 0:00 nginx:? Master Process / usr / local / nginx / sbin / nginx
nginx 67 799 0.0 1572 0.1 21004 S 22:07 0:00 nginx:? Process worker
[root@web3 nginx-1.16.1]# mv /usr/local/nginx/sbin/{nginx.old,nginx}
[root@web3 nginx-1.16.1]# ps aux|grep nginx
root 22307 0.0 0.0 112708 984 pts/0 R+ 23:39 0:00 grep --color=auto nginx
root 51891 0.0 0.0 20544 792 ? Ss 21:49 0:00 nginx: master process /usr/local/nginx/sbin/nginx
root 67798 0.0 0.1 20552 1588 ? S 22:07 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 67799 0.0 0.1 21004 1572 ? S 22:07 0:00 nginx: worker process
[root@web3 nginx-1.16.1]# kill -USR2 51891
[root@web3 nginx-1.16.1]# kill -9 67799
[root@web3 nginx-1.16.1]# ps aux|grep nginx
nginx 23560 1.1 0.1 21004 1328 ? S 23:40 0:00 nginx: worker process
root 23638 0.0 0.0 112708 984 pts/0 R+ 23:41 0:00 grep --color=auto nginx
root 51891 0.0 0.0 20544 792 ? Ss 21:49 0:00 nginx: master process /usr/local/nginx/sbin/nginx
root 67798 0.0 0.1 20552 1588 ? S 22:07 0:00 nginx: master process /usr/local/nginx/sbin/nginx
[root@web3 nginx-1.16.1]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.14.2

Guess you like

Origin www.cnblogs.com/bobo-wq/p/11514851.html