متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 38Fluent Bit · Monitoring

Install and set up Fluent Bit (log shipper)

Fluent Bit collects logs (and metrics) on servers and in Kubernetes, cleans and enriches them, and sends them anywhere: Loki, Elasticsearch/OpenSearch, Splunk, S3, Kafka, cloud logging. It is small (a few MB of RAM), fast, and the default log agent in many Kubernetes platforms. This guide installs Fluent Bit on RHEL and Ubuntu, writes a YAML pipeline (inputs → filters → outputs) with a disk buffer, sends logs to Loki and Elasticsearch, and covers health checks and the common problems.

  • 9 الدروس
  • 11 الأوامر

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

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

38.1

Know it before you install

A pipeline has inputs (read: files, journald, syslog, Kubernetes), parsers (turn text into fields), filters (add, change or drop fields and records) and outputs (send). Every record has a tag; filters and outputs choose records with match.

ItemValue
Packagefluent-bit (repository from packages.fluentbit.io)
Binary/opt/fluent-bit/bin/fluent-bit
Servicefluent-bit.service
Config/etc/fluent-bit/ (classic .conf or YAML .yaml)
Parsers/etc/fluent-bit/parsers.conf
Health and metricsHTTP server on port 2020 (when enabled)
Buffer and positionsfor example /var/lib/fluent-bit/

38.2

Install on RHEL and Ubuntu

The official script adds the right repository for your distribution and installs the package:

curl -fsSL https://raw.githubusercontent.com/fluent/fluent-bit/master/install.sh -o /tmp/fluent-bit-install.sh
less /tmp/fluent-bit-install.sh
sh /tmp/fluent-bit-install.sh
/opt/fluent-bit/bin/fluent-bit --version
Fluent Bit v4.1.1

In Kubernetes use the Helm chart instead (helm repo add fluent https://fluent.github.io/helm-charts, chart fluent/fluent-bit) — it runs as a DaemonSet on every node.

38.3

First configuration: a YAML pipeline

Read the nginx logs and the system journal, add the host name, buffer on disk, send to Loki:

/etc/fluent-bit/fluent-bit.yaml
service:
  flush: 1
  log_level: info
  http_server: on
  http_listen: 127.0.0.1
  http_port: 2020
  health_check: on
  storage.path: /var/lib/fluent-bit/buffer
  storage.sync: normal
  parsers_file: /etc/fluent-bit/parsers.conf
 
pipeline:
  inputs:
    - name: tail
      tag: nginx.access
      path: /var/log/nginx/access.log
      parser: nginx
      db: /var/lib/fluent-bit/tail-nginx.db
      storage.type: filesystem
      mem_buf_limit: 50MB
 
    - name: systemd
      tag: host.journal
      db: /var/lib/fluent-bit/journal.db
      strip_underscores: on
      storage.type: filesystem
 
  filters:
    - name: record_modifier
      match: "*"
      record:
        - host web1
        - env prod
 
    - name: grep
      match: nginx.access
      exclude: path ^/health
 
  outputs:
    - name: loki
      match: "*"
      host: loki.example.com
      port: 3100
      labels: job=fluent-bit, host=web1, env=prod
      line_format: json
      storage.total_limit_size: 1G
SettingWhy
db: on inputsRemembers the read position — no duplicate or lost lines after a restart.
storage.type: filesystem + storage.pathBuffers on disk when the output is down (no lost logs).
mem_buf_limitOne busy input can not use all memory.
parser: nginxTurns the access line into fields (status, path, IP).
grep … excludeDrop noise (health checks) before it costs storage.
health_check + http_server on localhostA health URL and Prometheus metrics.

The service starts the classic config by default. Point it to the YAML file, check it, start:

mkdir -p /var/lib/fluent-bit/buffer
systemctl edit fluent-bit
/etc/systemd/system/fluent-bit.service.d/override.conf
[Service]
ExecStart=
ExecStart=/opt/fluent-bit/bin/fluent-bit -c /etc/fluent-bit/fluent-bit.yaml
/opt/fluent-bit/bin/fluent-bit -c /etc/fluent-bit/fluent-bit.yaml --dry-run
configuration test is successful
systemctl daemon-reload
systemctl enable --now fluent-bit
systemctl restart fluent-bit
curl -s http://127.0.0.1:2020/api/v1/health
ok

38.4

Send to Elasticsearch (or more outputs)

One record can go to more than one place. Add an Elasticsearch output with TLS and an API key:

/etc/fluent-bit/fluent-bit.yaml
  outputs:
    - name: es
      match: nginx.*
      host: 10.0.2.11
      port: 9200
      tls: on
      tls.verify: on
      tls.ca_file: /etc/fluent-bit/es-ca.crt
      http_api_key: ${ES_API_KEY}
      index: logs-nginx
      suppress_type_name: on
      storage.total_limit_size: 1G

(Put ES_API_KEY=… in an environment file for the service, for example with EnvironmentFile=/etc/fluent-bit/secrets.env in the override, mode 600.)

Quick test output while you build the pipeline: - name: stdout with match: "*", then journalctl -u fluent-bit -f.

38.5

Daily use: the commands and the real uses

systemctl status fluent-bit
journalctl -u fluent-bit -f
curl -s http://127.0.0.1:2020/api/v1/metrics | jq .
curl -s http://127.0.0.1:2020/api/v2/metrics/prometheus | grep -E 'output_(proc|errors|retries)'
curl -s http://127.0.0.1:2020/api/v1/storage | jq .
du -sh /var/lib/fluent-bit/buffer

Real uses at work:

  • One agent on every server and every Kubernetes node, sending to Loki, Elasticsearch or a SIEM.
  • Clean logs at the source: parse, drop noise, mask secrets and personal data before they leave the host.
  • Send to two places during a migration (old SIEM and new one).

38.6

Make it safe

Security checklist:

  • TLS to every output that leaves the host; verify certificates.
  • Secrets (API keys, passwords) from environment files with mode 600, not in the YAML.
  • Mask or drop sensitive fields (modify, record_modifier, Lua filters) — tokens, passwords, card numbers.
  • HTTP server only on 127.0.0.1 (or firewall port 2020).
  • Disk buffer with a size limit, so a long outage can not fill the disk.
  • Pin the version; update with the package manager.

38.7

Update and remove

dnf -y upgrade fluent-bit
apt-get install --only-upgrade -y fluent-bit
systemctl restart fluent-bit
dnf -y remove fluent-bit

38.8

Fix common problems

ProblemCauseFix
[error] [config] … invalid at startYAML indentation, or a classic option in YAML.fluent-bit -c FILE --dry-run; check spaces (no tabs).
Service still uses the old configThe unit starts fluent-bit.conf.The systemctl edit override above; daemon-reload.
Lines sent twice after a restartNo db: on the tail input.Add db: for every tail input.
Logs lost when the output was downMemory buffer only.storage.type: filesystem + storage.path.
[warn] … pausing (mem buf overlimit)The input reads faster than the output sends.Disk buffer; check the output; raise mem_buf_limit a little.
Elasticsearch mapper_parsing_exceptionA field has different types in different records.Fix the parser; use an index template; rename the field with a filter.
No journal recordsThe service user can not read the journal.Run as root (default) or add the user to systemd-journal.

38.9

Next steps

1Why add db: to a tail input?

Fluent Bit saves the read position there, so after a restart it does not send lines again or skip lines.

2The log backend was down for one hour. How do you make sure no logs were lost?

Use a disk buffer: storage.type: filesystem with storage.path.

كل الأوامر في هذا الفصل