You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/09/10 08:00:53 UTC

[GitHub] [apisix-website] liuxiran commented on a change in pull request #578: docs: add transmitted blog of APISIX&Nginx

liuxiran commented on a change in pull request #578:
URL: https://github.com/apache/apisix-website/pull/578#discussion_r705978850



##########
File path: website/blog/2021-08-10-apisix-nginx.md
##########
@@ -0,0 +1,516 @@
+---
+title: "Apache APISIX 架构分析:如何动态管理 Nginx 集群?"
+keywords: 
+- API 网关
+- Apache APISIX
+- Nginx
+- Lua
+- 动态管理
+date: "2021-08-10"
+description: 本文转发自陶辉个人博客,主要介绍了基于APISIX 2.8 版本、OpenResty 1.19.3.2 版本以及 Nginx 1.19.3 版本进行 Apache APISIX 实现 REST API 远程控制 Nginx 集群的原理讲解。
+tags: [technology]
+---
+
+<!--truncate-->
+> 作者陶辉
+
+开源版 Nginx 最为人诟病的就是不具备动态配置、远程 API 及集群管理的能力,而 Apache APISIX 作为 Apache 基金会毕业的开源七层网关,基于 etcd 和 Lua 实现了对 Nginx 集群的动态管理。
+
+![APISIX 架构图](https://static.apiseven.com/202108/1631170283612-ba5e27ff-726b-47a6-aa51-84731b067c44.png)
+
+让 Nginx 具备动态、集群管理能力并不容易,因为这将面临以下问题:
+
+* 微服务架构使得上游服务种类多、数量大,这导致路由规则、上游 Server 的变更极为频率。而 Nginx 的路由匹配是基于静态的 Trie 前缀树、哈希表、正则数组实现的,一旦`server_name`、`location` 变动,不执行 reload 就无法实现配置的动态变更
+* Nginx 将自己定位于 ADC 边缘负载均衡,因此它对上游并不支持 HTTP2 协议。这增大了 OpenResty 生态实现 etcd gRPC 接口的难度,因此通过 watch 机制接收配置变更必然效率低下
+* 多进程架构增大了 Worker 进程间的数据同步难度,必须选择 1 个低成本的实现机制,保证每个 Nginx 节点、Worker 进程都持有最新的配置
+
+Apache APISIX 基于 Lua 定时器及 lua-resty-etcd 模块实现了配置的动态管理,本文将基于 APISIX 2.8 版本、OpenResty 1.19.3.2 版本以及 Nginx 1.19.3 版本进行 Apache APISIX 实现 REST API 远程控制 Nginx 集群的原理。
+
+## 基于 etcd watch 机制的配置同步方案
+
+管理集群必须依赖中心化的配置,etcd 就是这样一个数据库。Apache APISIX 没有选择关系型数据库作为配置中心,是因为 etcd 具有以下 2 个优点:
+
+* etcd 采用类 Paxos 的 Raft 协议保障了数据一致性,它是去中心化的分布式数据库,可靠性高于关系数据库
+* etcd 的 watch 机制允许客户端监控某个 key 的变动,即,若类似 /nginx/http/upstream 这种 key 的 value 值发生变动,watch 客户端会立刻收到通知,如下图所示:
+![基于 etcd 同步 nginx 配置](https://static.apiseven.com/202108/1631170345853-f020a64d-3e97-49c0-8395-c9e4e9cf4233.jpeg)
+
+因此,不同于 Orange 和 Kong,Apache APISIX 采用了 etcd 作为中心化的配置组件。
+
+因此,你可以在生产环境的 Apache APISIX 中通过 etcdctl 看到如下类似配置:

Review comment:
       两个 `因此`,去掉后面这个




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org