Step-by-Step Guide
- Update the Package Index
Open a terminal and update the package index to ensure you have the latest information about available packages:
sudo apt update
- Install Java
Elasticsearch requires Java to run. Install OpenJDK, which is a free and open-source implementation of the Java Platform:
sudo apt install openjdk-11-jdk
Verify the Java installation:
java -version
- Download and Install the Elasticsearch Public Signing Key
Add the Elasticsearch public GPG key to your system:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
- Add the Elasticsearch Repository
Add the Elasticsearch repository to your sources list:
sudo sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
- Update the Package Index Again
Update the package index to include the Elasticsearch repository:
sudo apt update
- Install Elasticsearch
Install Elasticsearch using theapt
package manager:
sudo apt install elasticsearch
- Configure Elasticsearch
Open the Elasticsearch configuration file for editing:
sudo nano /etc/elasticsearch/elasticsearch.yml
Set the network.host
to localhost
to restrict external access:
network.host: localhost
Save and close the file.
- Start and Enable Elasticsearch
Start the Elasticsearch service:
sudo systemctl start elasticsearch
Enable Elasticsearch to start on boot:
sudo systemctl enable elasticsearch
- Verify Elasticsearch Installation
Check the Elasticsearch service status to ensure it is running:
sudo systemctl status elasticsearch
If Elasticsearch is running, you should see an active (running) status.
- Test Elasticsearch Installation
Test the Elasticsearch installation by sending an HTTP request to the Elasticsearch server:curl -X GET "localhost:9200/"
You should see a JSON response with information about your Elasticsearch cluster. - Install Elasticsearch Plugins (Optional)
Elasticsearch supports various plugins. To install a plugin, use theelasticsearch-plugin
command. For example, to install the analysis-icu plugin:sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu
Restart Elasticsearch to apply the changes:sudo systemctl restart elasticsearch
- Configure Elasticsearch Memory Settings (Optional)
By default, Elasticsearch allocates 1GB of heap memory. To adjust the heap size, open thejvm.options
file:bash sudo nano /etc/elasticsearch/jvm.options
Modify the-Xms
and-Xmx
settings to allocate the desired amount of memory (e.g., 2GB):conf -Xms2g -Xmx2g
Save and close the file. Restart Elasticsearch to apply the changes:bash sudo systemctl restart elasticsearch