Setup ELK stack on Ubuntu 16.04

ELK Stack
ELK Stack

ELK is a full featured data analytics stack, consists of Elasticsearch, Logstash, and Kibana; help you to store and manage the logs centrally and offers an ability to analyze the issues by correlating the events on a particular time.

This guide helps you to install ELK stack on Ubuntu 16.04


Logstash – It does the processing (Collect, enrich and send it to Elasticsearch) of incoming logs sent by beats (forwarder).

Elasticsearch – It stores incoming logs from Logstash and provides an ability to search the logs/data in a real time

Kibana – Provides visualization of logs.

Beats – Installed on client machines, sends logs to Logstash through beats protocol.


Since Elasticsearch is based on Java, make sure you have either openJDK or Oracle JDK is installed on your machine.

Here, I choose to install Oracle JDK.

$ java -version

java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

Install wget.

$ sudo apt-get install wget

Install Elasticsearch:

Elasticsearch is an open-source search server, offers a real-time distributed search and analytics with the RESTful web interface. Elasticsearch stores all the data’s sent by the logstash and displays through the kibana on users request.

This topic covers configuration settings that are required for ELK only; you can also take at  Install Elasticsearch on Ubuntu 14.10 / Linux Mint 17.1 for more instruction.

Setup the Elasticsearch repository and install it.

$ wget -qO - | sudo apt-key add -
$ echo "deb stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch.list

Install Elasticsearch.

$ sudo apt-get update
$ sudo apt-get install -y elasticsearch

Configure Elasticsearch to start during system startup.

$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch.service && sudo systemctl start elasticsearch.service

Elastisearch should be now listening on 9200 for processing HTTP request; we can use CURL to get the response.

# curl -X GET http://localhost:9200
  "name" : "Allison Blaire",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.3.4",
    "build_hash" : "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f",
    "build_timestamp" : "2016-06-30T11:24:31Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  "tagline" : "You Know, for Search"

Install Logstash:

Logstash is an open source tool, it collects the logs, parse and store them on Elasticsearch for searching. Over 160+ plugins are available for Logstash, which provides the capability of processing different type of events with no extra work.

Let’s add the Logstash repository and begin the installation.

$ echo "deb stable main" | sudo tee -a /etc/apt/sources.list

$ sudo apt-get update && sudo apt-get install logstash

Create SSL certificate:

Forwarder (filebeat) which will be installed on client servers uses SSL certificate to validate the identity of Logstash server for secure communication.

Create SSL certificate either with the hostname or IP SAN.

Option 1: (Hostname FQDN)

If you use the hostname in the beats (forwarder) configuration, make sure you have A record for logstash server; ensure that client machine can resolve the hostname of the logstash server.

If you do not have a nameserver in your environment; make sure you add the host entry for logstash server in client machines as well as in the logstash server.

$ sudo nano /etc/hosts server.itzgeek.local

Go to the OpenSSL directory.

# cd /etc/ssl/

Now, create the SSL certificate. Replace “green” one in with the hostname of your real logstash server.

# openssl req -x509 -nodes -newkey rsa:2048 -days 365 -keyout logstash-forwarder.key -out logstash-forwarder.crt -subj /CN=server.itzgeek.local

Option 2: (IP Address)

If you are planning to use IP address instead of hostname, please follow the steps to create a SSL certificate for IP SAN.

As a pre-requisite, we would need to add an IP address of logstash server to SubjectAltName in the OpenSSL config file.

# vi /etc/ssl/openssl.cnf

Look for “[ v3_ca ]” section and replace “green” one with the IP of your logstash server.

subjectAltName = IP:

Goto OpenSSL directory.

# cd /etc/ssl/

Now,  create a SSL certificate by running following command.

# openssl req -x509 -days 365 -batch -nodes -newkey rsa:2048 -keyout logstash-forwarder.key -out logstash-forwarder.crt

This logstash-forwarder.crt should be copied to all client servers those who send logs to logstash server.

Configure Logstash:

Logstash configuration can be found in /etc/logstash/conf.d/.  If the files don’t exist, create a new one. logstash configuration file consists of three sections input, filter, and the output; all three sections can be found either in a single file or each section will have separate files end with .conf.

I recommend you to use a single file to placing input, filter and output sections.

# vi /etc/logstash/conf.d/logstash.conf

In the first section, we will put an entry for input configuration. The following configuration sets Logstash to listen on port 5044 for incoming logs from the beats (forwarder) that sit on client machines. Also, add the SSL certificate details in the input section for secure communication.

