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. You will need root access to follow this guide.

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
James Lee
James Lee

James Lee, a seasoned leader with 15+ years in the tech industry, leverages his Cloud expertise to drive innovative solutions and exceptional customer experiences. He identifies growth opportunities through keen market insights and user behavior analysis, navigating the complexities of the Cloud landscape. A skilled communicator and collaborator, James thrives on exceeding expectations and leading teams to deliver impactful products.

6 Comments

  1. Got to learn a lot from your article… Thanks a lot for sharing such useful information with us. Was looking for something exactly like this..

  2. Yes it should still work without any security issues provided that this is a dedicated environment (not shared hosting).

    Using “/tmp” for “ES_TMPDIR” is fine as well if you are sure that the “/tmp” directory in the server has sufficient space. Otherwise the safer option is to create a temporary directory and give it the 777 permission so it can be read and written by Elasticsearch.

  3. Sorry I couldn’t edit my last comment, running this: /usr/share/elasticsearch/bin/elasticsearch –version
    warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
    could not find java in JAVA_HOME at /usr/local/jdk/bin/java

Leave a Reply

Your email address will not be published. Required fields are marked *