Table of Contents
何为不停机发布?
Cluster模式
Master/Worker模式
延伸阅读
小结
Home Backend Development PHP Tutorial 【CI/CD】几种常见的不停机发布方式

【CI/CD】几种常见的不停机发布方式

Jun 20, 2016 pm 12:25 PM

何为不停机发布?

本文所说的不停机发布,是指在 不停止对外服务 的前提下完成应用的更新。与 热部署 的区别在于,热部署关注于 应用 层面并且以 不重启应用 为前提,而不停机发布则关注于 服务 层面。随着摩尔定律逐渐逼近极限和多核时代的到来,分布式应用已经成为事实上的主流。下文首先给出一种通用的适用于分布式应用环境的不停机发布方式,然后再介绍Master/Worker这种常见的适用于单机应用的不停机发布方式。

Cluster模式

对于运行于集群环境的分布式应用,一般在应用之上都有一层负载均衡(LB)。如果在发布过程中,在更新任一节点(也可以是一组节点)前先关闭该节点对应的负载,更新完再打开负载,即可实现整体服务的不停机发布。在此基础上,为了保证服务的稳定性,可以加上备机的支持,即更新某一节点时,先挂上备机,更新完再卸下,依次轮换更新完所有节点后最后再升级备机,如下图所示:

完整设计可以参考我写的另一篇 文章

上述发布过程其实就是一个简单的CD(Continuous Deployment)系统。作为一个参考实现,可以使用 Jenkins 2.0 Pipeline 特性定义整个发布流程,使用 Nginx Dynamic Upstream 插件操纵Nginx,然后配合脚本完成应用的启停和检测。

Master/Worker模式

对于单机应用,由于不存在LB,一般由应用容器实现不停机发布特性,最常见是Master/Worker模式。容器中常驻一个master进程和多个work进程,master进程只负责加载程序和分发请求,由fork出来的worker进程完成具体工作。当容器收到更新应用的信号时,master进程重新加载更新后的程序,然后fork新的worker进程处理新的请求,而老的worker进程在处理完当前请求后就自动销毁。Ruby的 Unicorn ,PHP的 FPM 都是采用了这套机制。

延伸阅读

不同于Master/Worker模式,erlang采用了另一种独特的方式实现了不停机发布。

erlang VM为每个模块最多保存2份代码,当前版本'current'和旧版本'old',当模块第一次被加载时,代码就是'current'版本。如果有新的代码被加载,'current'版本代码就变成了'old'版本,新的代码就成了'current'版本。erlang用两个版本共存的方法来保证任何时候总有一个版本可用,对外服务就不会停止。



—— 引自 分析erlang热更新实现机制

小结

不管是LB,还是Master/Worker,其基本思想都是在发布过程中,通过某种机制使得服务请求始终能够被系统的某个节点或者某个进程处理,从而保证了服务的可用性。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles