Setting Up Elasticsearch and Kibana Single-Node Cluster with Docker
Setting up Elasticsearch and Kibana on a single-node cluster can be a straightforward process with Docker. In this guide, we’ll walk through the steps to get your Elasticsearch and Kibana instances up and running smoothly.
Hardware Prerequisites
According to the Elastic Cloud Enterprise documentation, here are the hardware requirements for running Elasticsearch and Kibana
- CPU: A minimum of 2 CPU cores is recommended, but the actual requirement depends on your workload. More CPU cores may be required for intensive tasks or larger datasets.
- RAM: Elastic recommends a minimum of 8GB of RAM for Elasticsearch, but 16GB or more is recommended for production use, especially when running both Elasticsearch and Kibana on the same machine.
- Storage: SSD storage is recommended for better performance, especially for production use. The amount of storage required depends on your data volume and retention policies.
For more detailed hardware requirements and recommendations, refer to the Elastic Cloud Enterprise documentation.
Software Prerequisites
Before getting started, make sure you have Docker installed on your system. You can download and install Docker from the official website.
Setting Up Instructions
In this guide, I will perform these operations with the following specifications
- OS: Ubuntu 22.04
- RAM: 4GB
- Storage: 30GB SSD
1. Adjust Kernel Settings
The vm.max_map_count
kernel setting must be set to at least 262144
How you set vm.max_map_count
depends on your platform. For more information
I’m using the Linux operating system, so I will set vm.max_map_count
using as follows
Open the ‘/etc/sysctl.conf’ file in a text editor with root privileges. You can use the following command
sudo nano /etc/sysctl.conf
Navigate to the end of the file or search for the line containing vm.max_map_count
, If the line exists, modify it to set the desired value
vm.max_map_count=262144
If the line doesn’t exist, add it at the end of the file
# Set vm.max_map_count to increase memory map areas
vm.max_map_count=262144
Save the file and exit the text editor. Apply the changes by running the following command
sudo sysctl -p
This command reloads the sysctl settings from the configuration file. Now, the value of vm.max_map_count
should be updated to 262144.
2. Create Docker Network
Create a Docker network to facilitate communication between Elasticsearch and Kibana
docker network create elastic
3. Pull Elasticsearch Image
Pull the Elasticsearch Docker image from the official repository
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.12.1
4. Start Elasticsearch Container
Start an Elasticsearch container with sets up the Elasticsearch container with a memory limit of 1GB and exposes port 9200
.
docker run --name elasticsearch --net elastic -p 9200:9200 -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.12.1
The command prints the elastic
user password and an enrollment token for Kibana. Copy the generated elastic
password and enrollment token.
Note: The enrollment token is valid for the next 30 minutes when you generate it.
Now, press Ctrl + D to stop the Elastic Container. Then, start the container using the following command
docker start elasticsearch
5. Access Elasticsearch Dashboard
When Elasticsearch starts, to access it, open a web browser and navigate to https://localhost:9200 or https://<serveripaddress>:9200
Now, log in to Elasticsearch as the elastic
user with the password that was generated when you started Elasticsearch.
6. Pull Kibana Image
Pull the Kibana Docker image
docker pull docker.elastic.co/kibana/kibana:8.12.1
7. Start Kibana Container
Start an Elasticsearch container, mapping port 5601 to access the Kibana dashboard
docker run --name kibana --net elastic -p 5601:5601 -d docker.elastic.co/kibana/kibana:8.12.1
8. Obtain Verification Code
First, you’ll need to access the Kibana container using the docker exec
command
docker exec -it kibana /bin/bash
Once you’re inside the container’s shell, type the following command to obtain the verification code
bin/kibana-verification-code
Now, Copy the verification code for access the Kibana dashboard.
9. Access Kibana Dashboard
When Kibana starts, to access it, open a web browser and navigate to localhost:5601 or <serveripaddress>:5601
In your browser, enter the enrollment token that was generated when you started Elasticsearch.
After entering the token, click on the ‘Configure Elastic’ button and enter the verification code obtained from the Kibana container.
Now, log in to Kibana as the elastic
user with the password that was generated when you started Elasticsearch.
Conclusion
You’ve successfully set up Elasticsearch and Kibana on a single-node cluster using Docker.
Remember, after starting Elasticsearch for the first time, you’ll receive a generated password for the elastic
user. Use this password to log in to Elasticsearch and Kibana for further exploration.
Ensure to safeguard this password and follow best practices for securing your Elasticsearch and Kibana instances.
Reference https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html