Magento 2 / Server Setup

How to install ElasticSearch for Magento 2 on CentOS/RHEL

by , , revisited on


We have by far the largest RPM repository with dynamic stable NGINX modules and VMODs for Varnish 4.1 and 6.0 LTS. If you want to install NGINX, Varnish, and lots of useful modules for them, this is your one-stop repository to get all performance-related software.
You have to maintain an active subscription in order to be able to use the repository!

ElasticSearch and Magento 2.

ElasticSearch in Magento 2 is not only about search, as the name implies.
It actually speeds up the display of things throughout Magento, e.g. anywhere you browse the catalog, like category pages.
So, for a supporting Magento version, and, if you have adequate RAM available, installing and using ElasticSearch for Magento 2, is a must.

In this short tutorial, I review simple steps on how to set up ElasticSearch in a single-server scenario, on CentOS/RHEL 7 and CentOS/RHEL 8.

Installing ElasticSearch package

The latest Magento, at the time of this writing, supports only ElasticSearch 7.x series, so this is what we are going to install:

First, create repo configuration at /etc/yum.repos.d/elasticsearch.repo:

[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md

Magento 2 docs recommend specifically 7.6.x as being compatible. To install it, run:

sudo yum install --enablerepo=elasticsearch elasticsearch-7.6.*

Alternatively, if you feel lucky, you can try the most recent 7.x:

sudo yum install --enablerepo=elasticsearch elasticsearch

Enable ElasticSearch service by simply running:

sudo systemctl enable --now elasticsearch

Verify it’s running:

curl -XGET 'localhost:9200/_cat/health?v&pretty'

Should yield:

epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1601396097 16:14:57  elasticsearch yellow          1         1      3   3    0    0        3             0                  -                 50.0%

Configure Elasticsearch within Magento

To configure Magento to use Elasticsearch:

  • Log in to the Magento Admin as an administrator.
  • Click Stores > Settings > Configuration > Catalog > Catalog > Catalog Search.
  • From the Search Engine list, select your Elasticsearch version.

Now, reindex everything:

bin/magento indexer:reindex

Tips

If you want to reset ElasticSearch indexes, here’s a handy command:

curl -X DELETE 'http://localhost:9200/_all'

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: