Kennisbasis

Elastic Search Print

  • 0

How to Install Elasticsearch 8 on Ubuntu 24.04 (Manual Installation)

This guide explains how to manually install and configure Elasticsearch 8 on Ubuntu 24.04. It follows the same steps performed by the Ansible playbook but is written for beginners who prefer installing the application manually.


Prerequisites

  • An Ubuntu 24.04 VPS
  • A user account with sudo privileges
  • An internet connection
  • At least 4 GB RAM recommended

Step 1 - Update the System

Update your package list and install available updates.

sudo apt update
sudo apt upgrade -y

Step 2 - Install Required Packages

Install the packages required before Elasticsearch can be installed.

sudo apt install -y apt-transport-https ca-certificates curl gnupg ufw

Step 3 - Create the APT Key Directory

sudo mkdir -p /usr/share/keyrings

Step 4 - Download the Elasticsearch GPG Key

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

Step 5 - Add the Elasticsearch 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

Step 6 - Update Package Information

sudo apt update

Step 7 - Install Elasticsearch

sudo apt install elasticsearch -y

Step 8 - Configure Elasticsearch

Open the configuration file.

sudo nano /etc/elasticsearch/elasticsearch.yml

Find or add the following settings:

cluster.name: elasticsearch-cluster
node.name: elasticsearch-node-1

network.host: 0.0.0.0
http.port: 9200

discovery.type: single-node

Save the file.

  • Press CTRL + O
  • Press Enter
  • Press CTRL + X

Step 9 - Enable Elasticsearch

sudo systemctl enable elasticsearch

Step 10 - Start Elasticsearch

sudo systemctl start elasticsearch

Step 11 - Verify the Service

sudo systemctl status elasticsearch

You should see:

Active: active (running)

Step 12 - Allow Port 9200 (Optional)

If you use UFW, allow Elasticsearch traffic.

sudo ufw allow 9200/tcp
sudo ufw enable

Step 13 - Reset the Elastic User Password

Create a new password for the built-in elastic user.

sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

Copy the generated password because you will need it later.


Step 14 - Test Elasticsearch Locally

Copy the certificate so your normal user can access it.

sudo cp /etc/elasticsearch/certs/http_ca.crt ~/
sudo chown $USER:$USER ~/http_ca.crt

Run the following command:

curl --cacert ~/http_ca.crt -u elastic https://localhost:9200

Enter the password generated in the previous step.

If everything is working correctly you should receive output similar to:

{
  "name" : "elasticsearch-node-1",
  "cluster_name" : "elasticsearch-cluster",
  "version" : {
    "number" : "8.x.x"
  },
  "tagline" : "You Know, for Search"
}

Step 15 - Create an Administrator User

Create a new administrator account.

sudo /usr/share/elasticsearch/bin/elasticsearch-users useradd esadmin -r superuser

Enter a password when prompted.


Step 16 - Test the New User

curl --cacert ~/http_ca.crt -u esadmin https://localhost:9200

If prompted, enter the password you created for the esadmin user.


Step 17 - Create Your First Index

curl --cacert ~/http_ca.crt \
-u esadmin \
-X POST \
-H "Content-Type: application/json" \
https://localhost:9200/example/_doc/1 \
-d '{"message":"Hello world!"}'

Step 18 - Search the Index

curl --cacert ~/http_ca.crt \
-u esadmin \
"https://localhost:9200/example/_search?pretty"

You should see your document:

{
  "message": "Hello world!"
}

Accessing Elasticsearch

Elasticsearch is a REST API service, not a graphical web application.

You can access it using:

https://YOUR_SERVER_IP:9200

or

https://YOUR_DOMAIN:9200

When visiting the URL in a browser you will usually be prompted for a username and password. After signing in, Elasticsearch returns JSON data instead of a graphical interface.


Important Note

If you want a graphical interface to manage Elasticsearch, install Kibana. Kibana provides dashboards, search tools, visualizations, and index management through your web browser.


Useful Commands

sudo systemctl start elasticsearch
sudo systemctl stop elasticsearch
sudo systemctl restart elasticsearch
sudo systemctl status elasticsearch

curl --cacert ~/http_ca.crt -u esadmin https://localhost:9200

Conclusion

You have successfully installed Elasticsearch 8 on Ubuntu 24.04, created an administrator account, secured the installation with HTTPS, and verified that the server is working correctly. You can now use Elasticsearch through its REST API or install Kibana for a web-based management interface.


Was hierdie antwoord nuttig?
Back