How to install OpenSearch on Ubuntu 20.04

To Install OpenSearch On Ubuntu 20.04

Introduction

OpenSearch is a collaborative, open-source search and analytics platform utilized by developers for data ingestion, search, visualization, and analysis. The platform includes a data store and search engine (OpenSearch), a visualization tool and user interface (OpenSearch Dashboards), and a server-side data collector (Data Prepper). Additionally, users have the option to enhance the capabilities of OpenSearch through a variety of plugins that improve search, analytics, observability, security, machine learning, and other features.

Procedure Steps

Step 1: Check the OS version by using the below command

root@ubuntu:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Step 2: Install compatible Java Versions by using the below command.

root@ubuntu:~# apt install openjdk-21-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  ca-certificates-java fonts-dejavu-extra java-common libatk-wrapper-java libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-de
  openjdk-21-jdk-headless openjdk-21-jre openjdk-21-jre-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev
Suggested packages:
  default-jre libice-doc libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-21-demo openjdk-21-source visualvm fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei | fonts-wqy-zenhei
The following NEW packages will be installed:
  ca-certificates-java fonts-dejavu-extra java-common libatk-wrapper-java libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxt-de
  openjdk-21-jdk-headless openjdk-21-jre openjdk-21-jre-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev
0 upgraded, 21 newly installed, 0 to remove and 10 not upgraded.
Need to get 132 MB of archives.
After this operation, 317 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
update-alternatives: using /usr/lib/jvm/java-21-openjdk-amd64/bin/jhsdb to provide /usr/bin/jhsdb (jhsdb) in auto mode
Setting up libxcb1-dev:amd64 (1.14-2) ...
Setting up libx11-dev:amd64 (2:1.6.9-2ubuntu1.6) ...
Setting up openjdk-21-jdk:amd64 (21.0.2+13-1~20.04.1) ...
update-alternatives: using /usr/lib/jvm/java-21-openjdk-amd64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode
Setting up libxt-dev:amd64 (1:1.1.5-1) ...

Step 3: Check the installed java version by using the below command.

root@ubuntu:~# java -version
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-120.04.1)
OpenJDK 64-Bit Server VM (build 21.0.2+13-Ubuntu-120.04.1, mixed mode, sharing)

Step 4: For production workloads, make sure the Linux setting vm.max_map_count is set to at least 262144. To check the current value, run the below command.

root@ubuntu:~# cat /proc/sys/vm/max_map_count
65530

Step 5: Increase the value from 65530 to 262144, for that open the /etc/sysctl.conf file by using the vim text editor and add the following lines.

root@ubuntu:~# vim /etc/sysctl.conf
vm.max_map_count=262144

Step 6: Reload to apply changes

root@ubuntu:~# sysctl -p
vm.max_map_count = 262144

Step 7: Install the necessary packages by using the below commands.

root@ubuntu:~# apt-get update && sudo apt-get -y install lsb-release ca-certificates curl gnupg2
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
lsb-release set to manually installed.
ca-certificates is already the newest version (20230311ubuntu0.20.04.1).
ca-certificates set to manually installed.
The following additional packages will be installed:
  libcurl4
The following NEW packages will be installed:
  curl gnupg2 libcurl4
