28 C
Wednesday, April 14, 2021

How To Install and Configure Elasticsearch on Linux System

Must read

Elasticsearch is open-source analytics and a search engine. It is an enhanced search engine for servers and websites. Or, in normal words, Elasticsearch is a kind of database with some JSON files that can search from a large volume of data index. If you own a data server, web server, or website, you can install and configure the Elasticsearch engine on your system to find the database parameters. Elasticsearch can be installed and configured with Linux servers and systems to sort data, boost the search results, filter search parameters. Basically, you can use the Elasticsearch engine on your server to do all kinds of stuff for building a robust search engine.

How Elasticsearch Works

Elasticsearch responds with plain HTTP requests and keeps the database updated so that it never misses any query. You can run a query and analyze your data from the database through the Elasticseach engine. You can install Elasticsearch on both new and existing servers; it won’t duplicate your data on search queries.

Elasticsearch works with an Application Performance Management (APM) tool for collecting index data, metadata, and other data fields from the source database. It also allows API support for better performance.

Elasticsearch allows you to create a Pie chart and other graphical representations of your data. It’s not business intelligence but analyzes data pretty well. You can find the CPU and memory usages, detect an abnormality, and store data through Elasticsearch on a Linux system.

Install Elasticsearch on Linux

The Elasticsearch is written in Java, so you would need to have Java installed on your Linux system to install Elasticsearch on your system. It allows API integration so that you can use it on different web-applications. You can install Elasticsearch on a Linux system and configure it with an existing Apache or Nginx server. In this post, we’ll see how you can install and use Elastic search on a Linux system.

1. Install Elasticsearch On Ubuntu/Debian Linux

Installing Elasticsearch on a Debian-based Linux system is not a complicated task; It’s easy and straightforward. You need to know a few basic terminal commands and have the root privilege on your system. The following steps will guide you to install Elasticsearch on Ubuntu and other Debian Linux machines.

Step 1: Install Java For Elasticsearch

Elasticsearch requires Java to configure the web library functions on a Linux system. If your system doesn’t have Java installed, you can run the following terminal command on your shell to install Java.

sudo apt install openjdk-11-jre-headless

When the Java installation finishes, don’t forget to check the Java version to ensure it’s installed correctly.

java -version

Step 2: Add GPG Key For Elasticsearch on Debian Linux

For an effortless installation of Elasticsearch, you need to add the GPG-key (Gnu Privacy Guard) of Elasticsearch to your Linux system. Run the following cURL command on your terminal shell to add the GPG Key.

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

For Dedina distributions, Elasticsearch is available on the Linux repository. You need to add it to your system repository. You can run the following echo command to add Elasticsearch to your system’s repository.

echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

elastic search curl and echo on Ubuntu

When the echo command ends, update your system repository and check if it is added to your software. You can find your system repository under the Other Software tab in the ‘Software & Updates’ tool.

sudo apt-get update

elastci on repository

Step 3: Install Elasticsearch on Debian/Ubuntu

After adding the GPG key and updating the repository, installing Elasticsearch is now a matter of few clicks. You can now run the following aptitude command on your terminal shell with root privilege to install Elasticsearch on your Debian system.

sudo apt install elasticsearch

APT install Elasticsearch on Ubuntu

2. Install Elasticsearch on Fedora Workstation

If you’re using a Fedora Linux system, the following steps will guide you to install Elasticsearch on your machine. I’ve tested the following steps on my Fedora workstation; the steps would also be executable on other Red Hat-based systems.

Step 1: Install Java on Fedora Workstation

As I mentioned previously that installing Elasticsearch requires Java; first, we’ll install Java on our system. If you already have Java installed on your system, you can skip installing it. To ensure whether Java is installed or not, you can run a quick version check command on the terminal shell.

java -version

If you can’t see any Java version in return, you may now run the following DNF command to install it on your Fedora Linux.

sudo dnf install java-11-openjdk

install java on Fedora Linux

Step 2: Add Gnu Privacy Guard For Elasticsearch

In this step, we need to add the GPG-key for Elasticsearch to our system. You can run the following command on the terminal shell to add the GPG key.

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

Add EOF key for elasticsearch on Fedora

