Prerequisites:
System: Linux (Ubuntu 22/24 recommended)
Tools: Docker installed (apt update && apt install docker.io -y)
Step 1: Create a Docker Network
Run the command:
docker network create elastic
Step 2: Setup Data Persistence
Create and configure a local directory for data:
mkdir -p ~/elasticsearch/data chmod 776 ~/elasticsearch/data -R
Step 3: Install Elasticsearch
Pull the latest Elasticsearch image:
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.15.4
Run Elasticsearch with data persistence:
docker run -d --name es01 --net elastic -p 9200:9200 -m 2GB -v ~/elasticsearch/data:/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch:8.15.4
Step 4: Configure Elasticsearch
Wait ~5 minutes for the container to stabilize, then reset the password:
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
Obtain the enrollment token for Kibana:
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
Enrollment Token: eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTcyLjE5LjAuMjo5MjAwIl0sImZnciI6IjhiYzJhZmQ4ODhmNjg3NjE1YTA5NDQ1NjgzMzcwY2RiYzkxZGU0ZTEwMzQ4YmQyZWVlMTFlOTQ1ODAwOGZkZDQiLCJrZXkiOiJocGlaVXBNQm94LUZNa3RsaFplTTpJdW5MRTBySFFRR1BUZWwyQlprNUFnIn0=
Copy the SSL certificate locally:
docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .
Step 5: Verify Installation
Make a REST API call to Elasticsearch to ensure the Elasticsearch container is running. Check Elasticsearch status with:
curl --cacert http_ca.crt -u elastic:YOUR_PASSWORD https://localhost:9200
Step 6: Install Kibana
Pull and run Kibana:
docker pull docker.elastic.co/kibana/kibana:8.15.4 docker run -d --name kib01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.15.4
Access Kibana via http://:5601 and complete the setup using the enrollment token and generated verification code.
Enter the Enrollment token generated previously:
Get verification code:
# docker exec -it kib01 /usr/share/kibana/bin/kibana-verification-code
Enter the verification code:
During configuration:
Enter your username and password:
Log in to Kibana successfully:
Key Notes:
1. Ensure that Elasticsearch data persists even after Docker container restarts.
2. Access and test the setup from a web browser using your VPS or machine's public IP.
3. This configuration supports application-level logging by connecting developers' applications to Elasticsearch.
For more advanced setups, explore Elasticsearch security and scaling options. Happy deploying!