How to install Elasticsearch 7.x on CentOS 7 Print

  • elasticsearch, magento, elastic, search, magento 2, rpm, yum, java, cpanel
  • 2

Elasticsearch is gaining popularity as a modern, fast and powerful search engine. It can integrate into many pre-built applications and CMS' as well as custom coded applications using its fantastic API.  Today we'll give a simple overview of how to install Elasticsearch 7.x versions onto CentOS 7. We'll assume that you've already logged into your server using console or SSH, and that you have obtained root or su access.

1. Install Java

Elasticsearch is written in Java, so we first need to install Java on the server.

yum install java

2. Import Elasticsearch GPG Key

Elasticsearch packages are signed for authenticity, so we should import their GPG key for best security.

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

3. Add the RPM repo

The easiest way to install and keep updated with Elasticsearch is to use its CentOS repository. First let's open a new file:

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

Then, paste in the repo contents:

[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, hit CTRL + X to exit the file, remembering to save changes.

4. Installing the Elasticsearch service

Now we actually install Elasticsearch from the new repo we've created.

yum install --enablerepo=elasticsearch elasticsearch

5. Fix the JVM options

By default, CentOS + Java + Elasticsearch settings do not play nice with each other. We need to update Java's temp directory to ensure it can correctly start and run Elasticsearch and properly log entries. Open this file:

nano /etc/elasticsearch/jvm.options

Now locate the line that reads:

-Djava.io.tmpdir=${ES_TMPDIR}

Then, comment out the line (or just delete it), and then replace it with:

-Djava.io.tmpdir=/var/log/elasticsearch

Then exit out of nano with CTRL + X,  remembering to save changes.

6. Enable Elasticsearch on boot and start it

Finally we want to enable Elasticsearch as a system service that automatically runs on boot:

systemctl enable elasticsearch.service

And then we want to run it for the first time:

systemctl start elasticsearch.service

7. Configure Elasticsearch

That's it, you're done for the installation! Elasticsearch is now running on your server on its default port 9200. Now it's over to you for the final configuration and customisation of your choosing.


Was this answer helpful?

« Back