0 upgraded, 3 newly installed, 0 to remove and 10 not upgraded.
Need to get 401 kB of archives.
After this operation, 1,179 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libcurl4 amd64 7.68.0-1ubuntu2.22 [235 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 curl amd64 7.68.0-1ubuntu2.22 [161 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 gnupg2 all 2.2.19-3ubuntu2.2 [5,316 B]
Fetched 401 kB in 3s (130 kB/s)
Selecting previously unselected package libcurl4:amd64.
(Reading database ... 162978 files and directories currently installed.)
Preparing to unpack .../libcurl4_7.68.0-1ubuntu2.22_amd64.deb ...
Unpacking libcurl4:amd64 (7.68.0-1ubuntu2.22) ...
Selecting previously unselected package curl.
Preparing to unpack .../curl_7.68.0-1ubuntu2.22_amd64.deb ...
Unpacking curl (7.68.0-1ubuntu2.22) ...
Selecting previously unselected package gnupg2.
Preparing to unpack .../gnupg2_2.2.19-3ubuntu2.2_all.deb ...
Unpacking gnupg2 (2.2.19-3ubuntu2.2) ...
Setting up gnupg2 (2.2.19-3ubuntu2.2) ...
Setting up libcurl4:amd64 (7.68.0-1ubuntu2.22) ...
Setting up curl (7.68.0-1ubuntu2.22) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.15) ...

Step 8: Import the public GPG key by using the below command. This key is used to verify that the APT repository is signed.

root@ubuntu:~# curl -o- https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo gpg --dearmor --batch --yes -o /usr/share/keyrings/opensearch-keyring
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4300  100  4300    0     0  28859      0 --:--:-- --:--:-- --:--:-- 28859

Step 9: Create an APT repository for OpenSearch by using the below command

root@ubuntu:~# echo "deb [signed-by=/usr/share/keyrings/opensearch-keyring] https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | sudo tee /etc/apt/sources.list.d/open
deb [signed-by=/usr/share/keyrings/opensearch-keyring] https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main

Step 10: Verify that the repository was created successfully by running the below command.

root@ubuntu:~# sudo apt-get update
Get:1 https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable InRelease [7,536 B]
Get:2 https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable/main amd64 Packages [2,542 B]
Hit:3 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:6 http://security.ubuntu.com/ubuntu focal-security InRelease
Fetched 10.1 kB in 3s (3,844 B/s)
Reading package lists... Done
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable InRelease' doesn't support architecture

Step 11: With the repository information added, list all available versions of OpenSearch by using the below command.

root@ubuntu:~# sudo apt list -a opensearch
Listing... Done
opensearch/stable 2.14.0 amd64
opensearch/stable 2.13.0 amd64
opensearch/stable 2.12.0 amd64
opensearch/stable 2.11.1 amd64
opensearch/stable 2.11.0 amd64
opensearch/stable 2.10.0 amd64
opensearch/stable 2.9.0 amd64
opensearch/stable 2.8.0 amd64
opensearch/stable 2.7.0 amd64
opensearch/stable 2.6.0 amd64
opensearch/stable 2.5.0 amd64

Step 12: For new installations of OpenSearch 2.12 and later, you must define a custom admin password in order to set up a demo security configuration.

root@ubuntu:~# env OPENSEARCH_INITIAL_ADMIN_PASSWORD=ka0JY8Hrg8KCcQ95  apt-get install opensearch=2.12.0
Reading package lists... Done
Building dependency tree
Reading state information... Done
opensearch is already the newest version (2.12.0).
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up opensearch (2.12.0) ...
Running OpenSearch Post-Installation Script
### NOT starting on installation, please execute the following statements to configure opensearch service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable opensearch.service
### You can start opensearch service by executing
 sudo systemctl start opensearch.service
### Create opensearch demo certificates in /etc/opensearch/
 See demo certs creation log in /var/log/opensearch/install_demo_configuration.log
### Upcoming breaking change in packaging
 In a future release of OpenSearch, we plan to change the permissions associated with access to installed files
 If you are configuring tools that require read access to the OpenSearch configuration files, we recommend you add the user that runs these tools to the 'opensearch' group
 For more information, see https://github.com/opensearch-project/opensearch-build/pull/4043
Processing triggers for libc-bin (2.31-0ubuntu9.15) ...

Step 13: Enable and Start opensearch by using the below command

root@ubuntu:~# systemctl enable opensearch
Synchronizing state of opensearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable opensearch
Created symlink /etc/systemd/system/multi-user.target.wants/opensearch.service → /lib/systemd/system/opensearch.service.
root@ubuntu:~# systemctl start opensearch

Step 14: Verify the status of opensearch by using the below command

root@ubuntu:~# systemctl status opensearch
● opensearch.service - OpenSearch
     Loaded: loaded (/lib/systemd/system/opensearch.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2024-05-18 05:50:01 PDT; 2min 47s ago
       Docs: https://opensearch.org/
   Main PID: 8055 (java)
      Tasks: 69 (limit: 4556)
     Memory: 1.3G
     CGroup: /system.slice/opensearch.service
             └─8055 /usr/share/opensearch/jdk/bin/java -Xshare:auto -Dopensearch.networkaddress.cache.ttl=60 -Dopensearch.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt

May 18 05:49:26 ubuntu systemd-entrypoint[8055]: WARNING: System::setSecurityManager has been called by org.opensearch.bootstrap.OpenSearch (file:/usr/share/opensearch/lib/opensearch-2.12.0.jar)
May 18 05:49:26 ubuntu systemd-entrypoint[8055]: WARNING: Please consider reporting this to the maintainers of org.opensearch.bootstrap.OpenSearch
May 18 05:49:26 ubuntu systemd-entrypoint[8055]: WARNING: System::setSecurityManager will be removed in a future release
May 18 05:49:28 ubuntu systemd-entrypoint[8055]: May 18, 2024 5:49:28 AM sun.util.locale.provider.LocaleProviderAdapter <clinit>
May 18 05:49:28 ubuntu systemd-entrypoint[8055]: WARNING: COMPAT locale provider will be removed in a future release
May 18 05:49:30 ubuntu systemd-entrypoint[8055]: WARNING: A terminally deprecated method in java.lang.System has been called
May 18 05:49:30 ubuntu systemd-entrypoint[8055]: WARNING: System::setSecurityManager has been called by org.opensearch.bootstrap.Security (file:/usr/share/opensearch/lib/opensearch-2.12.0.jar)
May 18 05:49:30 ubuntu systemd-entrypoint[8055]: WARNING: Please consider reporting this to the maintainers of org.opensearch.bootstrap.Security
May 18 05:49:30 ubuntu systemd-entrypoint[8055]: WARNING: System::setSecurityManager will be removed in a future release
May 18 05:50:01 ubuntu systemd[1]: Started OpenSearch.

Step 15: Send requests to port 9200 to verify that OpenSearch is running. Note the use of the --insecure flag, which is required because the TLS certificates are self-signed.

root@ubuntu:~# curl -X GET https://localhost:9200 -u 'admin:ka0JY8Hrg8KCcQ95' –insecure

You should get a response that looks like this:

{
  "name" : "ubuntu",
  "cluster_name" : "opensearch",
  "cluster_uuid" : "ntJOWmC8T4GjLPZWJ8FHXw",
  "version" : {
    "distribution" : "opensearch",
    "number" : "2.12.0",
    "build_type" : "deb",
    "build_hash" : "2c355ce1a427e4a528778d4054436b5c4b756221",
    "build_date" : "2024-02-20T02:18:31.541484890Z",
    "build_snapshot" : false,
    "lucene_version" : "9.9.2",
    "minimum_wire_compatibility_version" : "7.10.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "The OpenSearch Project: https://opensearch.org/"
}

Step 16: Query the plugins endpoint by using the below command

root@ubuntu:~# curl -X GET https://localhost:9200/_cat/plugins?v -u 'admin:ka0JY8Hrg8KCcQ95' –insecure

The response should look like this:

name   component                            version
ubuntu opensearch-alerting                  2.12.0.0
ubuntu opensearch-anomaly-detection         2.12.0.0
ubuntu opensearch-asynchronous-search       2.12.0.0
ubuntu opensearch-cross-cluster-replication 2.12.0.0
ubuntu opensearch-custom-codecs             2.12.0.0
ubuntu opensearch-flow-framework            2.12.0.0
ubuntu opensearch-geospatial                2.12.0.0
ubuntu opensearch-index-management          2.12.0.0
ubuntu opensearch-job-scheduler             2.12.0.0
ubuntu opensearch-knn                       2.12.0.0
ubuntu opensearch-ml                        2.12.0.0
ubuntu opensearch-neural-search             2.12.0.0
ubuntu opensearch-notifications             2.12.0.0
ubuntu opensearch-notifications-core        2.12.0.0
ubuntu opensearch-observability             2.12.0.0
ubuntu opensearch-performance-analyzer      2.12.0.0
ubuntu opensearch-reports-scheduler         2.12.0.0
ubuntu opensearch-security                  2.12.0.0
ubuntu opensearch-security-analytics        2.12.0.0
ubuntu opensearch-skills                    2.12.0.0
ubuntu opensearch-sql                       2.12.0.0

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to install OpenSearch on Ubuntu 20.04. Your feedback is much welcome.

FAQ
Q
How do I manage OpenSearch logs?
A
Logs are stored in /var/log/opensearch/. Configure logging settings in the log4j2.properties file in the /etc/opensearch directory.
Q
How do I verify OpenSearch is running correctly?
A
Use the command curl -X GET "localhost:9200" to check the OpenSearch cluster status.
Q
How do I configure OpenSearch after installation?
A
Modify the configuration file at /etc/opensearch/opensearch.yml to set parameters like cluster.name, node.name, and network.host.
Q
How do I install Java, required by OpenSearch, on Linux?
A
Install Java 11 with the command: sudo apt install openjdk-21-jdk -y (Debian/Ubuntu) or sudo dnf install java-21-openjdk-devel -y (Red Hat-based).
Q
What is OpenSearch?
A
OpenSearch is an open-source search and analytics suite, a fork of Elasticsearch and Kibana.