Unn00n
Thumbnail for Set-Up Elastic Stack: Elasticsearch, Kibana and  Elastic Agent

Set-Up Elastic Stack: Elasticsearch, Kibana and Elastic Agent

3 min read 08 Sep 2024

Introduction

Elastic Stack, commonly known as the ELK Stack (Elasticsearch, Logstash, Kibana, and Beats), is a powerful suite of tools for searching, analyzing, and visualizing log and time-series data. The most commonly used combination today is Elasticsearch, Kibana, and Elastic Agent (which has replaced the need for Beats in many cases). These three components work together to provide scalable search, data indexing, and real-time insights. In this walkthrough, we will go through the steps involved in setting up Elasticsearch, Kibana, and Elastic Agent.

Set Up Elasticsearch

Add Server GPG key
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch |sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg
Update sources lists
echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-8.x.list
Install Elasticsearch
sudo apt update
sudo apt install elasticsearch

Configure Elasticsearch

Elasticsearch’s configuration file is in /etc/elasticsearch/elasticsearch.yml To make Elasticsearch listens on all interfaces and bound IPs uncomment network.host and replace its value with localhost

Start and Run Elasticsearch

Start the Elasticsearch service:

sudo systemctl start elasticsearch

Enable Elasticsearch to start up every time the server boots:

sudo systemctl enable elasticsearch

Check running by sending an HTTP request:

curl -X GET "localhost:9200"

Curl HTTP Request

Set Up Kibana

We have already added the Elastic package source above so we can install using apt:

sudo apt install kibana
Start and Run Kibana

Start the Kibana service:

sudo systemctl start kibana

Enable Kibana to start up every time the server boots:

sudo systemctl enable kibana

Open browser and write [localhost:5601] Elasticsearch Token Enrollment The elasticsearch-create-enrollment-token command creates enrollment tokens for Elasticsearch nodes and Kibana instances.

cd /usr/share/elasticsearch
sudo bin/elasticsearch-create-enrollment-token --scope kibana

Generate Token Enter the token then wait Verification Code based on the popup run:

cd /usr/share/kibana
sudo bin/kibana-verification-code

Generate Verification Code enter the generated verification code Configureing kibana When the set up completes, it displays the login page. Kibana Login Page to get  elastic user new password :

cd /usr/share/elasticsearch
sudo bin/elasticsearch-reset-password -u elastic
export ELASTIC_PASSWORD="your_auto_generated_password"

Reset Password for elastic user Kibana Login Page Filled Welcome Page Kibana Home Page

Set Up Elastic Agent

Set Up Fleet Server

Fleet from Kibana Fleet Page Add Fleet Server Name the fleet server and specify the host url with port 8220 Add Fleet Server Filled Install Fleet Agent we can use the same host of elasticsearch Confirmation Installed Fleet Server

Add Agents

I installed another virtual machine running ubuntu server to install elastic agent and retrieve logs from it.


On Virtual Box I created a Nat Network by “Ctrl + H” to view network settings Add Agent set both machines in the same Nat network by selecting each one and open Settings -> Network -> set Attached to Nat Network -> set Name to the created Nat network.

Add Agent Add Agent Add Agent Add Agent


From fleet page click “Add agent” Add Agent Create a Policy Create Policy Enroll in Fleet Enroll in Fleet Install Elastic Agent Install Elastic Agnet Following the installation guide on ubuntu server till the last command tweaked it to skip “certificate signed by unknown authority” error by adding --insecure:

sudo ./elastic-agent install --url=https://10.0.2.15:8220 --enrollment-token=your_generated_token --insecure

Wait Confirmation Wait Confirmation Successfully Agent Added Done Confirmation Check installed Agents Installed Agents Check Discover Tab and view logs Discover Tab Checking installed agent By following these steps, we made it and installed Elastic Stack. You can check the Set-up Fluent-Bit post to learn how to set up Fluent-Bit and send logs to Elastic Stack.