هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
service:
flush: 1
http_server: on
http_listen: 127.0.0.1
http_port: 2020
storage.path: /var/lib/fluent-bit/buffer
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
- name: systemd
tag: host.journal
read_from_tail: on
storage.type: filesystem
outputs:
- name: loki
match: '*'
host: loki.example.com
port: 3100
labels: job=fluent-bit, host=web01/opt/fluent-bit/bin/fluent-bit -c /etc/fluent-bit/fluent-bit.yaml --dry-run
systemctl restart fluent-bitStep by step
- Install Fluent Bit (see the full guide) and make the service use the YAML file with a
systemctl edit fluent-bitoverride (ExecStart=then the new line with-c /etc/fluent-bit/fluent-bit.yaml). - Test with stdout first — replace the output with
- name: stdoutandmatch: '*', run Fluent Bit in the foreground, and look at the records:
/opt/fluent-bit/bin/fluent-bit -c /etc/fluent-bit/fluent-bit.yamlYou see records with the parsed nginx fields (remote, code, path …). When they look right, switch back to the Loki output.
- Inputs —
tailreads files and remembers the position in thedbfile (no duplicates after a restart).systemdreads the journal; addsystemd_filter: _SYSTEMD_UNIT=sshd.serviceto take one unit only. - Buffer on disk —
storage.pathplusstorage.type: filesystemkeeps logs when Loki is down and sends them later. - Labels — keep them few and fixed (
job,host,env). Do not use user IDs or IPs as labels. - Filters — drop noise before it costs money:
filters:
- name: grep
match: nginx.access
exclude: path ^/healthz- Check health and counters — the built-in HTTP server shows records in and out, errors and retries:
curl -s http://127.0.0.1:2020/api/v1/metrics | jq '.output'
curl -s http://127.0.0.1:2020/api/v1/health- Kubernetes — use the Helm chart (DaemonSet on every node) with the
kubernetesfilter, which adds namespace, pod and container labels.
Check that it worked
--dry-run says the configuration is valid; the metrics show growing proc_records for the output and zero errors; in Loki logcli query '{job="fluent-bit", host="web01"}' --since=5m returns the newest nginx and journal lines.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| No records from the file | Wrong path, or no read rights on /var/log/nginx. | Check the path; run as root or add the user to adm. |
| Old lines sent again after restart | No db file for tail. | Add db:; keep /var/lib/fluent-bit on disk. |
Output errors and retries grow | Loki not reachable, wrong port, or rejects labels. | curl Loki /ready; check firewall; fewer labels. |
| Java stack traces split into many lines | One record per line. | A multiline.parser (for example java) on the input. |
| Memory grows when the network is down | Memory buffer only. | storage.type: filesystem and storage.path. |
| The service still uses the old config | The unit starts fluent-bit.conf. | The systemctl edit override; systemctl daemon-reload. |
Go further
- Command pages: fluent-bit, curl, jq.
- Next how-tos: Search logs with Loki and LogQL, Keep the journal after reboot and limit its size, Rotate log files with logrotate, Trace requests with OpenTelemetry.
- Learn it: Observability services — Fluent Bit, Observability tools at work — Loki. Full guide: Fluent Bit.
1Why does the tail input need a db file?
It stores how far each file was read, so after a restart Fluent Bit continues there instead of sending old lines again.
2What does filesystem storage protect against?
When the output is down, records wait on disk instead of filling memory or being lost.