Installing Filebeat on CentOS
To begin using Filebeat for real-time data processing on CentOS, you first need to install it. The most common method is via the official Elastic YUM repository, which ensures you get the latest stable version. Here’s how:
sudo yum update -y
.sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
echo "[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md" | sudo tee -a /etc/yum.repos.d/elasticsearch.repo
sudo yum install filebeat -y
.Configuring Filebeat for Real-Time Data Collection
The core of Filebeat’s real-time functionality lies in its configuration file (/etc/filebeat/filebeat.yml
). Key settings include:
.log
files in /var/log/
:filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
localhost
with your Elasticsearch server’s IP if remote):output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{+yyyy.MM.dd}" # Creates daily indices for better manageability
filebeat.inputs
section to balance speed and resource usage:
scan_frequency
: How often Filebeat checks for new log lines (default: 10s; reduce to 5s for faster detection).close_inactive
: Time (default: 5m) after which Filebeat closes an inactive log file. Shorten this (e.g., 1m) to release resources quickly.tail_files
: Set to true
to start reading from the end of new files (avoids reprocessing old logs).Starting and Enabling Filebeat
After configuring, start the Filebeat service and enable it to launch at boot:
sudo systemctl start filebeat
sudo systemctl enable filebeat
Verify the service is running: sudo systemctl status filebeat
(look for “active (running)” in the output).
Verifying Real-Time Data Transmission
To confirm Filebeat is sending data in real time:
curl -X GET "localhost:9200/_cat/indices?v"
(replace localhost
if needed). You should see indices named filebeat-YYYY.MM.DD
(e.g., filebeat-2025.09.30
).filebeat-*
index pattern, and you’ll see real-time log entries as they’re sent by Filebeat.Optional: Enhancing Real-Time Capabilities with Processors and Modules
processors:
- add_fields:
target: log
fields:
app_name: "my_app"
filebeat.modules:
- module: apache
access:
enabled: true
var.paths: ["/var/log/httpd/access.log*"]
error:
enabled: true
var.paths: ["/var/log/httpd/error.log*"]
Then load the module: sudo filebeat modules enable apache
.Troubleshooting Tips
/var/log/filebeat/filebeat
) for errors.