π Installing and Configuring Filebeat ποΈ
Filebeat is a lightweight shipper for forwarding and centralizing log data. It is commonly used to send logs to Logstash for further processing before indexing them in Elasticsearch. In this guide, we will go through the installation and configuration of Filebeat to work with Logstash.
π Step 1: Install Filebeat π οΈβ
First, install Filebeat using the following command:
sudo apt install filebeat
This will install Filebeat on your system.
βοΈ Step 2: Configure Filebeatβ
Filebeat supports multiple output destinations. However, in this setup, we will use Logstash for further processing before sending logs to Elasticsearch.
1οΈβ£ Modify the Configuration Fileβ
Open the Filebeat configuration file using:
sudo nano /etc/filebeat/filebeat.yml
πΉ Disable Direct Elasticsearch Output By default, Filebeat is configured to send logs directly to Elasticsearch. Since we are using Logstash, we need to disable it by commenting out the following lines:
#output.elasticsearch:
# Array of hosts to connect to.
#hosts: ["localhost:9200"]
πΉ Enable Logstash Output Next, configure Filebeat to send logs to Logstash by uncommenting the following lines:
output.logstash:
# The Logstash hosts
hosts: ["localhost:5044"]
This ensures that Filebeat sends logs to Logstash running on port 5044.
π Can we change localhost
to some other IP?β
Yes, instead of localhost
, you can use a specific IP address (e.g., 192.168.1.100
) when:
- Logstash is running on another server in the network.
- You have a distributed logging setup, and Filebeat is collecting logs from multiple remote machines.
- The Elastic Stack components (Logstash, Elasticsearch, Kibana) are deployed across multiple nodes.
For example, if your Logstash server is running on 192.168.1.100
, modify the Filebeat configuration:
output.logstash:
hosts: ["192.168.1.100:5044"]
Similarly, for Elasticsearch:
output.elasticsearch:
hosts: ["192.168.1.100:9200"]
π§© Step 3: Enable Filebeat Modulesβ
Filebeat modules simplify log collection and parsing. We will use the system module, which collects logs from system services.
Enable the system module by running:
sudo filebeat modules enable system
Verify the enabled modules:
sudo filebeat modules list
By default, this module collects logs from syslog and authorization logs.
You can view the moduleβs configuration in:
cat /etc/filebeat/modules.d/system.yml
π¦ What type of data does Filebeat send? π‘β
Filebeat collects and forwards different types of log data, including:
- System logs (e.g.,
/var/log/syslog
,/var/log/auth.log
) - Application logs (e.g., Nginx, Apache, MySQL logs)
- Container logs (e.g., Docker, Kubernetes logs)
- Custom log files specified in the configuration
These logs contain valuable information such as timestamps, event types, error messages, user activities, and more, helping in monitoring and troubleshooting.
ποΈ Step 4: Load Filebeat Ingest Pipelinesβ
To process logs before sending them to Logstash, we need to set up ingest pipelines. Run the following command:
sudo filebeat setup --pipelines --modules system
Next, set up index management:
sudo filebeat setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
π Step 5: Load Filebeat Dashboards into Kibana πβ
Filebeat provides pre-built dashboards for Kibana to visualize log data. To load them, disable Logstash output temporarily and enable Elasticsearch output:
sudo filebeat setup -E output.logstash.enabled=false -E output.elasticsearch.hosts=['localhost:9200'] -E setup.kibana.host=localhost:5601
This step ensures that the dashboards are available in Kibana for visualizing logs.
π Step 6: Start and Enable Filebeat Serviceβ
Once the configuration is complete, start and enable Filebeat to run on system boot:
sudo systemctl start filebeat
sudo systemctl enable filebeat
Verify that Filebeat is running:
sudo systemctl status filebeat
π Step 7: Verify Data in Elasticsearchβ
To check if logs are reaching Elasticsearch, run:
curl -XGET 'http://192.168.1.100:9200/filebeat-*/_search?pretty'
If everything is configured correctly, you should see log entries in the output.
π Conclusionβ
You have successfully installed and configured Filebeat to collect logs and send them to Logstash for processing. With Elasticsearch and Kibana, you can now analyze and visualize your logs efficiently. π Happy Logging! π―