In this tutorial, we will show you how to install ELK Stack on Debian 9. For those of you who didn’t know, ELK stack is a popular, open-source log management platform. It is used as centralized management for storing, analyzing, and viewing logs. Centralized management makes it easier to study the logs and identify issues if any for any number of servers.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of ELK Stack on a Debian 9 (Stretch) server.
Prerequisites
- A server running one of the following operating systems: Debian 9 (Stretch).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install ELK Stack on Debian 9 Stretch
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt-get
commands in the terminal:
apt-get update apt-get upgrade apt-get install apt-transport-https software-properties-common wget
Step 2. Installing Java.
Elasticsearch requires at least Java 8 in order to run, You can install the OpenJDK package that includes JRE:
apt install openjdk-8-jdk
Verify the Java version:
[root@idroot.us ~]# java -version openjdk version "1.8.0_171" OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-1~deb9u1-b11) OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
Step 3. Installing Elasticsearch on Debian 9.
First, install Elasticsearch using the apt package manager from the official Elastic repository:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list sudo apt-get update
Then, install Elasticsearch with apt using the following command:
apt-get install elasticsearch
Start the Elasticsearch service and set it to automatically start on boot:
systemctl restart elasticsearch systemctl enable elasticsearch
Now run the following command from the terminal to check if the elastic search is working properly:
curl -X GET http://localhost:9200
You should get the following output:
{ "name" : "idroot.us", "cluster_name" : "elasticsearch", "cluster_uuid" : "k27ZZFBMWe46aOtwg6_pyzEiw", "version" : { "number" : "6.2.4", "build_hash" : "2cfe0df", "build_date" : "2018-05-29T16:05:51.443Z", "build_snapshot" : false, "lucene_version" : "7.2.1" }, "tagline" : "You Know, for Search" }
Step 4. Installing Kibana on Debian 9.
First, install the latest version of Kibana using the apt package manager from the official Elastic repository:
apt-get install kibana
Once the installation is completed, open the kibana.yml file and restrict the remote access to the Kibana instance:
nano /etc/kibana/kibana.yml # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values. # The default is 'localhost', which usually means remote machines will not be able to connect. # To allow connections from remote users, set this parameter to a non-loopback address. server.host: "localhost"
Start the Kibana service and set it to start automatically on boot:
systemctl start kibana systemctl enable kibana
Step 5. Install and configure Nginx as a reverse proxy.
Next, use Nginx as a reverse proxy to access Kibana from the public IP address. To install Nginx, run:
apt-get install nginx
Create a basic authentication file with the OpenSSL command:
echo "admin:$(openssl passwd -apr1 YourPassword)" | sudo tee -a /etc/nginx/htpasswd.kibana
Then, create a virtual host configuration file for the Kibana instance:
rm -f /etc/nginx/sites-enabled/default nano /etc/nginx/sites-available/kibana
server { listen 80 default_server; server_name _; return 301 https://$server_name$request_uri; } server { listen 443 default_server ssl http2; server_name _; ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem; ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key; ssl_session_cache shared:SSL:10m; auth_basic "Restricted Access"; auth_basic_user_file /etc/nginx/htpasswd.kibana; location / { proxy_pass http://localhost:5601; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
Creating a symbolic link and testing the Nginx configuration:
ln -s /etc/nginx/sites-available/kibana /etc/nginx/sites-enabled/kibana nginx -t
Restart the Nginx service and set it to start automatically on boot:
systemctl restart nginx systemctl enable nginx
Step 6. Installing Logstash on Debian 9.
Install Logstash using the apt package manager from the official Elastic repository:
apt-get install logstash
Once the Logstash package is installed start the Logstash service and set it to start automatically on boot:
systemctl restart logstash systemctl enable logstash
Step 7. Accessing Kibana.
You can now access the Kibana interface by opening your browser and typing:
https://Your-Ip-Address
Congratulations! You have successfully installed ELK. Thanks for using this tutorial for installing ELK (Elasticsearch, Logstash, and Kibana) on Debian 9 Stretch system. For additional help or useful information, we recommend you check the official ELK Stack website.