membphis commented on a change in pull request #1296: add chinese version URL: https://github.com/apache/incubator-apisix/pull/1296#discussion_r395416616
########## File path: doc/getting-started-cn.md ########## @@ -0,0 +1,256 @@ +<!-- +# +# 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. +# +--> +[English](getting-started.md) +# 快速入门指南 + +本指南的目的是介绍如何使用 APISIX 来配置出一个安全的可以对外提供服务的 API。当您读完本指南,你需要自己安装一下 APISIX 应用,并准备好一个可以对外提供服务的 API,该服务将由 API key 进行访问保护。 + +本指南会使用到以下 GET 请求,该服务可以回显发送到这个 API 的传参。 + +```bash +$ curl --location --request GET "https://httpbin.org/get?foo1=bar1&foo2=bar2" +``` + +让我们来分析一下这个 URL 请求 + +- Scheme: HTTPS +- Host/Address: httpbin.org +- Port: 443 +- URI: /get +- Query Parameters: foo1, foo2 + +## 前提 + +- 本指南使用 docker 和 docker compose 来安装 APISIX。 但是, 如果您已经以其他方式安装了 APISIX ,您只需跳到 [第二步](getting-started-cn.md#第二步:-在-APISIX-中设置路由) 。 +- Curl:指南使用 Curl 命令进行 API 测试,但是您也可以使用您选择的任何其他工具( 例如 Postman )。 + +## 第一步: 安装 APISIX + +APISIX 可以多种操作环境中安装。[如何安装文档](how-to-build-cn.md#installation-via-source-release) 显示了多个平台中的安装步骤。 +为了快速入门,让我们基于 docker 容器的安装方式进行安装。为了启动 APISIX 服务,我们可以参照这个镜像文件[repository](https://github.com/apache/incubator-apisix-docker) 并切换到 example 文件夹下执行如下命令。 + +如下命令会启动 APISIX 服务并默认在 9080端口 (https请求是 9443 端口) 提供 admin API 接口服务 + +```bash +$ git clone https://github.com/apache/incubator-apisix-docker.git +$ cd example +$ docker-compose -p docker-apisix up -d +``` + +第一次下载源代码需要一段时间,之后将非常快。在 docker 容器启动后,请访问以下链接,检查您是否获得成功的响应。 + +```bash +$ curl "http://127.0.0.1:9080/apisix/admin/services/" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' +``` + +下面是 Admin API 的接口响应: + +```json +{ + "node": { + "createdIndex": 6, + "modifiedIndex": 6, + "key": "/apisix/services", + "dir": true + }, + "action": "get" +} +``` + +## 第二步: 在 APISIX 中创建 Route + +为了配置各种 routes / services / plugins ,APISIX 提供了强大的 Admin API 和一个[ web控制台 ](https://github.com/apache/incubator-apisix-dashboard)。 +本指南将会使用到 Admin API 接口。 + +一个微服务可以通过 APISIX 的路由、服务、上游和插件等多个实体之间的关系进行配置。 +路由与客户端请求匹配,并指定它们到达 APISIX 后如何发送到上游(后端 API 服务)。 +服务为上游服务提供了抽象。因此,您可以创建单个服务并在多个路由中引用它。 +查看架构文档以获取更多信息。 + +从技术上讲,所有这些信息(upstream、service、plugins)都可以包含在路由配置中。路由是由三个主要部分组成的。 + +- 路由匹配规则: + + 让我们来看看下面的场景 + http://example.com/services/users + + 上面的URL托管了系统中所有跟用户有关的(getUser/GetAllUsers)微服务。例如,可以通过URL( http://example.com/services/users/GetAllUsers ) 访问到 GetAllUsers 服务接口。 + 现在要公开 `users` 路径下的所有 `GET` 服务请求(微服务)。以下是匹配此类请求的路由配置。 + + ```json + { + "methods": ["GET"], + "host": "example.com", + "uri": "/services/users/*", + ... Additional Configurations + } + ``` + 通过上面的匹配规则你就可以通过如下的命令跟 APISIX 进行交互了 + + ```bash + curl -i -X GET "http://{apisix_server.com}:{port}/services/users/getAllUsers?limit=10" -H "Host: example.com" + ``` + +- Upstream 信息: + + Upstream 是一个虚拟主机抽象,它根据配置规则在给定的一组服务节点上执行负载平衡。 + 因此,单个上游配置可以由提供相同服务的多个服务器组成。每个节点将包括一个 key(地址/ip:port)和一个 value (节点的权重)。 + 服务可以通过循环或一致哈希(cHash)机制进行负载平衡。 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
