Installing Filebeat on Debian
To begin real-time monitoring with Filebeat on Debian, you first need to install the tool. The recommended method is using APT for simplicity and dependency management:
sudo apt update
.sudo apt install filebeat
..deb
package from Elastic’s official website and install it manually: wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-<version>-amd64.deb
(replace <version>
with the desired release).sudo dpkg -i filebeat-<version>-amd64.deb
(resolve dependencies with sudo apt-get install -f
if prompted).Configuring Filebeat for Real-Time Monitoring
The core of real-time monitoring lies in configuring Filebeat to watch your target logs and forward them to a backend (e.g., Elasticsearch). Key steps include:
/etc/filebeat/filebeat.yml
in a text editor (e.g., sudo nano /etc/filebeat/filebeat.yml
).filebeat.inputs
, enable the log
type and specify the paths to monitor. For example, to track all .log
files in /var/log
:filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log
You can customize this to monitor specific files (e.g., /var/log/nginx/access.log
) or directories.output.elasticsearch: hosts: ["localhost:9200"] # Replace with your Elasticsearch server’s address if remote
If using Logstash as an intermediary, replace the output section with:output.logstash: hosts: ["localhost:5044"]
multiline
codec to your input:multiline: pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}' # Matches log line timestamps (adjust as needed) negate: true match: after # Combines lines after the pattern
processors: - add_host_metadata: ~ # Automatically adds host details (hostname, IP) - add_docker_metadata: ~ # Adds Docker container info (if applicable)
Starting and Enabling Filebeat
Once configured, start the Filebeat service and configure it to launch at boot:
sudo systemctl start filebeat
.sudo systemctl enable filebeat
.sudo systemctl status filebeat
(look for “active (running)” to confirm success).Verifying Real-Time Monitoring
To ensure Filebeat is actively sending logs in real time:
journalctl
to view real-time service logs:sudo journalctl -u filebeat -f
This displays Filebeat’s runtime activity, including file discovery and data forwarding./var/log/filebeat/filebeat.log
):sudo tail -f /var/log/filebeat/filebeat.log
curl -X GET "localhost:9200/_cat/indices?v" # Lists all indices (look for "filebeat-*") curl -X GET "localhost:9200/filebeat-*/_search?q=*&pretty" # Searches recent logs
If using Kibana, create an index pattern (e.g., filebeat-*
) in the Stack Management > Index Patterns section and navigate to the Discover page to view real-time logs.Advanced Monitoring and Maintenance
For production environments, enhance real-time monitoring with these steps:
logrotate
to manage log file size and retention, ensuring Filebeat processes rotated logs correctly. Create a configuration file at /etc/logrotate.d/filebeat
:/var/log/filebeat/*.log { daily missingok rotate 7 compress notifempty create 640 root adm }
This rotates logs daily, keeps 7 compressed copies, and ensures Filebeat picks up new logs after rotation.