How to install Elasticsearch 7 on CentOS 7

With the latest version of Magento, Magento 2.4 removing the MySQL search capability and forcing the use of Elasticsearch 7.x, many users may be frantically searching for the latest guide to install Elasticsearch in your server.

As most of the guides around the net are either outdated or may not work well in a CentOS 7 environment with cPanel/WHM installed, I hope this installation guide will be helpful to those of you running CentOS 7.

Firstly, create a yum repository in your server for Elasticsearch 7.x:-

nano /etc/yum.repos.d/elasticsearch.repo

Add the following content to the file:-

[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

Then, run the Elasticsearch installation:-

yum -y install --enablerepo=elasticsearch elasticsearch

Once the installation is complete, modify the file below:-

nano /etc/sysconfig/elasticsearch

Add this to any new line in the file above to reference a temporary directory:-

ES_TMPDIR=/usr/share/elasticsearch/tmp

Create the temporary directory referenced above and set the appropriate file permissions:-

mkdir /usr/share/elasticsearch/tmp
chmod 777 /usr/share/elasticsearch/tmp

Make sure Elasticsearch will be started automatically whenever the server reboots:-

/bin/systemctl daemon-reload
/bin/systemctl enable elasticsearch.service

Start Elasticsearch:-

/bin/systemctl start elasticsearch.service