In this tutorial, I am going to tell you how to install Elasticsearch on Centos 7?
Elasticsearch is an open-source search engine that you can install on your store, to search and analyze the large volume of data in real-time. Many applications that rely on intensive search operations, like an eCommerce store or data applications, use Elasticsearch.
When a user opens an eCommerce store, he may browse the site via the menu. Or the user will use the search function to find a product on the site.
Now there are millions of products on an eCommerce store, and that’s why they need a powerful tool that can perform the search quickly.
Speed is important for eCommerce SEO and also for customer satisfaction. Elasticsearch empowers the site to analyze and search the data quickly.
How to install Elasticsearch on Centos 7?
There are several ways to install Elasticsearch on your server depending on the OS distribution, but the easiest way of doing so is to download the RPM from artifacts.elastic.co.
Install and Verify Java
Since elasticsearch is built on Java, we will require the OpenJDK package as a prerequisite.
You can check if Java is installed on your server by executing:
# java -version
The expected result would be:
If java is not installed, you can easily install java using the command below.
# yum -y install java
Once java is installed, go ahead.
Download and Install the Elasticsearch
Execute the below commands one by one to download, verify, and install Elasticsearch.
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-x86_64.rpm
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-x86_64.rpm.sha512
# shasum -a 512 -c elasticsearch-7.7.0-x86_64.rpm.sha512
# rpm --install elasticsearch-7.7.0-x86_64.rpm
Start and enable the elasticsearch service.
# systemctl start elasticsearch # systemctl enable elasticsearch
Verify the Elasticsearch Installation
Verify the installation with the following command:
# systemctl status elasticsearch
By default, elasticsearch listens on port 9200. You can verify that elasticsearch is running by sending a GET request to port 9200 using CURL.
# curl -XGET http://localhost:9200
The output should look like this:
Elasticsearch is now installed successfully on your server.
Optimize the Elasticsearch
Now, we need to set the HEAP_SIZE for elasticsearch to ensure the maximum performance while keeping the server resources in mind.
By default, Elasticsearch tells the JVM to use a heap with a minimum and maximum size of 1 GB.
This is defined in the file /etc/elasticsearch/jvm.options as shown below.
- Xms represents the initial size of total heap space
- Xmx represents the maximum size of total heap space
A recommended value would be no more than 50% of the total physical RAM.
Once the value is set, restart elasticsearch service using the command below and you’re good to go!
# systemctl restart elasticsearch
Configure Elasticsearch on Magento Store
To configure Elasticsearch on your Magento, follow the steps below.
Log in to your Magento Admin, navigate to Stores > Settings > Configuration.
In the left panel, expand Catalog and choose Catalog underneath and expand the Catalog Search section.
For Search Engine, deselect the Use system value checkbox and choose the version that is installed on your server.
Add the configuration details to the fields and click on Test Connection.
By following this tutorial, you can easily install Elasticsearch on Centos 7.
Solr is an alternative of Elasticsearch that you can try too. Read the difference between Solr and Elasticsearch.
I also mentioned how to configure it for the Magento store, and how to optimize the Elasticsearch for the best performance.
If you run into any error or any issue, do leave it in the comment box.