
Elasticsearch is a distributed search and analytics engine built on Apache Lucene. It provides near real-time search capabilities for structured and unstructured data, making it ideal for log aggregation, full-text search, and business analytics. Elasticsearch scales horizontally across multiple nodes and supports complex queries through its RESTful API.
In this article, you will deploy Elasticsearch using Docker Compose, configure persistent storage for indexed data, and set up Traefik as a reverse proxy to securely access your Elasticsearch instance.
Before you begin, you need to:
sudo privileges.elasticsearch.example.com).In this section, you prepare the required directory structure for Elasticsearch and define environment variables in a .env file.
Create the directory structure for Elasticsearch.
These directories serve different purposes:
Navigate into the elasticsearch-logging directory.
Set proper ownership for the Elasticsearch data directory. Elasticsearch runs as the elasticsearch user (UID 1000) inside the container.
You can verify this UID by running docker run --rm elasticsearch:8.17.0 id.
Create a .env file.
Add the following variables:
Replace:
elasticsearch.example.com with your domain.admin@example.com with your email.Save and close the file.
Create an Elasticsearch configuration file.
Add the following content.
Save and close the file.
The configuration includes:
In this section, you create and deploy the Docker Compose stack that runs Elasticsearch behind Traefik. Docker Compose manages both containers, applies the environment variables from your .env file, and automatically configures HTTPS routing through Traefik.
Create a new Docker Compose manifest.
Add the following content.
Save and close the file.
This manifest specifies:
./elasticsearch-config, ./elasticsearch-data) mount into containers to persist configuration and search indexes.letsencrypt named volume stores certificate data permanently./var/run/docker.sock grants Traefik read-only access for automatic service discovery.Create and start the services.
Verify that the services are running.
Output:
Both containers are running. Elasticsearch processes search requests while Traefik handles incoming connections on ports 80 and 443.
View the logs of the services.
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
This section demonstrates verification of your Elasticsearch installation through cluster health checks and test index creation to validate search and storage functionality.
Access the Elasticsearch API in your browser.
You should see a JSON response with cluster information including the version number and cluster UUID.
Check cluster health using the command line.
Output:
A green status indicates the cluster is healthy and operational.
Create a test index to verify data storage.
Output:
Index a sample document.
Search for the document.
The output displays your indexed document, confirming that Elasticsearch can store and retrieve data successfully.
You have successfully deployed Elasticsearch for log management with HTTPS encryption. This Docker Compose implementation combines the search engine with an automatic SSL reverse proxy, while volume mounts preserve indexed data through container updates and restarts. Let's Encrypt integration maintains valid certificates automatically as Traefik routes incoming requests securely. Your Elasticsearch instance now stands ready to ingest application logs, perform full-text searches across massive datasets, and deliver real-time analytics through its RESTful API.
0 Comments
Be the first to comment and share your perspective with the community.