首页 > 解决方案 > Fluentd:将多个容器日志存储在一个文件中(AWS S3)

问题描述

我想将多个容器日志存储在 AWS S3 的单个文件中。

我们有一个应用程序的多个组件,比如说ui、server、engine、alert。所有在 AWS EKS 集群中作为 pod 运行。

我有一个FluentD 守护程序集,用于将 S3 中的所有日志存储在单独的文件中(s3://app/app-ui-1.log、s3://app/app-server-1.log、s3://app/app -engine-1.log, s3://app/app-alert-1.log),工作正常。


但我的要求是将所有组件日志存储一个文件中-> s3://app/app-all-logs/1.log

内容应该喜欢

<TIMESTAMP> UI-Log message
<TIMESTAMP> UI-Log message
<TIMESTAMP> SERVER-Log message
<TIMESTAMP> ENGINE-Log message

我尝试使用以下 FluentD 配置,但它将每个组件的日志存储在单独的文件中,例如

UI日志转到 s3://app/app-all-logs/ 1.log

服务器日志转到 s3://app/app-all-logs/ 2.log

引擎日志转到 s3://app/app-all-logs/ 3.log

FluentD 配置文件:

<source>
  @type tail
  path /var/log/containers/app-*.log
  pos_file /var/log/all/all.log.pos
  tag all.**
  <parse>
    @type none
  </parse>
  read_from_head true
</source>


<match all.**>
   @type s3

   aws_key_id "#{ENV['AWS_ACCESS_KEY']}"
   aws_sec_key "#{ENV['AWS_SECRET_ACCESS_KEY']}"
   s3_bucket "#{ENV['S3_LOGS_BUCKET_NAME']}"
   s3_region "#{ENV['S3_LOGS_BUCKET_REGION']}"
   path "#{ENV['S3_LOGS_BUCKET_PREFIX']}"
   s3_object_key_format %{path}/app-all-logs/%Y%m%d/%{index}.log

   buffer_chunk_limit 20m
   buffer_path /var/log/all/fluentd-buffer
   store_as log
   flush_interval 600s
   time_slice_format %Y/%m/%d
   utc

   <format>
      @type single_value
   </format>

   <instance_profile_credentials>
     ip_address IP_ADDRESS
     port       PORT
   </instance_profile_credentials>
</match>

标签: amazon-s3kubernetesloggingfluentdfluent-docker

解决方案


推荐阅读