How To Install and Configure Elasticsearch on Ubuntu 22.04

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 upgrade

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

apt update && apt upgrade

Install from APT Repository

Add the Elasticsearch APT Repository on Ubuntu 22.04

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg

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 22.04

apt install elasticsearch

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

Update Firewall Settings

Allow port 9200 for Elasticsearch by running the following ufw command

ufw allow from <yourserver.ip.address> to any port 9200

Enable the firewall service:

ufw enable

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@vps:~# curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200
Enter host password for user 'elastic':
{
  "name" : "vps.server.com",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "HZcPm0lAQMCcsx94chOPPA",
  "version" : {
    "number" : "8.5.1",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "c1310c45fc534583afe2c1c03046491efba2bba2",
    "build_date" : "2022-11-09T21:02:20.169855900Z",
    "build_snapshot" : false,
    "lucene_version" : "9.4.1",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
root@vps:~#

This concludes the Installation and Configure Elasticsearch on Ubuntu 22.04.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS