nginx笔记(三)
热部署
nginx热部署
热升级的流程
1、将旧的nginx文件替换成新的nginx文件
2、向master进程发送USR2信号
3、master进程修改pid文件,加后缀.oldbin4、master进程用新nginx文件启动新master进程
5、向旧的master进程发送WINCH信号,l旧的worker子进程退出
6、回滚情形∶向旧master发送HUP, l
向新的master发送QUIT
热升级过程图示
Nginx热部署完整步骤演示
[root@localhost ~]# /usr/sbin/nginx
[root@localhost ~]# ps -ef | grep nginx
root 1624 1 0 09:58 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1625 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1626 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1627 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1628 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1629 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1630 1624 0 09:58 ? 00:00:00 nginx: worker process
root 1632 1597 0 09:58 pts/0 00:00:00 grep --color=auto nginx
[root@localhost sbin]# cp nginx nginx.bak
root@localhost sbin]# ps -ef | grep nginx
root 1624 1 0 09:58 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1625 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1626 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1627 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1628 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1629 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1630 1624 0 09:58 ? 00:00:00 nginx: worker process
root 1675 1597 0 10:01 pts/0 00:00:00 grep --color=auto nginx
[root@localhost sbin]# kill -s SIGUSR2 1624
[root@localhost sbin]#
[root@localhost sbin]# ps -ef | grep nginx
root 1624 1 0 09:58 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1625 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1626 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1627 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1628 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1629 1624 0 09:58 ? 00:00:00 nginx: worker process
nginx 1630 1624 0 09:58 ? 00:00:00 nginx: worker process
root 1677 1624 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1678 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1679 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1680 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1681 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1682 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1683 1677 0 10:02 ? 00:00:00 nginx: worker process
root 1685 1597 0 10:02 pts/0 00:00:00 grep --color=auto nginx
[root@localhost sbin]#
[root@localhost usr]# cd /var/log/nginx/
[root@localhost nginx]# ls
access.log access.log-20230407 error.log error.log-20230407
[root@localhost ~]# kill -s SIGWINCH 1624
[root@localhost ~]# ps -ef | grep nginx
root 1624 1 0 09:58 ? 00:00:00 nginx: master process /usr/sbin/nginx
root 1677 1624 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1678 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1679 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1680 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1681 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1682 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1683 1677 0 10:02 ? 00:00:00 nginx: worker process
root 1697 1597 0 10:06 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]# kill -s SIGQUIT 1624
[root@localhost nginx]# ps -ef | grep nginx
root 1677 1 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1678 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1679 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1680 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1681 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1682 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1683 1677 0 10:02 ? 00:00:00 nginx: worker process
root 1701 1597 0 10:07 pts/0 00:00:00 grep --color=auto nginx
#回滚
[root@localhost nginx]# ps -ef | grep nginx
root 1677 1 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1678 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1679 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1680 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1681 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1682 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1683 1677 0 10:02 ? 00:00:00 nginx: worker process
root 1707 1597 0 10:09 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]# kill -s SIGURG2 1677
-bash: kill: SIGURG2: invalid signal specification
[root@localhost nginx]# kill -s SIGURG2 1677
-bash: kill: SIGURG2: invalid signal specification
[root@localhost nginx]# ps -ef | grep nginx
root 1677 1 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1678 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1679 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1680 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1681 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1682 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1683 1677 0 10:02 ? 00:00:00 nginx: worker process
root 1709 1597 0 10:10 pts/0 00:00:00 grep --color=auto nginx
[root@localhost nginx]# kill -s SIGURG2 1677
-bash: kill: SIGURG2: invalid signal specification
[root@localhost nginx]# ls
access.log access.log-20230407 error.log error.log-20230407
[root@localhost nginx]#
[root@localhost nginx]#
[root@localhost nginx]#
[root@localhost nginx]# cd
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# kill -s SIGURG2 1677
-bash: kill: SIGURG2: invalid signal specification
[root@localhost ~]# kill -s SIGUSR2 1677
[root@localhost ~]# ps -ef | grep nginx
root 1677 1 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1678 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1679 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1680 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1681 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1682 1677 0 10:02 ? 00:00:00 nginx: worker process
nginx 1683 1677 0 10:02 ? 00:00:00 nginx: worker process
root 1711 1677 0 10:11 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1712 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1713 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1714 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1715 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1716 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1717 1711 0 10:11 ? 00:00:00 nginx: worker process
root 1719 1597 0 10:11 pts/0 00:00:00 grep --color=auto nginx
[root@localhost ~]# kill -s SIGWINCH 1677
[root@localhost ~]# ps -ef | grep nginx
root 1677 1 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
root 1711 1677 0 10:11 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1712 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1713 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1714 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1715 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1716 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1717 1711 0 10:11 ? 00:00:00 nginx: worker process
root 1744 1597 0 10:12 pts/0 00:00:00 grep --color=auto nginx
[root@localhost ~]# kill -s SIGHUP 1677
[root@localhost ~]# ps -ef | grep nginx
root 1677 1 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
root 1711 1677 0 10:11 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1712 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1713 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1714 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1715 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1716 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1717 1711 0 10:11 ? 00:00:00 nginx: worker process
nginx 1746 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1747 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1748 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1749 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1750 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1751 1677 0 10:13 ? 00:00:00 nginx: worker process
root 1753 1597 0 10:13 pts/0 00:00:00 grep --color=auto nginx
[root@localhost ~]# kill -s SIGQUIT 1711
[root@localhost ~]# ps -ef | grep nginx
root 1677 1 0 10:02 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1746 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1747 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1748 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1749 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1750 1677 0 10:13 ? 00:00:00 nginx: worker process
nginx 1751 1677 0 10:13 ? 00:00:00 nginx: worker process
root 1756 1597 0 10:14 pts/0 00:00:00 grep --color=auto nginx
[root@localhost ~]#