Elasticsearch & Kibana — Part 1

Configuring Elasticsearch & Kibana — Part 1 — image 1

Installing Elasticsearch on Ubuntu

First, let’s import elastic’s GPG key. This command fetches elastic’s GPG key and converts it into a format APT understands. The key ensures that the packages you’re about to install are authentic and secure :).

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

Configuring Elasticsearch & Kibana — Part 1 — image 2

Now, let’s add the elasticsearch APT repository. This tells APT where to fetch Elasticsearch packages from. The signed-by option links the repo to the GPG key we added for secure verification. We then update our package list with sudo apt update.

echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

sudo apt update

Configuring Elasticsearch & Kibana — Part 1 — image 3

APT now knows where to find elasticsearch and we install it with:

sudo apt-get install elasticsearch

Configuring Elasticsearch & Kibana — Part 1 — image 4

Let’s configure elasticsearch network settings, in this file, you’ll want to configure the values network.host and http.port depending on your setup. For example:

network.host: 0.0.0.0
http.port: 9200

sudo nano /etc/elasticsearch/elasticsearch.yml

Configuring Elasticsearch & Kibana — Part 1 — image 5

Enabling elasticsearch to start on boot, ensures elasticsearch runs every time your system boots (no one wants to start the service each time manually).

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch

Configuring Elasticsearch & Kibana — Part 1 — image 6

Once you start the elasticsearch service you can check that everything is running smoothly using the status command.

sudo systemctl start elasticsearch
sudo systemctl status elasticsearch

Configuring Elasticsearch & Kibana — Part 1 — image 7

It's up and running!

Configuring Elasticsearch & Kibana — Part 1 — image 8

Configuring Elasticsearch & Kibana — Part 1 — image 9

Installing Kibana on Ubuntu

Installing kibana:

sudo apt-get install kibana

Configuring Elasticsearch & Kibana — Part 1 — image 10

Now let’s configure kibana by updating some of the values below:

server.port: 5601
server.host: “0.0.0.0”
elasticsearch.hosts: [“http://localhost:9200"]

This sets kibana to be accessible on port 5601 and connects it to your elasticsearch instance.

sudo nano /etc/kibana/kibana.yml

Configuring Elasticsearch & Kibana — Part 1 — image 11

Next, let's enable kibana and ensure it starts automatically when the system boots.

sudo systemctl enable kibana
sudo systemctl start kibana
sudo systemctl status kibana

Configuring Elasticsearch & Kibana — Part 1 — image 12

To securely connect kibana to elasticsearch, generate an enrollment token (you’ll use it in the kibana web setup process):

sudo /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana

Configuring Elasticsearch & Kibana — Part 1 — image 13

Open kibana in your browser and paste in the enrollment token. Click Configure Elastic to continue.

Configuring Elasticsearch & Kibana — Part 1 — image 14

Kibana will prompt you for a verification code. Generate it with:

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

Configuring Elasticsearch & Kibana — Part 1 — image 15

Enter the code, then proceed with logging in using the username (elastic) and the password generated during elasticsearch installation.

Configuring Elasticsearch & Kibana — Part 1 — image 16

That’s it! You now have a fully running Elastic Stack with both Elasticsearch and Kibana configured.

Wow, Very Win, Such Amaze! Wow, Very Win, Such Amaze!

References:

https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html