Now, we need to create a repository file for Elasticsearch inside the /etc/yum.repos.d directory. You can open the browse the filesystem and create a new text document script and rename it as elasticsearch.repo. If you have permission issues while making a new repository file, you can run the following chown command to access the file. Don’t forget to replace the word ‘ubuntupit‘ with your username.

sudo chown ubuntupit elasticsearch.repo

chown command for elastic search

Then you need to copy and paste the following script inside the elasticsearch.repo file and save and exit the file.

cat <<EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo
name=Elasticsearch repository for 7.x packages

configure elasticsearch on Fedora Linux

Step 3: Install Elasticsearch On Fedora

After installing Java and adding the GPG key, we’ll now install Elasticsearch on our Fedora Linux. Before installing it, you may need to run a quick DNF clean command to clean the repository metadata from your system. Then run the following YUM command on your shell with root privilege to install Elasticsearch on your system.

sudo dnf clean
sudo yum install elasticsearch

If you have any issues installing it on your system, you can run the following DNF command to avoid errors.

sudo dnf install elasticsearch-oss

DNF install Elasticsearch on Fedora Linux

When the installation finishes, you can now run the following system control commands on your terminal shell to start and enable Elasticsearch on your Linux machine.

sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch

If everything goes correctly, you can run the following system control command to check the status of Elasticsearch on your machine. In return, you would see the service name, main PID, activation status, task details, and CPU runtime.

sudo systemctl status elasticsearch

system control elasticsearch on fedora

Configure Elasticsearch on Linux

After installing Elasticsearch on a Linux machine, you may need to configure it with your server IP address to load it with your server. Here, I’m using the localhost ( address to load it. You can run the following command on your terminal shell to open the configuration script.

sudo nano /etc/elasticsearch/elasticsearch.yml

When the script opens, find the network.host parameter and replace the existing value with your active server’s address. After changing the IP address, save and exit the file.

network.host: localhost

localhost network elasticsearch

Now, start and enable the Elasticsearch on your Linux system to reload it on your machine.

sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch

start and enable elasticsearch on Ubuntu

When you add a new IP address with a new port, it’s always brilliant to add it to the firewall. I must mention that by default, Elasticsearch uses the network ports 9200-9300. Here, I’ll use port 9200 for configuring Elasticsearch with the localhost address.

As Ubuntu uses the UFW tool for firewall settings, you can run the following UFW commands on your terminal shell to allow port 9200 on your system.

sudo ufw allow from to any port 9200
sudo ufw enable

You can now check the UFW status on the terminal shell to check if the port is added or not in the network system.

sudo ufw status

UFW Elasticsearch

If you are using Fedora, Red Hat Linux, and other Linux distributions, you use the Firewalld command to enable port 9200 for your environment. First, enable the Firewalld on your Linux system.

systemctl status firewalld
systemctl enable firewalld
sudo firewall-cmd --reload

Now, add the rule to the Firewalld settings. Then restart the Angular CLI system.

firewall-cmd --add-port=9200/tcp
firewall-cmd --list-all

Get Started With Elasticsearch

After installing, configuring server IP, and adding the firewall rules on our Linux system, it’s now time to get started with it. Here, I’ll run a cURL command to send a request to your server through Elasticsearch. In return, you would see the hostname, cluster name, UUID, and the tag line of Elasticsearch at the bottom of the return page.

curl -X GET 'http://localhost:9200'

test cURL elasticsearch on Ubuntu

We can try to insert a string data inside the Elasticsearch database and pull the data to check if it works perfectly or not. Run the following cURL command to push the data inside the system.

-X POST 'http://localhost:9200/ubuntupit/hello/1'
-H 'Content-Type: application /json' 
-d '{ "name" : " ubuntupit " }'

To pull the string data through Elasticsearch, run the following command on your system’s terminal shell.

curl -X GET 'http://localhost:9200/ubuntupit/hello/1'

Final Words

Elasticsearch is a popular tool for generating your own search engine. You would know that the big e-commerce giant Amazon uses Elasticsearch on its product storefront search. In the entire post, I’ve described how you can install, configure, and run your first query on Elasticsearch. You can also run a boolean query, have pagination datatable through the Elasticseach, and use UI tools like Kibana to use Elasticsearch with your existing database.

Please share this post with your friends and the Linux community if you find it helpful and handy. You can also write down your opinions regarding this post in the comment section.

Source link

- Advertisement -

More articles


Please enter your comment!
Please enter your name here

Latest article