Log Monitoring Using ELK Stack on Ubuntu 22.04

Introduction Log monitoring is a crucial task for maintaining the health and performance of IT systems. The ELK Stack, which consists of Elasticsearch,...


0

Introduction

Log monitoring is a crucial task for maintaining the health and performance of IT systems. The ELK Stack, which consists of Elasticsearch, Logstash, and Kibana, is a powerful suite for centralized logging and monitoring. This guide will walk you through setting up a monitoring stack on Ubuntu 22.04 using the ELK Stack. Implementing a robust monitoring stack on Ubuntu helps in real-time log analysis and visualization. We will cover the installation and configuration of each component, making it easier to monitor your infrastructure effectively. By the end of this guide, you will have a comprehensive monitoring stack on Ubuntu ready to enhance your system’s performance and security.

Prerequisites

What you need:

  • A system running Ubuntu 22.04
  • Root or sudo user access
  • Minimum of 4GB RAM and 20GB of free disk space
  • Java 11 or newer installed on the system

Before you begin, ensure your system is updated. Run the following commands:

sudo apt update
sudo apt upgrade

This will update your package list and upgrade existing packages to the latest versions.

Step 1: Install Java

Elasticsearch requires Java to be installed on your system. Install OpenJDK 11 using the following command:

sudo apt install openjdk-11-jdk

Verify the installation:

java -version

This command checks if Java is installed correctly and displays the Java version.

Step 2: Install and Configure Elasticsearch

Elasticsearch is the search and analytics engine of the ELK Stack. Begin by adding the Elasticsearch GPG key and repository:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'

Update your package list and install Elasticsearch:

sudo apt update
sudo apt install elasticsearch

Enable and start the Elasticsearch service:

sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch

With Elasticsearch running, you can now proceed to set up Logstash.

Step 3: Install and Configure Logstash

Logstash is responsible for processing logs and forwarding them to Elasticsearch. Install Logstash using the following command:

sudo apt install logstash

Create a configuration file for Logstash:

sudo nano /etc/logstash/conf.d/01-logstash.conf

Enter the following configuration to handle logs:

input {
  beats {
    port => 5044
  }
}
filter {
  # Add filters as needed
}
output {
  elasticsearch {
    hosts => ["localhost:9200"]
  }
}

Start Logstash:

sudo systemctl start logstash

Logstash is now configured to collect and process logs, forming an integral part of the monitoring stack on Ubuntu.

Step 4: Install and Configure Kibana

Kibana provides a graphical interface to visualize data stored in Elasticsearch. Install Kibana by running:

sudo apt install kibana

Edit the Kibana configuration file:

sudo nano /etc/kibana/kibana.yml

Uncomment and set the server host:

server.host: "0.0.0.0"

Enable and start the Kibana service:

sudo systemctl enable kibana
sudo systemctl start kibana

Kibana is now set up, allowing you to visualize your data.

Step 5: Install Filebeat on Client Machines

Filebeat is a lightweight shipper for forwarding and centralizing log data. Install Filebeat on your client machines:

sudo apt install filebeat

Configure Filebeat to send logs to Logstash:

sudo nano /etc/filebeat/filebeat.yml

Modify the output section:

output.logstash:
  hosts: ["your-logstash-server-ip:5044"]

Enable and start Filebeat:

sudo systemctl enable filebeat
sudo systemctl start filebeat

Filebeat is now collecting logs and sending them to Logstash.

Step 6: Configure UFW Firewall

Ensure that your firewall allows traffic on the necessary ports. Open the following ports:

sudo ufw allow 9200
sudo ufw allow 5601
sudo ufw allow 5044

Reload UFW to apply the changes:

sudo ufw enable

Configuring the firewall is crucial to securing your monitoring stack on Ubuntu.

Step 7: Test Your ELK Stack

Verify that each component of the ELK Stack is functioning correctly by connecting to Kibana and checking the data flow through the stack. This final step ensures that your monitoring stack on Ubuntu is fully operational and ready to provide insights into your IT infrastructure.


Like it? Share with your friends!

0

What's Your Reaction?

hate hate
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win
Anoop Patel