input {
 beats {
   port => 5044
   ssl => true
   ssl_certificate => "/etc/ssl/logstash-forwarder.crt"
   ssl_key => "/etc/ssl/logstash-forwarder.key"
   congestion_threshold => "40"

In the filter section.  We will use Grok to parse the logs ahead of sending it to Elasticsearch. The following grok filter will look for the “syslog” labeled logs and tries to parse them to make a structured index.

filter {
if [type] == "syslog" {
    grok {
      match => { "message" => "%{SYSLOGLINE}" }

    date {
match => [ "timestamp", "MMM  d HH:mm:ss", "MMM dd HH:mm:ss" ]


Ffor more filter patterns, take a look at grokdebugger page.

In the output section, we will define the location where the logs to get stored; obviously, it should be Elasticsearch.

output {
 elasticsearch {
  hosts => localhost
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
stdout {
    codec => rubydebug

Now start and enable the logstash.

$ sudo systemctl start logstash
$ sudo systemctl enable logstash

You can troubleshoot any issues by looking at below log.

$ sudo cat /var/log/logstash/logstash.log

Next, we will configure beats to ship the logs to logstash server.

Install Filebeat.

There are four beats clients available.

  1. Packetbeat – Analyze network packet data.
  2. Filebeat – Real-time insight into log data.
  3. Topbeat – Get insights from infrastructure data.
  4. Metricbeat – Ship metrics to Elasticsearch.

To analyze the system logs, we will be using filebeat here. You can download filebeat from the official website or you can use the following command to install it.

$ echo "deb stable main" |  sudo tee -a /etc/apt/sources.list.d/beats.list

$ sudo apt-get update && sudo apt-get install filebeat

Filebeat (beats) uses SSL certificate for validating logstash server identity, so copy the logstash-forwarder.crt from the logstash server to the client.

$ scp -pr [email protected]:/etc/ssl/logstash-forwarder.crt /etc/ssl

Configure Filebeat:

Now, it’s the time to connect filebeat with Logstash; follow up the below steps to get filebeat configured with ELK stack.

Filebeat configuration file is in YAML format, which means indentation is very important. Make sure you use the same number of spaces used in the guide.

Open up the filebeat configuration file.

$ sudo vi /etc/filebeat/filebeat.yml

On top, you would see the prospectors section; specifies which log files should be sent to logstash and how they should be handled. Each prospector starts with character.

For testing purpose, we will configure filebeat to send /var/log/syslog to Logstash server. To do that, modify the existing prospector under paths section. Comment out the – /var/log/*.log to avoid sending all .log file present in that directory to Logstash.

.  .  .


        - /var/log/syslog
        # - /var/log/*.log

.  .  .

Find the below line; uncomment it and set the value as “syslog. It defines the field value of _type in the Elasticsearch output, which means the above logs in this prospectors are of type syslog.

.  .  .

      document_type: syslog

.  .  .

In the “output:” section, comment out the elasticsearch: section as we are not going to store logs directly to Elasticsearch.

Now, find the line “logstash:” and modify the entries like below. This section defines filebeat to send logs to logstash server “server.itzgeek.local” on port “5044” and mention the path where the copied SSL certificate is placed

Note: Replace “server.itzgeek.local” with IP address in case if you are using IP SAN.

.   .   .



    hosts: ["server.itzgeek.local:5044"]


      certificate_authorities: ["/etc/ssl/logstash-forwarder.crt"]

.   .   .

Restart the service.

$ sudo systemctl restart filebeat

Beats logs are typically found syslog file.

$ sudo cat /var/log/syslog

Configure Kibana 4:

Kibana provides visualization of logs stored on the elasticsearch, download it from the official website or use the following command to setup repository.

$ wget -qO - | sudo apt-key add -
$ echo "deb stable main" | sudo tee -a /etc/apt/sources.list

Install the Kibana using the following command.

$ sudo apt-get update && sudo apt-get install kibana

Start and enable kibana on system startup.

$ sudo systemctl start kibana

$ sudo systemctl enable kibana

Access the Kibana using the following URL.

http://your-ip-address:5601/ or http://your-serve-name

On your first login, you have to map the filebeat index.

Type the following in the Index name or pattern box.


Select[email protected] and then click on create.

Setupa ELK stack on Ubuntu 16.04 - Mapping Index
Setupa ELK stack on Ubuntu 16.04 – Mapping Index

Now, it will redirect you to kibana main page. Here, you can do the search queries and view the incoming logs.

Setup ELK stack on Ubuntu 16.04 - Kibana Discover Page
Setup ELK stack on Ubuntu 16.04 – Kibana Discover Page

That’s All; you have ELK stack running on Ubuntu 16.04


Share This Post

  • ww

    I need some help in configuring this stack to monitor or collect logs from a loadbalancer