Elasticsearch is a real-time, distributed, and scalable search engine based on Lucene, enabling users to store, search, and analyze massive volumes of data swiftly. It’s often used for log and event data analysis in IT environments. In this guide, we will explain how to install and configure Elasticsearch on Ubuntu 22.04.

Advertisement

Please note, this guide assumes that you are working as a non-root user with sudo privileges configured on a Ubuntu 22.04 server.

Step 1: Installing Java

Since Elasticsearch is built using Java, we need to install it. At the time of writing, Elasticsearch requires at least Java 8 to operate, but can also work with newer versions. For this guide, we’ll use OpenJDK 11.

First, update the package lists for upgrades and new package installations:

sudo apt-get update 

Then, install the default-jdk package, which installs OpenJDK 11:

sudo apt-get install -y default-jdk 

Verify the Java installation by checking the version:

java -version 

This should display the installed version of Java.

Step 2: Installing Elasticsearch

Elasticsearch is not available in the default Ubuntu 22.04 repositories. Therefore, we will install it from the official Elastic APT repository.

First, import the Elasticsearch public GPG key into APT:

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

Next, we need to add the Elastic APT repository. Since the lsb_release -cs sub-command will return the name of your Ubuntu distribution (such as ‘focal’), the command will add the correct repository:

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 

Update the package lists again:

sudo apt-get update 

Then install Elasticsearch:

sudo apt install elasticsearch 

Elasticsearch is now installed but not yet running. Let’s fix that.

Step 3: Configuring and Running Elasticsearch

Before we start Elasticsearch for the first time, we need to configure a few things.

The Elasticsearch configuration file is located at /etc/elasticsearch/elasticsearch.yml. Open it in your favorite text editor:

sudo nano /etc/elasticsearch/elasticsearch.yml 

In this file, you can set various settings such as the network host and the maximum amount of memory that Elasticsearch can use. For now, let’s just set the network host.

Find the line that contains network.host, uncomment it, and change its value to ‘localhost’:

Save and close the file.

Next, enable Elasticsearch to start on boot:

sudo systemctl enable elasticsearch 

Now you can start Elasticsearch:

sudo systemctl start elasticsearch 

Wait for a few seconds for Elasticsearch to start, then verify that it’s working by sending an HTTP request:

curl -X GET "localhost:9200/" 

You should see a response with the name of your Elasticsearch node and its version, which means that Elasticsearch is running correctly.

Step 4: Configuring Elasticsearch to Start on Boot

You will want Elasticsearch to run when your system boots. To enable this, use the following command:

sudo systemctl enable elasticsearch 

Step 5: Configuring the Elasticsearch Cluster (optional)

If you plan to use multiple servers and want them to connect as a cluster, you should configure the cluster settings. To do this, edit the elasticsearch.yml file:

sudo nano /etc/elasticsearch/elasticsearch.yml 

You need to add or edit the following lines with your respective settings:

Here myCluster is the name of your cluster and myNode is the name of your node. Make sure to replace these with your own names.

After making these changes, save and close the file. You’ll need to restart Elasticsearch for the changes to take effect:

sudo systemctl restart elasticsearch 

Conclusion

You have successfully installed and configured Elasticsearch on your Ubuntu 22.04 server. You can now start using Elasticsearch to store, search, and analyze data. The next steps for you are to learn Elasticsearch’s query syntax and how to import data into your new search engine. If you are using a firewall, don’t forget to open the necessary ports.

Share.
Leave A Reply


Exit mobile version