This repository contains tools, scripts, and documentation for managing and using the ELK (Elasticsearch, Logstash, Kibana) stack. These tools help streamline the installation, management, and usage of the ELK stack, making it easier for users to deploy and maintain.
Here is a visual representation of the ELK stack in action:
Ensure your system meets the following requirements before installing the ELK stack:
- Operating System: Ubuntu 18.04 or later
- Java: Java 8 or later
- Storage: Minimum 20 GB of available disk space (50-100 GB recommended for production environments)
- Internet Connection: Required for downloading packages and updates
- Memory: Minimum 4 GB RAM (8 GB or more recommended for better performance)
To install the ELK stack on your machine, follow these steps:
-
Download and install the public signing key:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
-
Install the apt-transport-https package:
sudo apt-get install apt-transport-https
-
Save the repository definition to
/etc/apt/sources.list.d/elastic-7.x.list
:echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
-
Update your package lists and install Elasticsearch:
sudo apt-get update && sudo apt-get install elasticsearch
-
Start Elasticsearch and enable it to start on boot:
sudo systemctl enable elasticsearch sudo systemctl start elasticsearch
-
Install Logstash from the same repository:
sudo apt-get install logstash
-
Start Logstash and enable it to start on boot:
sudo systemctl enable logstash sudo systemctl start logstash
-
Install Kibana from the same repository:
sudo apt-get install kibana
-
Start Kibana and enable it to start on boot:
sudo systemctl enable kibana sudo systemctl start kibana
-
Check Elasticsearch:
curl -X GET "localhost:9200/"
-
Check Logstash:
sudo systemctl status logstash
-
Check Kibana:
Open your web browser and go to
http://localhost:5601
.
Following these steps will install and start the ELK stack on your machine.
After installing the ELK stack, you can start, stop, and manage services using the provided scripts in this repository. Refer to the Scripts section for details on each script's usage.
Script to start Elasticsearch, Logstash, and Kibana services:
#!/bin/bash
# Start Elasticsearch service
sudo systemctl start elasticsearch
# Start Logstash service
sudo systemctl start logstash
# Start Kibana service
sudo systemctl start kibana
echo "ELK services started successfully."
Script to stop Elasticsearch, Logstash, and Kibana services:
#!/bin/bash
# Stop Elasticsearch service
sudo systemctl stop elasticsearch
# Stop Logstash service
sudo systemctl stop logstash
# Stop Kibana service
sudo systemctl stop kibana
echo "ELK services stopped."
Script to restart Elasticsearch, Logstash, and Kibana services:
#!/bin/bash
# Restart Elasticsearch service
sudo systemctl restart elasticsearch
# Restart Logstash service
sudo systemctl restart logstash
# Restart Kibana service
sudo systemctl restart kibana
echo "ELK services restarted."
Script to check the status of Elasticsearch, Logstash, and Kibana services:
#!/bin/bash
# Check status of Elasticsearch service
sudo systemctl status elasticsearch | head -n 4
echo -e "\n"
# Check status of Logstash service
sudo systemctl status logstash | head -n 4
echo -e "\n"
# Check status of Kibana service
sudo systemctl status kibana | head -n 4
echo "Status of Elasticsearch, Logstash, and Kibana have been checked."
Script to clear logs for Elasticsearch, Logstash, and Kibana:
#!/bin/bash
# Function to clear logs in a directory
clear_logs() {
local LOG_DIR=$1
if [ -d "$LOG_DIR" ]; then
echo "Clearing logs in $LOG_DIR..."
sudo find $LOG_DIR -type f -name "*.log" -exec rm -f {} \;
echo "Logs in $LOG_DIR have been cleared."
else
echo "Directory $LOG_DIR does not exist."
fi
}
# Clear Elasticsearch logs
clear_logs "/var/log/elasticsearch"
clear_logs "/var/lib/elasticsearch"
# Clear Logstash logs
clear_logs "/var/log/logstash"
clear_logs "/var/lib/logstash"
# Clear Kibana logs
clear_logs "/var/log/kibana"
clear_logs "/var/lib/kibana"
echo "All ELK logs have been cleared."
Example Logstash pipeline configuration to parse and index Apache logs:
input {
file {
path => "/var/log/apache2/access.log"
start_position => "beginning"
}
}
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "apache-logs"
}
stdout { codec => rubydebug }
}
- Open Kibana: Go to
http://localhost:5601
in your web browser. - Create Index Pattern: Navigate to
Management > Index Patterns
and create a new index pattern forapache-logs
. - Import Dashboard: Go to
Dashboard > Create new dashboard
and start adding visualizations based on your indexed data.
For detailed documentation on installing, configuring, and using the ELK stack, refer to the following resources:
- Official Elasticsearch Documentation
- Official Logstash Documentation
- Official Kibana Documentation
- ELK Stack Setup Guide
- ELK Stack Troubleshooting
This repository is licensed under the MIT License. See the LICENSE file for more details.