You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Fluentd收集的日志转发至GCP Cloud Storage

Steps to Configure Fluentd to Forward Logs to GCP Cloud Storage

Prerequisites

  • GCP Cloud Storage bucket created
  • GCP Service Account with roles/storage.objectCreator permission assigned to the bucket
  • Service Account JSON key file downloaded locally

Step 1: Install the Fluentd GCS Plugin

Use the appropriate command based on your Fluentd distribution:

  • For vanilla Fluentd:
    gem install fluent-plugin-gcs
    
  • For td-agent (Treasure Data's Fluentd distribution):
    td-agent-gem install fluent-plugin-gcs
    

Step 2: Set Up GCP Authentication

Point Fluentd to your service account key file via environment variable:

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-service-account-key.json"

If running Fluentd as a system service, add this variable to your service configuration (e.g., systemd unit file for td-agent).

Step 3: Modify fluentd.conf

Update your configuration to add an output block for GCP Cloud Storage. You can retain the existing Loki output for dual delivery, or replace it if you only want logs sent to GCS.

Example Configuration Snippet

# Existing Docker source (keep this)
<source>
  @type docker
  tag docker.*
  path /var/lib/docker/containers/*/*-json.log
  pos_file /var/log/fluentd/docker.pos
  read_from_head true
</source>

# Optional existing filters (retain if you use them)
<filter docker.**>
  @type parser
  key_name log
  <parse>
    @type json
  </parse>
</filter>

# Existing Loki output (keep for dual delivery)
<match docker.**>
  @type loki
  url "http://loki:3100/loki/api/v1/push"
  <label>
    job "docker"
    container_name ${tag_parts[2]}
  </label>
</match>

# New GCS output block
<match docker.**>
  @type gcs

  project_id your-gcp-project-id
  bucket your-bucket-name
  path logs/%Y/%m/%d/
  format json
  compression gzip
  buffer_chunk_limit 100MB
  buffer_queue_limit 10
  flush_interval 10m
  timezone UTC

  # Uncomment below if not using the environment variable for credentials
  # credentials /path/to/your-service-account-key.json
</match>

Key Configuration Details

  • project_id: Your GCP project ID where the bucket is hosted
  • bucket: Exact name of your Cloud Storage bucket
  • path: Chronological directory structure using time variables (e.g., %Y for year, %m for month) to organize logs
  • format: Output format for logs (json is recommended for structured data)
  • compression: gzip reduces storage and bandwidth costs
  • buffer settings: Adjust based on your log volume to balance upload frequency and file size

Step 4: Restart Fluentd

Apply changes by restarting the service:

# For td-agent
sudo systemctl restart td-agent

# For vanilla Fluentd
sudo systemctl restart fluentd

Step 5: Verify Log Delivery

Check your GCP Cloud Storage bucket after the configured flush_interval—you should see compressed log files in the specified path.

内容的提问来源于stack exchange,提问作者Aditya Sahu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 05:20:32