Installing Elasticsearch: Simple Steps to Follow

Step 1: Update System Packages
Before installing Elasticsearch, update the system packages to avoid any dependency issues.
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Dependencies
Elasticsearch requires Java to run, but starting from Elasticsearch 8.x, it comes bundled with a compatible Java version, so you don’t need to install it separately. However, you should install some essential tools:
sudo apt install apt-transport-https ca-certificates curl -y
Step 3: Download and Install Elasticsearch 8.10.4
- Import the Elasticsearch GPG key:
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
- Add the Elasticsearch repository:
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list
- Update the package list and install Elasticsearch 8.10.4:
sudo apt update
sudo apt install elasticsearch=8.10.4
Step 4: Enable and Start Elasticsearch Service
Enable Elasticsearch to start on boot:
sudo systemctl enable elasticsearch
Start the Elasticsearch service:
sudo systemctl start elasticsearch
Check if it is running:
sudo systemctl status elasticsearch
if everything is setup it should show status as active
Step 5: Configure Elasticsearch (Network & Port Settings)
By default, Elasticsearch binds to localhost (127.0.0.1), which means it's only accessible from the same machine. To allow external connections, modify the elasticsearch.yml file.
- Open the configuration file:
sudo vi /etc/elasticsearch/elasticsearch.yml
- Modify the following settings:
network.host: 0.0.0.0
http.port: 9200
# optional below setting, if you want to disable authentication while accessing the Elastic server
xpack.security.enabled: false
network.host
: 0.0.0.0
→ Allows access from any IP. (Use a specific IP instead if needed)http.port: 9200
→ Default Elasticsearch port.
Save and close the file.
Restart Elasticsearch for changes to take effect:
sudo systemctl restart elasticsearch
Step 6: Test Elasticsearch
To verify that Elasticsearch is running, use:
curl -X GET "http://localhost:9200/"
If you're accessing from another machine, replace localhost
with the server’s IP:
curl -X GET "http://<your-server-ip>:9200/"
If Elasticsearch is running correctly, you should see a JSON response with details about the cluster.
{
"name" : "machine-name",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "vPo6-DvSTO6ag0d3dYChJQ",
"version" : {
"number" : "8.10.4",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "b4a62ac808e886ff032700c391f45f1408b2538c",
"build_date" : "2023-10-11T22:04:35.506990650Z",
"build_snapshot" : false,
"lucene_version" : "9.7.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
Step 7: Adjust Firewall (If Needed)
If you have UFW (Uncomplicated Firewall) enabled, allow Elasticsearch connections:
sudo ufw allow 9200/tcp
sudo ufw reload
Step 8: Secure Elasticsearch (Optional but Recommended)
Elasticsearch 8.x enables security by default (unlike previous versions). On first startup, Elasticsearch generates a temporary password for the elastic
superuser.
To view the generated password:
sudo cat /var/log/elasticsearch/elasticsearch.log | grep "generated password"
You can also manually reset the password:
sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
This will allow you to authenticate when connecting from Kibana or other clients.
Install plugins (Optional)
analysis-icu-8.10.4
wget https://artifacts.elastic.co/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-8.10.4.zip -P /usr/share/elasticsearch/
Then, install:
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///usr/share/elasticsearch/analysis-icu-8.10.4.zip
analysis-nori-8.10.4
wget https://artifacts.elastic.co/downloads/elasticsearch-plugins/analysis-nori/analysis-nori-8.10.4.zip -P /usr/share/elasticsearch/
Then, install:
sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install file:///usr/share/elasticsearch/analysis-nori-8.10.4.zip
Subscribe to my newsletter
Read articles from Arshad Lari directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
