Home Linux ServerTools How to install Elasticsearch on Ubuntu 22.04

How to install Elasticsearch on Ubuntu 22.04

by Thạch Phạm
Published: Last Updated on
A+A-
Reset

Installing Elasticsearch on Ubuntu 22.04 with 4 steps.

Có thể bạn sẽ thích

Introduction

Elasticsearch is a search engine based on Lucene software. It provides a full-featured, distributed search engine with an HTTP web interface that supports JSON data. Elasticsearch is developed in Java and is released as open source under the Apache license. Elasticsearch is the most popular search engine, followed by Apache Solr, which is also based on Lucene.

Requirements

  • Ubuntu Server 22.04.
  • Recommended configuration: 2GB RAM/2 CPU

Implementation Guide

Step 1: Install Elasticsearch

Elasticsearch is not available in the default Ubuntu repositories. However, we can use the apt command to install directly from Elastic’s source.

First, use cURL to enter the GPG public Elasticsearch key into apt. This command will convert the key into a format that apt can use to verify downloaded packages.

  • Convert key format
AZDIGI Tutorial
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg
    
  • Next, add the Elastic source to the sources.list.d directory, where apt will search for the latest sources.
AZDIGI Tutorial
echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
    
  • Update the package list so that apt will use the new Elastic source.
AZDIGI Tutorial
sudo apt update
    
  • Install Elasticsearch
AZDIGI Tutorial
sudo apt install elasticsearch
    
How to install Elasticsearch on Ubuntu 22.04

Step 2: Configure Elasticsearch

After installing Elasticsearch, the configuration file will be named elasticsearch.yml and located at the path: /etc/elasticsearch/. In the above configuration file, you will make all the edits related to cluster, node, paths, memory, network, discovery and gateway.

By default, Elasticsearch will use Port 9200. If you want to ban all external access to Elasticsearch to prevent outsiders from reading your data, or shut down your Elasticsearch cluster via the [API REST], edit the content in the elasticsearch.yml file.

AZDIGI Tutorial
sudo nano /etc/elasticsearch/elasticsearch.yml
    

Find and edit the content below to:

#network.host: 192.168.0.1  => network.host: localhost
How to install Elasticsearch on Ubuntu 22.04

Conversely, if you need to configure an external user to connect to Elasticsearch, replace localhost with the IP you specify.

  • Start the service and enable system startup.
AZDIGI Tutorial
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
sudo systemctl status elasticsearch
    
How to install Elasticsearch on Ubuntu 22.04

Step 3: Configure Security for Elasticsearch

By default, everyone can connect to Elasticsearch via the HTTP API. So if you still want to allow specific users to connect to Elasticsearch via the HTTP API, you can use Ubuntu’s UFW firewall to limit and only allow certain users to connect to Elasticsearch.

  • For example, I have another server with IP 45.252.249.193, now I want to allow this IP to connect to Elasticsearch via HTTP API with the default port of TCP 9200, so I will configure it with the following command:
AZDIGI Tutorial
sudo ufw allow from 45.252.249.193 to any port 9200
    
  • Once done, enable and view the UFW status with the command:
AZDIGI Tutorial
sudo ufw enable
sudo ufw status
    
How to install Elasticsearch on Ubuntu 22.04

Step 4: Test Elasticsearch

Currently, Elasticsearch will run with Port 9200 on your VPS. You can do a quick test using cURL and a GET request.

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

If the installation is successful, you will get the following output:

How to install Elasticsearch on Ubuntu 22.04

Above are the complete steps to install Elasticsearch on Ubuntu 22.04. Hopefully, this article will be helpful to you. Wishing you success!

You can refer to other instructions at the link below:

If you need support, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign