How to Install and Configure Elasticsearch on Ubuntu 23.10

Elasticsearch is a platform for real-time, distributed data analysis. Because of its usability, potent features, and scalability, it is a well-liked option. Installing Elasticsearch, configuring it for your use case, securing your installation, and beginning to work with your Elasticsearch server.

First, check for any pending System Updates

Let's update software packages first. To perform updates, run the following command

apt update && apt upgrade

Installing from the APT repository

Add the Elasticsearch APT Repository on Ubuntu 23.10

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg

Need to install the apt-transport-https (APT) package using below command,

apt-get install apt-transport-https

To Save the repository definition to /etc/apt/sources.list.d/elastic-8.x.list:

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

Install Elasticsearch on Ubuntu 23.10

apt-get update && sudo apt-get install elasticsearch

Output:

--------------------------- Security autoconfiguration information ------------------------------

Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.

The generated password for the elastic built-in superuser is : 2ezNQ0FkHkR8BYHSTiio

Note: The password will be displayed above while installing; please note it.

Update Firewall Settings

Allow port 9200 for Elasticsearch by running the following ufw command

ufw allow 9200

Reload the firewall,

ufw reload

Next, view firewall service status:

ufw status

Configuring Elasticsearch

Let us configure Elasticsearch, we will edit its main configuration file elasticsearch.yml, which contains the majority of its configuration options. This file is located in the directory /etc/elasticsearch.

Edit the Elasticsearch configuration file with your preferred text editor. We'll use nano in this case:

nano /etc/elasticsearch/elasticsearch.yml

Note: Elasticsearch’s configuration file is in YAML format, which means that we need to maintain the indentation format. Be sure that you do not add any extra spaces as you edit this file.

Output:

# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: localhost
#

Because we specified localhost, Elasticsearch will listen on all interfaces and bound IPs. If you only want it to listen on one interface, use its IP address instead of localhost. Elasticsearch.yml should be saved and closed. If you're using nano, you can do so by pressing CTRL+X, then Y, and finally ENTER.

These are the bare minimum settings you can use to get started with Elasticsearch. You can now launch Elasticsearch for the first time.

Systemctl will start the Elasticsearch service. Allow Elasticsearch a few moments to load. Otherwise, you may receive errors indicating that you are unable to

Start the Elasticsearchservice,

systemctl start elasticsearch

Enable the Elasticsearchservice,

systemctl enable elasticsearch

Verify that the Elasticsearch has been installed and running on the server by running the following command:

curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200

You will be prompted to enter the password for the elastic user. Use the password that was provided to you during the installation from earlier.

Output:

root@server:~# curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200
Enter host password for user 'elastic':
{
  "name" : "server",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "n9hsO_nPQW2HjE7y6RUp2Q",
  "version" : {
    "number" : "8.10.4",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "b4a62ac808e886ff032700c391f45f1408b2538c",
    "build_date" : "2023-10-11T22:04:35.506990650Z",
    "build_snapshot" : false,
    "lucene_version" : "9.7.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

This concludes the Installation and Configure Elasticsearch on Ubuntu 23.10.