Filebeat is the lightweight log shipper in the Elastic stack — it tails files, tracks position, and forwards events to Logstash or Elasticsearch with at-least-once delivery. This article installs Filebeat on Ubuntu, configures inputs for system and application logs, enables built-in modules (nginx, system, mysql), and ships safely to a downstream pipeline. Audience is operators bringing a new host into an existing ELK setup.
How to verify
After install and config, confirm Filebeat is shipping:
systemctl status filebeat
journalctl -u filebeat -n 50 --no-pager
sudo filebeat test config
sudo filebeat test output
sudo filebeat modules list
curl -sk -u elastic:"$PW" 'https://es:9200/_cat/indices/filebeat-*?v'
Healthy operation: test output returns “OK”, journal shows “Harvester started”, and indices like filebeat-8.x.x-YYYY.MM.dd exist on the cluster.
What’s happening
Filebeat is a Go binary with a registry file (/var/lib/filebeat/registry/) that tracks the inode and read offset of every harvested file. After a restart, it resumes from the last acknowledged position — so log lines aren’t duplicated or skipped under normal conditions.
The shipper has three input types:
filestream— modern file input (replaces deprecatedloginput). Handles rotated files, follows symlinks, supports multiline.journald— reads systemd journal entries.udp/tcp/syslog— listens for events pushed from other sources.
Modules are pre-built configurations for common services (nginx, apache, system, mysql, postgresql, kafka). They include the input config, ingest pipeline definitions, dashboards for Kibana, and ECS-compliant field mappings. Enabling a module is a single command.
Output is either Logstash (when you need filtering/enrichment beyond ingest pipelines) or Elasticsearch directly (when ingest pipelines suffice). For mixed environments, Logstash is the more flexible choice.
The procedure
1. Install via the vendor APT repo:
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | \
sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg
echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | \
sudo tee /etc/apt/sources.list.d/elastic-8.x.list
sudo apt update
sudo apt install -y filebeat
2. Configure /etc/filebeat/filebeat.yml for application logs:
filebeat.inputs:
- type: filestream
id: app-logs
enabled: true
paths:
- /var/log/app/*.log
parsers:
- multiline:
type: pattern
pattern: '^\d{4}-\d{2}-\d{2}'
negate: true
match: after
fields:
service: app
env: prod
fields_under_root: true
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: true
reload.period: 30s
queue.mem:
events: 4096
flush.min_events: 2048
flush.timeout: 1s
output.logstash:
hosts: ["logstash1:5044", "logstash2:5044"]
loadbalance: true
worker: 2
bulk_max_size: 2048
compression_level: 3
logging.level: info
logging.to_files: true
logging.files:
path: /var/log/filebeat
name: filebeat
rotateeverybytes: 10485760
keepfiles: 7
3. Enable modules:
sudo filebeat modules enable nginx system mysql
sudo filebeat modules list | grep Enabled
Then edit /etc/filebeat/modules.d/nginx.yml to point at the correct paths:
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log*"]
error:
enabled: true
var.paths: ["/var/log/nginx/error.log*"]
4. Initial setup — load index templates and Kibana dashboards (run once per cluster):
sudo filebeat setup --index-management \
-E output.logstash.enabled=false \
-E output.elasticsearch.hosts="https://es:9200" \
-E output.elasticsearch.username=elastic \
-E output.elasticsearch.password="$PW"
sudo filebeat setup --dashboards \
-E output.elasticsearch.hosts="https://es:9200" \
-E setup.kibana.host="http://kibana:5601" \
-E output.elasticsearch.username=elastic \
-E output.elasticsearch.password="$PW"
5. Start the service:
sudo systemctl enable --now filebeat
sudo filebeat test output
6. Test with a known event:
logger -t app-test "filebeat smoke check $(date)"
sleep 5
curl -sk -u elastic:"$PW" 'https://es:9200/filebeat-*/_search?q=message:smoke&size=1&pretty'
Common pitfalls
- Forgetting
filestreaminput id is mandatory — without it, Filebeat refuses to start. Use a stable id per input; changing it breaks position tracking. - Inode reuse on log rotation —
copytruncaterotation can fool the registry. Userename-based rotation (logrotate default) andclean_inactive: 72hto age out old state. - Module path defaults — enabling a module doesn’t auto-detect log paths on non-standard installs. Always set
var.pathsexplicitly. - No retry caps with Elasticsearch output — connection failures retry forever by default. Set
backoff.max: 60sto bound the retry window. output.elasticsearchandoutput.logstashare mutually exclusive — Filebeat refuses both. Pick one per host.- Filebeat user can’t read
/var/log— many distros restrict log group membership. Addfilebeatto theadmgroup:usermod -aG adm filebeat.
In the engagements we run, Filebeat is the workhorse of log ingestion — one shipper per host, modules enabled per service, and the output funneled through a Logstash layer where business-specific parsing happens. Once the ELK pipeline is tuned, Filebeat almost manages itself; the operational work is keeping the modules and templates aligned with the version of the stack. See /en/services/managed-operations/ for how we operate the full log pipeline.