

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将 OpenSearch 采集管道与 Fluentd 配合使用
<a name="configure-client-fluentd"></a>

Fluentd是一个开源数据收集生态系统，它提供了 SDKs 不同的语言和子项目，例如Fluent Bit。此示例 [Fluentd 配置文件](https://docs.fluentd.org/output/http#example-configuration)将日志数据从 Fluentd 发送到摄取管道。 OpenSearch 有关摄取日志数据的更多信息，请参阅 Data Prepper 文档中的[日志分析](https://github.com/opensearch-project/data-prepper/blob/main/docs/log_analytics.md)。

注意以下几点：
+ `endpoint` 值必须是管道端点。例如 `pipeline-endpoint.us-east-1osis.amazonaws.com/apache-log-pipeline/logs`。
+ `aws_service` 值必须为 `osis`。
+ 该`aws_role_arn`值是 AWS IAM 角色的 ARN，供客户端代入并用于签名版本 4 身份验证。

```
<source>
  @type tail
  path logs/sample.log
  path_key log
  tag apache
  <parse>
    @type none
  </parse>
</source>

<filter apache>
  @type record_transformer
  <record>
    log ${record["message"]}
  </record>
</filter>

<filter apache>
  @type record_transformer
  remove_keys message
</filter>

<match apache>
  @type http
  endpoint pipeline-endpoint.us-east-1osis.amazonaws.com/apache-log-pipeline/logs
  json_array true

  <auth>
    method aws_sigv4
    aws_service osis
    aws_region region
    aws_role_arn arn:aws:iam::account-id:role/ingestion-role
  </auth>

  <format>
    @type json
  </format>

  <buffer>
    flush_interval 1s
  </buffer>
</match>
```

然后，您可以配置如下所示的 OpenSearch 采集管道，该管道以 HTTP 为源：

```
version: "2"
apache-log-pipeline:
  source:
    http:
      path: "/${pipelineName}/logs"
  processor:
    - grok:
        match:
          log:
            - "%{TIMESTAMP_ISO8601:timestamp} %{NOTSPACE:network_node} %{NOTSPACE:network_host} %{IPORHOST:source_ip}:%{NUMBER:source_port:int} -> %{IPORHOST:destination_ip}:%{NUMBER:destination_port:int} %{GREEDYDATA:details}"
  sink:
    - opensearch:
        hosts: ["https://search-domain-endpoint.us-east-1es.amazonaws.com"]
        index: "index_name"
        aws_region: "region"
        aws_sigv4: true
```