How to Install Elasticsearch on a Linux Server

Elasticsearch is a powerful, distributed search and analytics engine that is commonly used for full-text search, log aggregation, and real-time data processing. It is designed to handle large amounts of unstructured data and is a core component of the ELK stack (Elasticsearch, Logstash, Kibana). This guide will walk you through the steps to install Elasticsearch on your Linux server.

Why Use Elasticsearch on Your Linux Server?

Elasticsearch on a Linux Server

Elasticsearch is highly regarded for its speed, scalability, and flexibility. It is ideal for managing and searching large datasets, which is why it’s widely used for logging, monitoring, and full-text search applications. Elasticsearch’s distributed architecture ensures that it can handle increasing data volumes without compromising performance. With features like real-time indexing and fast searches, it is a key tool for developers and system administrators dealing with high-throughput, real-time data.

Common use cases for Elasticsearch include:

  • Website search: Elasticsearch powers fast and relevant search experiences on many websites.
  • Log management: It aggregates and indexes logs, making it easier to analyze system activity.
  • Data analytics: Elasticsearch enables the analysis of large amounts of unstructured or semi-structured data to gain valuable insights.
  • Monitoring: Real-time metrics and event monitoring in various applications.

Prerequisites

Before proceeding with the installation, make sure you have the following:

  • Root or sudo privileges: You need administrative access to install and configure Elasticsearch.
  • A Linux server running a compatible distribution (Ubuntu, Debian, CentOS, RHEL, etc.).
  • Java Runtime Environment (JRE): Elasticsearch requires Java 8 or later to run.
  • Internet connection: You will need access to the internet to download the Elasticsearch package and its dependencies.
  • Basic command-line knowledge: Familiarity with using the Linux terminal is necessary for executing commands.

Install Elasticsearch on a Linux Server

Elasticsearch can be easily installed on a Linux server using package managers like apt or yum, depending on your distribution. Follow the steps below to install it on your system.

Update Your Package List

Before installing any software, it’s always good practice to update your system’s package list to ensure you’re working with the latest available versions.

  • For Ubuntu/Debian-based systems:
sudo apt update
  • For CentOS/RHEL-based systems:
sudo yum update

Install Java (If Not Installed)

Elasticsearch requires Java 8 or later. If Java is not installed on your system, you can install it easily using the following commands.

  • For Ubuntu/Debian-based systems:
sudo apt install openjdk-11-jdk
  • For CentOS/RHEL-based systems:
sudo yum install java-11-openjdk

Once installed, verify Java is set up correctly by checking the version:

java -version

Add the Elasticsearch APT or YUM Repository

To install Elasticsearch, you must first add its official repository to your system’s package manager.

For Ubuntu/Debian-based systems:

  • Install Required Dependencies
sudo apt install -y gnupg curl apt-transport-https
  • Import the Elasticsearch GPG Key
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] \
https://artifacts.elastic.co/packages/8.x/apt stable main" | \
sudo tee /etc/apt/sources.list.d/elastic-8.x.list

For CentOS/RHEL-based systems:

  • Install Required Dependencies
sudo yum install -y curl gnupg2
  • Import the Elasticsearch GPG Key
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
  • Install the Elasticsearch YUM repository:
sudo yum install https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.x.rpm

Install Elasticsearch

Now that the repository is added, you can install Elasticsearch using your package manager.

  • For Ubuntu/Debian-based systems:
sudo apt update sudo apt install elasticsearch
  • For CentOS/RHEL-based systems:
sudo yum install elasticsearch

Configure Elasticsearch

Before starting Elasticsearch, you may want to configure some basic settings, such as memory allocation or network settings. The main configuration file for Elasticsearch is located at /etc/elasticsearch/elasticsearch.yml.

Some common configurations include:

  • Cluster Name: Set a custom cluster name for your Elasticsearch instance:
cluster.name: my-cluster
  • Network Settings: To allow external access to Elasticsearch, set the network.host to your server’s IP address or hostname:
network.host: 0.0.0.0
  • Memory Settings: By default, Elasticsearch uses 1GB of RAM. You can adjust the heap size by editing the jvm.options file located at /etc/elasticsearch/jvm.options:
-Xms2g
-Xmx2g

Start and Enable Elasticsearch

Once the configuration is done, start the Elasticsearch service and enable it to run on system boot.

To start Elasticsearch:

sudo systemctl start elasticsearch

To enable Elasticsearch to start automatically at boot:

sudo systemctl enable elasticsearch

Check the status of Elasticsearch to ensure it is running correctly:

sudo systemctl status elasticsearch

Verify Elasticsearch Installation

To verify that Elasticsearch is installed and running correctly, you can test the service by making an HTTP request to the local server.

Run the following curl command:

curl -X GET "localhost:9200/"

You should receive a JSON response that includes version information and cluster health status.

Check Out | How to Install MongoDB on a Linux Server

Configure Elasticsearch for Security

By default, Elasticsearch does not require authentication. If you’re running Elasticsearch in a production environment, it’s highly recommended to secure it.

To enable security features, you can use the X-Pack plugin, which provides authentication, SSL encryption, and role-based access control (RBAC). X-Pack comes pre-installed with Elasticsearch in the basic license, but you may need to configure it according to your requirements.

You can enable SSL for secure communications by modifying the elasticsearch.yml file:

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

Verify Elasticsearch Operation

Once Elasticsearch is running, check the logs for any issues:

sudo less /var/log/elasticsearch/elasticsearch.log

You can also perform a simple test by creating and querying an index:

curl -X PUT "localhost:9200/my_index?pretty"
curl -X GET "localhost:9200/my_index/_search?pretty"

Conclusion

In this guide, we walked through the steps to install and configure Elasticsearch on your Linux server. Elasticsearch is an essential tool for developers and system administrators who need fast, scalable search and analytics capabilities. After installation, you can explore additional features like data indexing, real-time search, and security configurations for your production environment.

Leave A Comment