To install Elasticsearch on Ubuntu 22, you can follow these steps:

Update System Packages

Open a terminal and run the following commands to update the system packages to their latest versions

sudo apt update
sudo apt upgrade

 

Install Java Development Kit (JDK)
Elasticsearch requires Java to run. Install OpenJDK using the following command

sudo apt install openjdk-11-jdk

 

Import the Elasticsearch GPG Key
Run the command below to import the Elasticsearch GPG key

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

Add Elasticsearch Repository
Create the Elasticsearch source list file with the command

echo "deb [signed-by=/usr/share/keyrings/elasticsearch-archive-keyring.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic.list

 

Install Elasticsearch
Update the package list and install Elasticsearch using the following commands

sudo apt update
sudo apt install elasticsearch

 

Start and Enable Elasticsearch
Start the Elasticsearch service and enable it to start automatically on system boot

Start and Enable Elasticsearch:
Start the Elasticsearch service and enable it to start automatically on system boot

 

Verify Installation
Check the status of Elasticsearch to ensure it is running without any issues

sudo systemctl status elasticsearch

If Elasticsearch is running correctly, you should see a "active (running)" status message.

Congratulations! You have successfully installed Elasticsearch on Ubuntu 22. Elasticsearch should now be accessible at http://localhost:9200.

 

Common configuration options you may need to modify

Cluster Name
Specify a unique name for your Elasticsearch cluster. Open the Elasticsearch configuration file (elasticsearch.yml) and add or modify the following line

cluster.name: your_cluster_name

Replace your_cluster_name with the desired name for your Elasticsearch cluster.

 

Node Name
Set a name for the Elasticsearch node. Add or modify the following line in the configuration file

node.name: your_node_name

Replace your_node_name with the desired name for the Elasticsearch node.

 

Network Settings
Configure network-related settings such as host and port. By default, Elasticsearch binds to localhost on port 9200. Modify the following lines to change the network settings

network.host: 0.0.0.0
http.port: 9200

In this example, Elasticsearch is configured to bind to all available network interfaces (0.0.0.0) and listen on port 9200. Adjust these settings based on your network requirements.

 

Discovery Settings
Specify the discovery mechanism for Elasticsearch to find other nodes in the cluster. If you're running a single-node cluster or using a static list of nodes, you can disable the discovery feature. Add or modify the following line

discovery.type: single-node

Setting the discovery.type to single-node disables the discovery mechanism.

 

Memory Settings
Adjust the memory allocation settings for Elasticsearch based on your server's resources. These settings control the amount of memory allocated to Elasticsearch's heap space. Locate the following lines and modify them according to your needs

# Set the initial heap size
-Xms2g
# Set the maximum heap size
-Xmx2g

In this example, Elasticsearch is configured with an initial heap size of 2g and a maximum heap size of 2g. Adjust these values based on the available memory on your server.

 

The Elasticsearch configuration file (elasticsearch.yml) provides a wide range of options for customizing the server's behavior. You can explore additional settings such as logging, indexing, caching, security, and more in the official Elasticsearch documentation.


Once you've made the necessary configuration changes, save the file and restart the Elasticsearch server for the modifications to take effect.

Note: It's important to be cautious when modifying Elasticsearch configuration settings, as incorrect configuration can impact the performance and stability of your Elasticsearch cluster. Always refer to the Elasticsearch documentation and consult best practices for optimal configuration.