重识Nginx - 05 热更新_不停机更换新版本的nginx

简介: 重识Nginx - 05 热更新_不停机更换新版本的nginx

20200103193054943.png


热部署 (不停机更换新版本的nginx 二进制文件)


  • 查看nginx进程
  • 模拟 上传新版本,老版本的ng备份
  • 发送 USR2 信号给 原来的ng的 pid
  • 再次查看ng进程,会发现多出来几个, 此时老的ng已经不再监听了,流量会切到新的ng上来
  • 向老的ng master 发送信息,优雅的关闭它的 work线程 (需要等待老业务都处理完了)
# 查看nginx进程  
[root@VM-0-7-centos artisan_ng]# ps -ef|grep nginx |grep -v grep
root      447751       1  0 12:23 ?        00:00:00 nginx: master process ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
nobody    454927  447751  0 13:14 ?        00:00:00 nginx: worker process
[root@VM-0-7-centos artisan_ng]#
[root@VM-0-7-centos artisan_ng]# pwd
/root/ng/artisan_ng
[root@VM-0-7-centos artisan_ng]# ls
client_body_temp  conf  fastcgi_temp  html  logs  proxy_temp  sbin  scgi_temp  uwsgi_temp
[root@VM-0-7-centos artisan_ng]# cd sbin/
# 模拟 上传新版本,老版本的ng备份 
[root@VM-0-7-centos sbin]# cp nginx nginx_old
[root@VM-0-7-centos sbin]#
# 发送  USR2 信号给 原来的ng的 pid 
[root@VM-0-7-centos sbin]# kill -USR2 447751
[root@VM-0-7-centos sbin]#
# 再次查看ng进程,会发现多出来几个, 此时老的ng已经不再监听了,流量会切到新的ng上来 
[root@VM-0-7-centos sbin]# ps -ef|grep nginx
root      447751       1  0 12:23 ?        00:00:00 nginx: master process ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
nobody    454927  447751  0 13:14 ?        00:00:00 nginx: worker process
root      455372  447751  0 13:17 ?        00:00:00 nginx: master process ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
nobody    455373  455372  0 13:17 ?        00:00:00 nginx: worker process
root      455386  454554  0 13:17 pts/1    00:00:00 grep --color=auto nginx
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
# 向老的ng master 发送信息,优雅的关闭它的 work线程   (需要等待老业务都处理完了)
[root@VM-0-7-centos sbin]# kill -WINCH 447751
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#
# 老的master进程 还是存在的, 已经没有work进程了 。 老的ngxin存在 便于我们进行版本回退 (可以给老的nginx 发送 reload命令)
[root@VM-0-7-centos sbin]# ps -ef|grep nginx |grep -v grep
root      447751       1  0 12:23 ?        00:00:00 nginx: master process ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
root      455372  447751  0 13:17 ?        00:00:00 nginx: master process ./nginx -c /root/ng/artisan_ng/conf/nginx.conf
nobody    455373  455372  0 13:17 ?        00:00:00 nginx: worker process
[root@VM-0-7-centos sbin]#
[root@VM-0-7-centos sbin]#


热更新流程


  1. 将旧Nginx件换成新Nginx件(注意备份)
  2. 向master进程发送USR2信号
  3. master进程修改pid件名,加后缀.oldbin
  4. master进程用新Nginx件启动新master进程
  5. 向老master进程发送WINCH号,关闭老worker
  6. 回滚:向老master送HUP,向新master送QUIT

14a0589244654344aca74ab99168c260.png


相关文章
|
2月前
|
应用服务中间件 Linux 网络安全
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
CentOS 7.4源码编译nginx1.12 并且隐藏nginx的版本
35 0
|
2月前
|
应用服务中间件 Shell 开发工具
nginx+shell脚本实现一键启用与关闭停机维护页面
nginx+shell脚本实现一键启用与关闭停机维护页面
54 0
|
23天前
|
tengine 安全 应用服务中间件
修改Nginx/Tengine版本名称伪装任意WEB SERVER
修改Nginx/Tengine版本名称伪装任意WEB SERVER
|
2月前
|
应用服务中间件 网络安全 nginx
nginx 常用命令 |升级到1.20.1版本 | 如何更换 Nginx SSL 证书
nginx 常用命令 |升级到1.20.1版本 | 如何更换 Nginx SSL 证书
222 0
|
2月前
|
存储 Linux 应用服务中间件
VMware安装无GUI版本的Linux(CentOS7)——安装Nginx示例demo
VMware安装无GUI版本的Linux(CentOS7)——安装Nginx示例demo
143 1
|
10月前
|
负载均衡 应用服务中间件 Linux
CentOS 系列版本搭建 Nginx 服务
Nginx 是一个广泛使用的Web服务器和反向代理服务器。 反向代理和负载均衡:Nginx支持反向代理和负载均衡,能够分发请求到多个后端服务器,提高了可用性和性能。 SSL/TLS支持:Nginx支持SSL/TLS协议,使您能够配置HTTPS并提供安全的数据传输。 低资源消耗:Nginx设计得非常轻量,占用较少的内存和CPU资源,因此在资源受限的环境中表现出色。 简单的配置:Nginx的配置文件易于理解和维护,使管理员能够快速进行配置更改。
74 1
|
9月前
|
前端开发 Java jenkins
Jenkins+Gitlab+Nginx+SonarQube+Maven编译Java项目自动发布与基于tag版本回退
Jenkins+Gitlab+Nginx+SonarQube+Maven编译Java项目自动发布与基于tag版本回退
280 0
|
9月前
|
Java jenkins 应用服务中间件
Jenkins+Gitlab+Nginx+Maven编译Java项目自动发布与基于tag版本回退(重复构建问题已解决)
Jenkins+Gitlab+Nginx+Maven编译Java项目自动发布与基于tag版本回退(重复构建问题已解决)
|
9月前
|
jenkins 应用服务中间件 持续交付
Jenkins+Gitlab+Nginx实现自动发布与回退基于tag版本的静态项目(解决重复构建问题)
Jenkins+Gitlab+Nginx实现自动发布与回退基于tag版本的静态项目(解决重复构建问题)
109 0