mirror of https://github.com/istio/istio.io.git
zh: update tasks/observability/logs/access-log file (#11024)
This commit is contained in:
parent
02a474d1c1
commit
98f9d9822b
|
@ -2,7 +2,7 @@
|
|||
title: 获取 Envoy 访问日志
|
||||
description: 此任务向您展示如何配置 Envoy 代理将访问日志打印到其标准输出。
|
||||
weight: 10
|
||||
keywords: [telemetry]
|
||||
keywords: [telemetry,logs]
|
||||
aliases:
|
||||
- /zh/docs/tasks/telemetry/access-log
|
||||
- /zh/docs/tasks/telemetry/logs/access-log/
|
||||
|
@ -18,24 +18,92 @@ Istio 最简单的日志类型是 [Envoy 的访问日志](https://www.envoyproxy
|
|||
|
||||
## 开启 Envoy 访问日志{#enable-envoy-s-access-logging}
|
||||
|
||||
修改 `istio` 配置文件:
|
||||
Istio 提供了几种启用访问日志的方法。建议使用遥测 API。
|
||||
|
||||
{{< text bash >}}
|
||||
$ istioctl manifest apply --set values.global.proxy.accessLogFile="/dev/stdout"
|
||||
configmap "istio" replaced
|
||||
### 使用 Telemetry API{#using-telemetry-API}
|
||||
|
||||
遥测 API 可以开启或关闭访问日志:
|
||||
|
||||
{{< text yaml >}}
|
||||
apiVersion: telemetry.istio.io/v1alpha1
|
||||
kind: Telemetry
|
||||
metadata:
|
||||
name: mesh-default
|
||||
namespace: istio-system
|
||||
spec:
|
||||
accessLogging:
|
||||
- providers:
|
||||
- name: envoy
|
||||
{{< /text >}}
|
||||
|
||||
上面的示例使用默认的 `envoy` 访问日志提供程序,除了默认设置外,我们没有配置任何其他内容。
|
||||
|
||||
类似的配置也可以应用于单独的名称空间或单独的工作负载,以在细粒度级别控制日志记录。
|
||||
|
||||
有关使用遥测API的详细信息,请参见 [Telemetry API 概览](/zh/docs/tasks/observability/telemetry/).
|
||||
|
||||
### 使用 Mesh 配置{$using-mesh-config}
|
||||
|
||||
如果你使用 `IstioOperator` CR来安装 Istio,请在你的配置中添加以下字段:
|
||||
|
||||
{{< text yaml >}}
|
||||
spec:
|
||||
meshConfig:
|
||||
accessLogFile: /dev/stdout
|
||||
{{< /text >}}
|
||||
|
||||
您也可以通过设置 `accessLogEncoding` 为 `JSON` 或 `TEXT` 来在两种格式之间切换。
|
||||
|
||||
您也许希望通过设置 `accessLogFormat` 来自定义访问日志的[格式](https://www.envoyproxy.io/docs/envoy/latest/configuration/observability/access_log/usage#format-rules)。
|
||||
|
||||
{{< tip >}}
|
||||
这三种参数也可以通过[安装选项](/zh/docs/reference/config/installation-options/)来进行配置:
|
||||
{{< /tip >}}
|
||||
更多信息请参考[global mesh options](/zh/docs/reference/config/istio.mesh.v1alpha1/#MeshConfig)在这三个设置中:
|
||||
|
||||
* `global.proxy.accessLogFile`
|
||||
* `global.proxy.accessLogEncoding`
|
||||
* `global.proxy.accessLogFormat`
|
||||
* `meshConfig.accessLogFile`
|
||||
* `meshConfig.accessLogEncoding`
|
||||
* `meshConfig.accessLogFormat`
|
||||
|
||||
## 默认访问日志格式{#default-access-log-format}
|
||||
|
||||
如果没有指定 `accessLogFormat` Istio 将使用以下默认的访问日志格式:
|
||||
|
||||
{{< text plain >}}
|
||||
[%START_TIME%] \"%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%\" %RESPONSE_CODE% %RESPONSE_FLAGS% %RESPONSE_CODE_DETAILS% %CONNECTION_TERMINATION_DETAILS%
|
||||
\"%UPSTREAM_TRANSPORT_FAILURE_REASON%\" %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% \"%REQ(X-FORWARDED-FOR)%\" \"%REQ(USER-AGENT)%\" \"%REQ(X-REQUEST-ID)%\"
|
||||
\"%REQ(:AUTHORITY)%\" \"%UPSTREAM_HOST%\" %UPSTREAM_CLUSTER% %UPSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_LOCAL_ADDRESS% %DOWNSTREAM_REMOTE_ADDRESS% %REQUESTED_SERVER_NAME% %ROUTE_NAME%\n
|
||||
{{< /text >}}
|
||||
|
||||
下表显示了一个使用默认的访问日志格式的示例,请求从 `sleep` 发送到 `httpbin`:
|
||||
|
||||
| Log operator | access log in sleep | access log in httpbin |
|
||||
|--------------|---------------------|-----------------------|
|
||||
| `[%START_TIME%]` | `[2020-11-25T21:26:18.409Z]` | `[2020-11-25T21:26:18.409Z]`
|
||||
| `\"%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%\"` | `"GET /status/418 HTTP/1.1"` | `"GET /status/418 HTTP/1.1"`
|
||||
| `%RESPONSE_CODE%` | `418` | `418`
|
||||
| `%RESPONSE_FLAGS%` | `-` | `-`
|
||||
| `%RESPONSE_CODE_DETAILS%` | `via_upstream` | `via_upstream`
|
||||
| `%CONNECTION_TERMINATION_DETAILS%` | `-` | `-`
|
||||
| `\"%UPSTREAM_TRANSPORT_FAILURE_REASON%\"` | `"-"` | `"-"`
|
||||
| `%BYTES_RECEIVED%` | `0` | `0`
|
||||
| `%BYTES_SENT%` | `135` | `135`
|
||||
| `%DURATION%` | `4` | `3`
|
||||
| `%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%` | `4` | `1`
|
||||
| `\"%REQ(X-FORWARDED-FOR)%\"` | `"-"` | `"-"`
|
||||
| `\"%REQ(USER-AGENT)%\"` | `"curl/7.73.0-DEV"` | `"curl/7.73.0-DEV"`
|
||||
| `\"%REQ(X-REQUEST-ID)%\"` | `"84961386-6d84-929d-98bd-c5aee93b5c88"` | `"84961386-6d84-929d-98bd-c5aee93b5c88"`
|
||||
| `\"%REQ(:AUTHORITY)%\"` | `"httpbin:8000"` | `"httpbin:8000"`
|
||||
| `\"%UPSTREAM_HOST%\"` | `"10.44.1.27:80"` | `"127.0.0.1:80"`
|
||||
| `%UPSTREAM_CLUSTER%` | <code>outbound|8000||httpbin.foo.svc.cluster.local</code> | <code>inbound|8000||</code>
|
||||
| `%UPSTREAM_LOCAL_ADDRESS%` | `10.44.1.23:37652` | `127.0.0.1:41854`
|
||||
| `%DOWNSTREAM_LOCAL_ADDRESS%` | `10.0.45.184:8000` | `10.44.1.27:80`
|
||||
| `%DOWNSTREAM_REMOTE_ADDRESS%` | `10.44.1.23:46520` | `10.44.1.23:37652`
|
||||
| `%REQUESTED_SERVER_NAME%` | `-` | `outbound_.8000_._.httpbin.foo.svc.cluster.local`
|
||||
| `%ROUTE_NAME%` | `default` | `default`
|
||||
|
||||
否则,在原来的 `istioctl install` 命令中添加相同的设置,例如:
|
||||
|
||||
{{< text syntax=bash snip_id=none >}}
|
||||
$ istioctl install <flags-you-used-to-install-Istio> --set meshConfig.accessLogFile=/dev/stdout
|
||||
{{< /text >}}
|
||||
|
||||
## 测试访问日志{#test-the-access-log}
|
||||
|
||||
|
@ -92,9 +160,16 @@ $ kubectl delete -f @samples/httpbin/httpbin.yaml@
|
|||
|
||||
### 关闭 Envoy 的访问日志{#disable-envoy-s-access-logging}
|
||||
|
||||
编辑 `istio` 配置文件然后设置 `accessLogFile` 为 `""`。
|
||||
编辑 `istio` 配置文件然后设置 `meshConfig.accessLogFile` 为 `""`。
|
||||
|
||||
{{< tip >}}
|
||||
在下面的例子中,将 `default` 替换为安装 Istio 时使用的配置文件的名称。
|
||||
{{< /tip >}}
|
||||
|
||||
{{< text bash >}}
|
||||
$ istioctl manifest apply
|
||||
configmap "istio" replaced
|
||||
$ istioctl install --set profile=default
|
||||
✔ Istio core installed
|
||||
✔ Istiod installed
|
||||
✔ Ingress gateways installed
|
||||
✔ Installation complete
|
||||
{{< /text >}}
|
||||
|
|
Loading…
Reference in New Issue