الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

fluent-bit

A small, fast agent that collects logs (and metrics) from files, journald and containers, changes them and sends them anywhere.

المستوى
خدمة DevSecOps
المجموعة
المراقبة والسجلات
يحتاج root
للتغييرات
الحزمة
fluent-bit

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

Fluent Bit (CNCF, part of Fluentd) runs on each host or as a DaemonSet in Kubernetes. A pipeline has inputs (tail, systemd, kubernetes events), filters (kubernetes metadata, grep, modify, lua, masking) and outputs (loki, es, azure_logs_ingestion, s3, forward, stdout). It uses little memory (a few MB), so it is the common choice for log shipping.

Config is classic .conf sections or YAML (fluent-bit.yaml).

طريقة الكتابة

fluent-bit -c CONFIG
fluent-bit -i INPUT -o OUTPUT [-p key=value]

الأجزاء الرئيسية

Pipeline parts

[INPUT] tail
Read log files (with position database).
[INPUT] systemd
Read the journal.
[FILTER] kubernetes
Add pod, namespace and labels.
[FILTER] grep
Keep or drop records by regex.
[FILTER] modify / record_modifier
Add, rename, remove fields.
[OUTPUT] loki
Send to Loki.
[OUTPUT] es
Send to Elasticsearch/OpenSearch.
[OUTPUT] azure_logs_ingestion
Send to Azure Monitor (DCR).
[OUTPUT] stdout
Print (debugging).

الخيارات 6

الأكثر استخدامًا

Command-line flags

-c FILE
Config file.
--dry-run
Check the config and exit.
-i NAME / -o NAME / -p k=v
Quick pipeline without a file.
-f SECONDS
Flush interval.
-v / -vv
More output.
-H
Enable the HTTP monitoring server (port 2020).

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Test quickly on the terminal

    fluent-bit -i cpu -o stdout -f 1
    fluent-bit -i systemd -p systemd_filter=_SYSTEMD_UNIT=sshd.service -o stdout
  2. 2Ship nginx logs to Loki

    cat /etc/fluent-bit/fluent-bit.conf
    [SERVICE]
        Flush        5
        HTTP_Server  On
    [INPUT]
        Name   tail
        Path   /var/log/nginx/access.log
        Tag    nginx.access
        DB     /var/lib/fluent-bit/nginx.db
    [OUTPUT]
        Name   loki
        Match  nginx.*
        Host   loki.lab.local
        Port   3100
        Labels job=nginx, host=${HOSTNAME}
  3. 3Check the config

    fluent-bit -c /etc/fluent-bit/fluent-bit.conf --dry-run
    systemctl restart fluent-bit
  4. 4Read the journal and drop debug lines

    cat /etc/fluent-bit/journal.conf
    [INPUT]
        Name            systemd
        Tag             host.*
        Read_From_Tail  On
    [FILTER]
        Name    grep
        Match   host.*
        Exclude PRIORITY ^7$
  5. 5Hide secrets before sending

    cat /etc/fluent-bit/mask.conf
    [FILTER]
        Name   modify
        Match  *
        Remove password
        Remove authorization
  6. 6Install on Kubernetes with Helm

    helm repo add fluent https://fluent.github.io/helm-charts
    helm install fluent-bit fluent/fluent-bit -n logging --create-namespace -f fluent-bit-values.yaml
    kubectl -n logging get ds fluent-bit
  7. 7Add Kubernetes metadata

    cat fluent-bit-values.yaml
    config:
      filters: |
        [FILTER]
            Name       kubernetes
            Match      kube.*
            Merge_Log  On
            Keep_Log   Off
  8. 8Watch its own health

    curl -s http://localhost:2020/api/v1/metrics | jq '.output'
    curl -s http://localhost:2020/api/v1/health
  9. 9Read its logs

    journalctl -u fluent-bit -f
  10. 10Send to Azure Monitor Logs

    cat /etc/fluent-bit/azure.conf
    [OUTPUT]
        Name            azure_logs_ingestion
        Match           *
        client_id       ${AZ_CLIENT_ID}
        client_secret   ${AZ_CLIENT_SECRET}
        tenant_id       ${AZ_TENANT_ID}
        dce_url         https://dce-lab-weu.westeurope-1.ingest.monitor.azure.com
        dcr_id          dcr-00000000000000000000000000000000
        table_name      Syslog_CL

انتبه

  • Logs often contain tokens, passwords and personal data: filter or mask them before they leave the host.
  • Without a DB file for tail, a restart re-sends or loses lines.
  • Use TLS (tls On) for outputs that leave the host.

الملفات

/etc/fluent-bit/fluent-bit.conf
Main config.
/etc/fluent-bit/parsers.conf
Parsers (json, regex, docker, cri).

نصائح للحفظ

  • Use Mem_Buf_Limit and storage.type filesystem so a slow backend does not eat all memory.

رموز الخروج

0Success.
1Error (bad config).

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man fluent-bit