membphis commented on a change in pull request #1281: feature: Support for using Eureka as a service discovery center URL: https://github.com/apache/incubator-apisix/pull/1281#discussion_r398477526
########## File path: doc/discovery-cn.md ########## @@ -0,0 +1,122 @@ +<!-- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +--> + +# 集成服务发现注册中心 + +## 摘要 + +当业务量发生变化时,需要对下游服务进行扩缩容,或者因服务器硬件故障需要更换服务器。如果网关是通过配置来维护这些信息,在微服务架构模式下,其带来的维护成本可想而知。再者因不能及时更新这些信息,也会对业务带来一定的影响,所以网关非常必要通过服务注册中心来获取最新的服务实例列表。架构图如下所示: + + + +1. 服务启动时将自身的一些信息,比如服务名、IP、端口等信息注册到注册中心,并通过心跳等机制告诉注册中心,可以正常提供服务;当服务下线时,会修改注册中心的状态或删除数据; +2. 网关会准实时地从注册中心获取服务实例信息; +3. 当用户通过网关请求服务时,网关将请求代理到从注册中心获取的实例列表中的一台服务器; + +常见的注册中心:Eureka, Etcd, Consul, Zookeeper, Nacos等 + +## 开启服务发现 + +首先要在 `conf/config.yaml` 文件中增加如下配置,以选择注册中心的类型: + +```yaml +apisix: + discovery: eureka +``` + +现已经支持 `Eureka` 注册中心。 + +## 注册中心配置 + +### Eureka 的配置 + +在 `conf/config.yaml` 增加如下格式的配置: + +```yaml +eureka: + host: # it's possible to define multiple eureka hosts addresses of the same eureka cluster. + - "http://${usename}:${passowrd}@${eureka_host1}:${eureka_port1}" + - "http://${usename}:${passowrd}@${eureka_host2}:${eureka_port2}" + prefix: "/eureka/" + timeout: + connect: 2000 + send: 2000 + read: 5000 +``` + +通过 `eureka.host ` 配置 eureka 的服务器地址。 + +如果 eureka 的地址是 `http://127.0.0.1:8761/` ,并且不需要用户名和密码验证的话,配置如下: + +```yaml +eureka: + host: + - "http://127.0.0.1:8761" + prefix: "/eureka/" +``` + +## upstream 配置 + +APISIX是通过 `upstream.service_name` 与注册中心的服务名进行关联。下面是 uri 为 "/a/*" 的请求路由到注册中心名为 "a_service" 的服务上例子: + +```shell +$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +{ + "uri": "/a/*", + "upstream": Review comment: missing curly braces `{ ... }` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
