How To Install OpenSearch on Ubuntu 22.04

Introduction

OpenSearch is an open-source search and analytics engine, built from Elasticsearch 7.10 and Kibana 7.10. It is used for log monitoring, dashboards, full-text search, and data analytics. In this guide, we will install and configure OpenSearch on Ubuntu 22.04 step by step.

Step 1: Update System

sudo apt update && sudo apt upgrade -y

Step 2: Install Java

OpenSearch requires Java 11 or later.
sudo apt install -y openjdk-11-jdk
java -version

Step 3: Download and Install OpenSearch

Download the latest OpenSearch package:
wget https://artifacts.opensearch.org/releases/bundle/opensearch/2.12.0/opensearch-2.12.0-linux-x64.tar.gz
tar -xvf opensearch-2.12.0-linux-x64.tar.gz
sudo mv opensearch-2.12.0 /usr/local/opensearch

Step 4: Create OpenSearch User

sudo useradd opensearch -d /usr/local/opensearch
sudo chown -R opensearch:opensearch /usr/local/opensearch

Step 5: Configure OpenSearch

Edit /usr/local/opensearch/config/opensearch.yml:
cluster.name: my-opensearch-cluster
node.name: node-1
path.data: /usr/local/opensearch/data
path.logs: /usr/local/opensearch/logs
network.host: 0.0.0.0
http.port: 9200
discovery.type: single-node

Step 6: Create Systemd Service

sudo nano /etc/systemd/system/opensearch.service
Add:
[Unit]
Description=OpenSearch
Wants=network.target
After=network.target

[Service]
Type=simple
User=opensearch
ExecStart=/usr/local/opensearch/bin/opensearch
Restart=always
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
Reload and start service:
sudo systemctl daemon-reload
sudo systemctl enable opensearch
sudo systemctl start opensearch

Step 7: Verify OpenSearch

Check status:
sudo systemctl status opensearch
Test using curl:
curl -X GET "http://localhost:9200"
You should see JSON output with cluster info.

Step 8: Access OpenSearch Dashboard (Optional)

Install OpenSearch Dashboard for UI:
wget https://artifacts.opensearch.org/releases/bundle/opensearch-dashboards/2.12.0/opensearch-dashboards-2.12.0-linux-x64.tar.gz
tar -xvf opensearch-dashboards-2.12.0-linux-x64.tar.gz
sudo mv opensearch-dashboards-2.12.0 /usr/local/opensearch-dashboards
Edit /usr/local/opensearch-dashboards/config/opensearch_dashboards.yml:
server.host: "0.0.0.0"
opensearch.hosts: ["http://localhost:9200"]
Start Dashboard:
cd /usr/local/opensearch-dashboards
./bin/opensearch-dashboards
Access UI: http://server-ip:5601

Practical for Students

  • Check OpenSearch status with systemctl and curl.
  • Create an index: curl -X PUT "localhost:9200/test-index"
  • Insert a document: curl -X POST "localhost:9200/test-index/_doc/1" -H 'Content-Type: application/json' -d '{"name":"student","course":"linux"}'
  • Search document: curl -X GET "localhost:9200/test-index/_search?q=course:linux"

Interview Tips & Tricks for OpenSearch

  • Q: What is OpenSearch? A: A community-driven, open-source search and analytics engine, forked from Elasticsearch 7.10.
  • Q: Which port does OpenSearch use by default? A: Port 9200.
  • Q: What is the difference between Elasticsearch and OpenSearch? A: OpenSearch is fully open-source and community-driven, while Elasticsearch moved to a restrictive license.
  • Q: How do you secure OpenSearch? A: Enable TLS, authentication, and role-based access control (RBAC).

Conclusion

We have successfully installed and configured OpenSearch on Ubuntu 22.04. We also learned how to install OpenSearch Dashboards for a web interface, and tested basic commands for index creation and searching. This setup is useful for logs monitoring, search, and analytics, and is widely used in modern production environments.

Leave a Reply

Your email address will not be published. Required fields are marked *