
Elasticsearch is a distributed, open-source search engine built on Apache Lucene. It stores and retrieves large volumes of structured, unstructured, and vector data with high speed and scalability. It is commonly used as part of the Elastic Stack alongside Logstash and Kibana for logging, analytics, and full-text search.
In this article, you will install Elasticsearch on Ubuntu 24.04, configure it for secure local access, test its functionality, and secure it with Let's Encrypt SSL certificates and Nginx as a reverse proxy.
Before you begin, you need to:
www.example.com.Install Certbot and Nginx to prepare for securing Elasticsearch with SSL.
Update your system’s package list.
Install Certbot, Nginx, and the Nginx plugin.
Elasticsearch is not available in Ubuntu’s default package repositories. Add the official Elastic APT repository and install it as follows:
Import the Elasticsearch GPG signing key.
Add the Elasticsearch APT source list.
Update your package list again to include the new repository.
Install Elasticsearch.
Restrict Elasticsearch to listen only on localhost to prevent external access.
Open the Elasticsearch configuration file.
Find the following line (usually near the bottom) and replace or add it to restrict access to localhost:
Setting network.host to 127.0.0.1 ensures Elasticsearch is not exposed to external networks.
Save the file and exit.
Restart and enable the Elasticsearch service to apply changes and ensure it starts on boot.
Reload systemd to register service changes.
Restart the Elasticsearch service.
Enable Elasticsearch to start automatically on reboot.
Verify that the service is active and running.
Verify that Elasticsearch is working by allowing required firewall ports, resetting the default user password, and querying the API.
Allow HTTP and HTTPS ports.
Enable the firewall.
Confirm that the rules are active.
Output:
Reset the elastic user password.
The command above generates and displays a new password for the elastic user, which you will use in the next step.
Test the Elasticsearch API with the generated password.
Replace <password> with the value generated in the previous step to authenticate the request. The -k option skips SSL certificate validation.
Elasticsearch enables authentication by default since version 8.0. Resetting the elastic user password is required for API access.
The response should resemble:
This confirms that Elasticsearch is functioning and accessible via a secure API.
To enable secure remote access, use Let's Encrypt SSL certificates with an Nginx reverse proxy.
Create a new reverse proxy configuration for Nginx.
Add the following configuration and replace www.example.com accordingly.
Enable the new Elasticsearch reverse proxy.
Restart Nginx.
Request a TLS certificate using Certbot.
After completing the prompt, Certbot stores the certificates at:
/etc/letsencrypt/live/www.example.com/fullchain.pem/etc/letsencrypt/live/www.example.com/privkey.pemRemove the default Nginx site.
Open your browser and visit https://www.example.com.
You should see a login prompt:
Log in using the elastic user and password to reach the homepage.
This confirms that Elasticsearch is securely accessible over HTTPS.
In this article, you installed Elasticsearch on Ubuntu 24.04, restricted its access to localhost, reset the elastic user password, verified its API functionality, and secured remote access using Let's Encrypt SSL certificates with an Nginx reverse proxy. This setup provides a secure and production-ready Elasticsearch environment.
For advanced use cases and cluster management, refer to the official Elasticsearch documentation.
0 Comments
Be the first to comment and share your perspective with the community.