Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install the ELK Stack on Ubuntu

Install Elasticsearch, Logstash and Kibana, and put Nginx with HTTPS in front of Kibana.

VPS and Cloud Servers2 min read14 screenshots

What the ELK stack is

  • Elasticsearch stores and searches the data.
  • Logstash collects and processes logs.
  • Kibana is the web interface for charts and searches.

Together they are used for log analysis and monitoring. You need a server with at least 4 GB of RAM.

Step 1: Install Elasticsearch

Update the system:

sudo apt update
Updating the system packages

Import the GPG key:

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

Add the repository:

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
Adding the Elasticsearch repository

Install:

sudo apt update
sudo apt install elasticsearch
Installing Elasticsearch

Note the password of the elastic user that the install prints.

Start the service:

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
Starting Elasticsearch

Step 2: Install Logstash

sudo apt install logstash
Installing Logstash

Start and enable it:

sudo systemctl start logstash.service
sudo systemctl enable logstash.service
Starting Logstash

Step 3: Install Kibana

sudo apt install kibana
Installing Kibana

Start and enable it:

sudo systemctl enable kibana.service
sudo systemctl start kibana.service
Starting Kibana

Step 4: Open Kibana

Kibana listens on port 5601. By default it listens on localhost only. For a first test from your computer, open an SSH tunnel:

ssh -L 5601:localhost:5601 user@your_server_ip

Then open http://localhost:5601 in your browser.

The Kibana start page

The first time, Kibana asks for an enrollment token. Make one on the server:

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

and a verification code:

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

Then log in as elastic with the password from step 1.

Configuring Kibana

You can also install Beats (light data shippers) on other servers to send data to Elasticsearch or Logstash.

Step 5: Secure the stack with Nginx and HTTPS

To reach Kibana at a domain name, put Nginx in front of it.

Install Nginx:

sudo apt install nginx
Installing Nginx

Create a server block that proxies to http://localhost:5601. Then add HTTPS with Let's Encrypt:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com
Securing Nginx with Let's Encrypt

Step 6: Firewall

sudo ufw allow 'Nginx Full'

Open port 5601 only if you must reach Kibana directly, and only for your own IP address.

Check Elasticsearch (use your own password):

curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200/_cat/indices?v
Checking the Elasticsearch indices

Quick recap

  • Install Elasticsearch, Logstash and Kibana from the Elastic repository.
  • Use an enrollment token to connect Kibana.
  • Put Nginx with HTTPS in front, and keep ports 9200 and 5601 closed to the world.