Oct 28, 2023 5 min read

How to Install Elasticsearch on CentOS 8

Install Elasticsearch on CentOS 8 with our step-by-step tutorial. Elasticsearch is a scalable search engine for real-time search.

Install Elasticsearch on CentOS 8
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Elasticsearch on CentOS 8, let's briefly understand – What is Elasticsearch?

Elasticsearch is a highly scalable and distributed search engine used for real-time, fast, and powerful search capabilities. It helps businesses analyze and search through vast amounts of data quickly. It's designed to handle structured and unstructured data, making it ideal for various applications, including e-commerce, logging, and data analytics.

In this tutorial, we'll show you how to set up Elasticsearch on CentOS 8. We will also address a few FAQs on how to install Elasticsearch on CentOS 8.

Advantages of Elasticsearch

  1. Fast and Accurate Search: Elasticsearch delivers near-instantaneous search results, enabling users to retrieve information quickly.
  2. Scalability: Elasticsearch scales effortlessly, allowing businesses to handle increasing amounts of data without compromising performance.
  3. Distributed Architecture: Its distributed nature ensures high availability and fault tolerance, preventing data loss and minimizing downtime.
  4. Data Flexibility: Elasticsearch can handle both structured and unstructured data, making it versatile for various applications and data types.
  5. Real-time Analytics: With real-time search capabilities, Elasticsearch empowers businesses to gain immediate insights from their data, facilitating faster decision-making.

Installing Elasticsearch

Installing the rpm package from the official Elasticsearch repository is the suggested method for installing Elasticsearch on CentOS 8.

The most recent Elasticsearch version, which is 6.7 as of this writing, requires Java 8 or a later version.

Type the following command on your CentOS system to install OpenJDK 8:

sudo yum install java-1.8.0-openjdk-devel

Verify the Java version to confirm the installation:

java -version

You will get an output like below:

Output

openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)

The next step is to add the Elasticsearch repository after Java has been installed.

Utilize the following command to import the repository's GPG key:

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

Create the following repo file in your text editor:

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

Copy and paste the following text into the file:

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

After saving the file, exit the text editor.

ℹ️
Change 6.x in the command above to the version you require if you want to install an earlier release of Elasticsearch.

To install the Elasticsearch package, use the following command:

sudo yum install elasticsearch

When the installation is finished, start and enable the service by running:

sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service

You can confirm that Elasticsearch is operational by using the curl command to send an HTTP request to localhost's port 9200:

curl -X GET "localhost:9200/"

The output will look similar to the following:

Output
{
  "name" : "fLVNqN_",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "6zKcQppYREaRH0tyfJ9j7Q",
  "version" : {
    "number" : "6.7.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "8453f77",
    "build_date" : "2019-03-21T15:32:29.844721Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

Starting the service could take 5–10 seconds. Observe curl: (7) Failed to connect to localhost port 9200: Connection refused; try again in a few seconds.

Use the following command to view the messages that the Elasticsearch service has logged:

sudo journalctl -u elasticsearch

At this point, you have Elasticsearch installed on your CentOS server.

Setting up Elasticsearch

Elasticsearch configuration files are found at /etc/elasticsearch, and data is kept in the /var/lib/elasticsearch directory.

Elasticsearch is set up by default to only listen on localhost. You don't need to modify the default configuration file if you are configuring a single node cluster and the client connecting to the database is also operating on the same server.

Remote entry

Anyone with access to the HTTP API can use Elasticsearch because it does not use authentication. You must set up your firewall to permit only trusted clients to access Elasticsearch port 9200 if you wish to enable remote access to your Elasticsearch server.

As of CentOS 7, FirewallD has taken iptables' place as the standard firewall administration program.

Run the following command to permit assessment from the distant trusted IP address on port 9200:

sudo firewall-cmd --new-zone=elasticsearch --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --zone=elasticsearch --add-source=192.168.121.80/32 --permanent
sudo firewall-cmd --zone=elasticsearch --add-port=9200/tcp --permanent
sudo firewall-cmd --reload
ℹ️
Keep in mind to replace 192.168.121.80 with your remote IP Address.

Later, if you want to allow access from another IP Address use:

sudo firewall-cmd --zone=elasticsearch --add-source=<IP_ADDRESS> --permanent
sudo firewall-cmd --reload

Once the firewall is configured, the next step is to edit the Elasticsearch configuration and allow Elasticsearch to listen for external connections.

To do so, open the elasticsearch.yml configuration file:

sudo nano /etc/elasticsearch/elasticsearch.yml

Search for the line that contains network.host, uncomment it, and change the value to 0.0.0.0:

network.host: 0.0.0.0

If your computer has numerous network interfaces, you can specify the interface IP address to have Elasticsearch solely listen to that interface.

For the modifications to take effect, restart the Elasticsearch service:

sudo systemctl restart elasticsearch

That’s it. You can now connect to the Elasticsearch server from your remote location.

FAQs to Install Elasticsearch on CentOS 8

What are the system requirements for installing Elasticsearch on CentOS 8?

Elasticsearch requires Java 8 or higher and a minimum of 2 GB RAM. CentOS 8 with a 64-bit architecture is recommended.

How can I install Java on CentOS 8 for Elasticsearch?

Run the command sudo yum install java-1.8.0-openjdk to install Java 8 on CentOS 8.

How can I install Elasticsearch from the downloaded package?

Extract the downloaded package and navigate to the extracted directory. Run the command sudo rpm -i elasticsearch-{version}.rpm to install Elasticsearch.

How can I start Elasticsearch service on CentOS 8?

Run the command sudo systemctl start elasticsearch to start the Elasticsearch service.

How can I check the status of the Elasticsearch service?

Use the command sudo systemctl status elasticsearch to check the current status of the Elasticsearch service.

How do I access the Elasticsearch API on CentOS 8?

Elasticsearch API can be accessed through HTTP. Use tools like cURL or a web browser to interact with the API on the specified port (9200 by default).

How can I secure Elasticsearch on CentOS 8?

Elasticsearch provides various security features. You can enable authentication, encrypt communications, and configure access control using X-Pack or other security plugins. Refer to the Elasticsearch documentation for detailed instructions.

Conclusion

Elasticsearch is now operational on your CentOS 8 computer. You can now learn how to use Elasticsearch by going to the official Elasticsearch Documentation page.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.