Site icon DesignLinux

How to Install Elasticsearch on CentOS 8

How to Install Elasticsearch on CentOS 8

Elasticsearch is a powerful open-source analytics and full-text search engine. It provides a distributed, multitenant-capable architecture which enables you to store, search and analyze large volumes of data faster. Elastic search is freely available under the Apache 2 license, which provides the most flexibility. In this tutorial we will show you how to install Elasticsearch on CentOS 8 Linux.

Install Elasticsearch on CentOS

Make sure you should login to your Debian system using sudo privileged user or root account. Perform the following steps:

1. Installing Java

Elasticsearch is a Java application, so the first step is to install Java.

Execute the following command to install the OpenJDK package:

sudo dnf install java-11-openjdk-devel

Verify the Java installation by checking the Java version:

java -version

It will show the output like below:

openjdk version "11.0.5" 2019-10-15 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.5+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode, sharing)

2. Installing Elasticsearch

The standard Debian 10 repositories does not includes Elasticsearch package, so we will install it from the Elasticsearch APT repository.

Import the repository’s public key using the following rpm command:

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

Create the repository file inside the /etc/yum.repos.d directory:

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

Paste the following content into the file:

[elasticsearch-7.x]
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=1
autorefresh=1
type=rpm-md

Save the file and close your text editor.

Now the repository is enabled, run below command to install the Elasticsearch package:

sudo dnf install elasticsearch

After completion of the process, start, and enable the service:

sudo systemctl enable elasticsearch.service --now

3. Configuring Elasticsearch

Configuration files for Elasticsearch are located in /var/lib/elasticsearch and Java start-up options can be configured in the /etc/elasticsearch file.

By default, Elasticsearch is configured to listen on localhost only. There is no authentication layer in Elasticsearch, so it can be accessed by anyone who can access the HTTP API. If you want to allow remote access to your Elasticsearch server, you will need to configure your firewall and allow access to the Elasticsearch port 9200 only from trusted clients.

For instance, if your system has secured with firewall and you want to allow connections only from 192.168.123.45, run the following command:

sudo firewall-cmd --new-zone=elasticsearch --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --zone=elasticsearch --add-source=192.168.123.45/32 --permanent
sudo firewall-cmd --zone=elasticsearch --add-port=9200/tcp --permanent
sudo firewall-cmd --reload

Next, you have to edit the Elasticsearch configuration and allow Elasticsearch to listen for external connections.

Open the elasticsearch.yml configuration file:

sudo nano /etc/elasticsearch/elasticsearch.yml

Find the line that contains network.host, uncomment and change the value to 0.0.0.0:

network.host: 0.0.0.0

Restart the Elasticsearch service for the changes to take effect:

sudo systemctl restart elasticsearch

It’s done. You can now connect to the Elasticsearch server from the remote location.

4. Test Elasticsearch Setup

The Elasticsearch service is ready to use. You can test it using curl command-line utility. To verify, use curl to send an HTTP request to port 9200 on localhost:

curl -X GET "http://localhost:9200/?pretty"
{
  "name" : "centos8.localdomain",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "V_mfjn2PRJqX3PlZb_VD7w",
  "version" : {
    "number" : "7.6.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "7f634e9f44834fbc12724506cc1da681b0c3b1e3",
    "build_date" : "2020-02-06T00:09:00.449973Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Conclusion

In this tutorial you learned how to install Elasticsearch on CentOS 8 system. To get more details about Elasticsearch visit the official documentation page.

If you face any problem or having a feedback, feel free to leave a comment below.

Exit mobile version