هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
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.
| Item | Value |
|---|---|
| Package | fluent-bit (repository from packages.fluentbit.io) |
| Binary | /opt/fluent-bit/bin/fluent-bit |
| Service | fluent-bit.service |
| Config | /etc/fluent-bit/ (classic .conf or YAML .yaml) |
| Parsers | /etc/fluent-bit/parsers.conf |
| Health and metrics | HTTP server on port 2020 (when enabled) |
| Buffer and positions | for example /var/lib/fluent-bit/ |
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.1In 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.
First configuration: a YAML pipeline
Read the nginx logs and the system journal, add the host name, buffer on disk, send to Loki:
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| Setting | Why |
|---|---|
db: on inputs | Remembers the read position — no duplicate or lost lines after a restart. |
storage.type: filesystem + storage.path | Buffers on disk when the output is down (no lost logs). |
mem_buf_limit | One busy input can not use all memory. |
parser: nginx | Turns the access line into fields (status, path, IP). |
grep … exclude | Drop noise (health checks) before it costs storage. |
health_check + http_server on localhost | A health URL and Prometheus metrics. |
The service starts the classic config by default. Point it to the YAML file, check it, start:
[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
okSend to Elasticsearch (or more outputs)
One record can go to more than one place. Add an Elasticsearch output with TLS and an API key:
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.
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/bufferReal 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).
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.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
[error] [config] … invalid at start | YAML indentation, or a classic option in YAML. | fluent-bit -c FILE --dry-run; check spaces (no tabs). |
| Service still uses the old config | The unit starts fluent-bit.conf. | The systemctl edit override above; daemon-reload. |
| Lines sent twice after a restart | No db: on the tail input. | Add db: for every tail input. |
| Logs lost when the output was down | Memory 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_exception | A field has different types in different records. | Fix the parser; use an index template; rename the field with a filter. |
| No journal records | The service user can not read the journal. | Run as root (default) or add the user to systemd-journal. |
Next steps
- Quick how-tos: Ship logs to Loki, Search them with LogQL.
- Command page: fluent-bit.
- Where the logs go: Grafana Loki, Elasticsearch + Kibana.
- At work: Ship the logs.
- In Kubernetes: Install and set up Helm.
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.