Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: sync stream proxy Chinese version #5793

Merged
merged 5 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/zh/latest/admin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -985,11 +985,13 @@ $ curl "http://127.0.0.1:9080/apisix/admin/plugins/key-auth" -H 'X-API-KEY:

| 名字 | 可选项| 类型 | 说明 | 示例 |
| ---------------- | ------| -------- | ------| -----|
| remote_addr | 可选 | IP/CIDR | 客户端 IP 地址 | "127.0.0.1/32" 或 "127.0.0.1" |
| server_addr | 可选 | IP/CIDR | 服务端 IP 地址 | "127.0.0.1/32" 或 "127.0.0.1" |
| server_port | 可选 | 整数 | 服务端端口 | 9090 |
| sni | 可选 | Host | 服务器名称指示| "test.com" |
| upstream | 可选 | Upstream | 启用的 Upstream 配置,详见 [Upstream](architecture-design/upstream.md) | |
| upstream_id | 可选 | Upstream | 启用的 upstream id,详见 [Upstream](architecture-design/upstream.md) | |
| remote_addr | 可选 | IP/CIDR | 过滤选项:如果客户端 IP 匹配,则转发到上游 | "127.0.0.1/32" 或 "127.0.0.1" |
| server_addr | 可选 | IP/CIDR | 过滤选项:如果 APISIX 服务器 IP 与 server_addr 匹配,则转发到上游 | "127.0.0.1/32" 或 "127.0.0.1" |
| server_port | 可选 | 整数 | 过滤选项:如果 APISIX 服务器 port 与 server_port 匹配,则转发到上游 | 9090 |
| sni | 可选 | Host | 服务器名称指示| "test.com" |
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved

点击 [此处](./stream-proxy.md#more-route-match-options),了解更多有关过滤器如何工作的信息。

[Back to TOC](#目录)
68 changes: 67 additions & 1 deletion docs/zh/latest/stream-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03

## 更多 route 匹配选项

我们可以添加更多的选项来匹配 route。
我们可以添加更多的选项来匹配 route。目前 Stream Route 配置支持 3 个字段进行过滤:

- server_addr: 接受 Stream Route 连接的 APISIX 服务器的地址。
- server_port: 接受 Stream Route 连接的 APISIX 服务器的端口。
- remote_addr: 发出请求的客户端地址。

例如

Expand All @@ -92,6 +96,68 @@ curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f03

例子中 APISIX 会把服务器地址为 `127.0.0.1`, 端口为 `2000` 代理到上游地址 `127.0.0.1:1995`。

让我们再举一个实际场景的例子:

1. 将此配置放在 `config.yaml` 中

```yaml
apisix:
stream_proxy: # TCP/UDP proxy
tcp: # TCP proxy address list
- 9100 # by default uses 0.0.0.0
- "127.0.0.10:9101"
```

2. 现在运行一个 mysql docker 容器并将端口 3306 暴露给主机

```shell
$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=toor -p 3306:3306 -d mysql
# check it using a mysql client that it works
$ mysql --host=127.0.0.1 --port=3306 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
...
mysql>
```

3. 现在我们将创建一个带有服务器过滤的 stream 路由:

```shell
curl http://127.0.0.1:9080/apisix/admin/stream_routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"server_addr": "127.0.0.10",
"server_port": 9101,
"upstream": {
"nodes": {
"127.0.0.1:3306": 1
},
"type": "roundrobin"
}
}'
```

每当 APISIX 服务器 `127.0.0.10` 和端口 `9101` 收到连接时,它只会将请求转发到 mysql 上游。让我们测试一下:

4. 向 `9100` 发出请求(在 config.yaml 中启用 stream 代理端口),过滤器匹配失败。

```shell
$ mysql --host=127.0.0.1 --port=9100 -u root -p
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any special output in the apisix logs at the time of this error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not clear on this, I've just updated the English part here, Do you have any good advice?

```

下面的请求匹配到了 stream 路由,所以它可以正常代理到 mysql。

```shell
mysql --host=127.0.0.10 --port=9101 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
...
mysql>
```

完整的匹配选项列表参见 [Admin API 的 Stream Route](./admin-api.md#stream-route)。

## 接收 TLS over TCP
Expand Down