Jun 22, 2023 5 min read

How to Install Elasticsearch on CentOS 7

Install Elasticsearch on CentOS 7 with our step-by-step tutorial. It is a free and open-source full-text search and analytics platform.

Install Elasticsearch on CentOS 7
Table of Contents

Choose a different version or distribution

Introduction

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

Elasticsearch is a powerful and scalable search engine that 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.

With its distributed architecture and real-time search capabilities, Elasticsearch enables fast and accurate searches, empowering organizations to uncover valuable insights and improve decision-making. Its popularity stems from its ability to handle diverse data types, provide high availability, and scale effortlessly.

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

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 7.

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 installation by printing the Java version :

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

Open your text editor and create the following repo file:

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

Paste the following content 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

Close the text editor after saving the file.

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

Now, type the following command to install the Elasticsearch package:

sudo yum install elasticsearch

Once the installation process is complete, start and enable the service by running:

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

By using the curl command to submit an HTTP request to localhost's port 9200, you can confirm that Elasticsearch is operational:

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 the 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 on 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 7

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

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

How can I install Java on CentOS 7 for Elasticsearch?

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

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 7?

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

How can I check the status of 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 7?

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 7?

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 7 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.