Install Opensearch as a service without using docker or Kubernetes like Elasticsearch?

How do I install OpenSearch and OpenSearch dashboard as service/RPM on Linux without using docker or K8s like Elasticsearch can be done?
Thanks in advance.

Here you go.

Path for service:

/etc/systemd/system/opensearch.service

Content of it:

[Unit]
Description=Opensearch
Documentation=https://opensearch.org/docs/latest
Requires=network.target remote-fs.target
After=network.target remote-fs.target
ConditionPathExists=/data/opensearch-1.2.3
ConditionPathExists=/data/opensearch/data
[Service]
User=opensearch
Group=opensearch
WorkingDirectory=/data/opensearch-1.2.3
ExecStart=/data/opensearch-1.2.3/bin/opensearch


# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65535

# Specifies the maximum number of processes
LimitNPROC=4096

# Specifies the maximum size of virtual memory
LimitAS=infinity

# Specifies the maximum file size
LimitFSIZE=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0

# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM

# Send the signal only to the JVM rather than its control group
KillMode=process

# Java process is never killed
SendSIGKILL=no

# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143

# Allow a slow startup before the systemd notifier module kicks in to extend the timeout
TimeoutStartSec=75

[Install]
WantedBy=multi-user.target

Status of Service:

root@sys-test-48-54:/data/opensearch-1.2.3# service opensearch status
* opensearch.service - Opensearch
   Loaded: loaded (/etc/systemd/system/opensearch.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2022-01-18 16:01:40 +07; 2min 14s ago
     Docs: https://opensearch.org/docs/latest
 Main PID: 22630 (java)
    Tasks: 144 (limit: 4915)
   CGroup: /system.slice/opensearch.service
           `-22630 /data/opensearch-1.2.3/jdk/bin/java -Xshare:auto -Dopensearch.networkaddress.cache.ttl=60 -Dopensearch.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna

Jan 18 16:03:22 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:22,226][WARN ][o.o.c.r.a.AllocationService] [opensearch-48-54] [si-context-1232][0] marking unavailable shards as stale: [M_pvF53NR_ORlcMwzqNCYQ]
Jan 18 16:03:22 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:22,227][WARN ][o.o.c.r.a.AllocationService] [opensearch-48-54] [si-youtube-2021-09][1] marking unavailable shards as stale: [dIqWTxi4T0yD7JICavIJHQ]
Jan 18 16:03:22 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:22,227][WARN ][o.o.c.r.a.AllocationService] [opensearch-48-54] [si-youtube-comment-2021-08][1] marking unavailable shards as stale: [v7utcGIUQ0yRo0qcfnEwMg]
Jan 18 16:03:22 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:22,227][WARN ][o.o.c.r.a.AllocationService] [opensearch-48-54] [security-auditlog-2022.01.09][0] marking unavailable shards as stale: [YrJGLw0XR0OWnK84KzkQFQ]
Jan 18 16:03:22 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:22,228][WARN ][o.o.c.r.a.AllocationService] [opensearch-48-54] [security-auditlog-2021.12.27][0] marking unavailable shards as stale: [kdwq-PXDSDCfgLy-1DaaHA]
Jan 18 16:03:27 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:27,640][INFO ][o.o.i.i.ManagedIndexCoordinator] [opensearch-48-54] Performing move cluster state metadata.
Jan 18 16:03:39 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:39,080][WARN ][o.o.c.r.a.AllocationService] [opensearch-48-54] [si-news-2021-12][1] marking unavailable shards as stale: [9Frpc2hwQIW3MT_n3sBOMw]
Jan 18 16:03:39 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:39,081][WARN ][o.o.c.r.a.AllocationService] [opensearch-48-54] [si-news-2021-11][1] marking unavailable shards as stale: [cWauA_G1Tc219s_-ZfkZVg]
Jan 18 16:03:39 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:39,082][WARN ][o.o.c.r.a.AllocationService] [opensearch-48-54] [si-news-2021-09][1] marking unavailable shards as stale: [V7Sc8MjmRAeMBntOst8SGg]
Jan 18 16:03:50 sys-test-48-54 opensearch[22630]: [2022-01-18T16:03:50,689][INFO ][o.o.c.r.a.a.BalancedShardsAllocator] [opensearch-48-54] Cannot move any shard in the cluster as there is no node on which shards can be allocated. Skipping

It is running with port 9200 + 9300

root@sys-test-48-54:/data/opensearch-1.2.3# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp6       0      0 :::9200                 :::*                    LISTEN      22630/java          
tcp6       0      0 :::9300                 :::*                    LISTEN      22630/java          

Note: You have to create user opensearch with it’s group.

/data/opensearch-1.2.3

is the location where I untar binary file for OpenSearch.

I only spend about 10 minutes to make it works so I bet it is not really optimized :joy_cat:
Most of it I copy open distro from

# Specifies the maximum file descr....

until the end.

Also, don’t forget to run this command after creating service file

systemctl daemon-reload
3 Likes

@BlackMetalz That’s really helpful man!!! So I can use OpenSearch Dashboard using a similar service file named opensearch-dashboard.service?

Yeah. I’m pretty sure they are the same xD. You can check the kibana service of opendistro for example

Great man!!! Thanks a lot

@avnishs could you please provide feedback regarding possibility to start OpenSearch as a service?
The config proposed by BlackMetalz did not work for me.
Installation path from the documentation
CentOS Linux release 8.5.2111

Also I tried different variations (for example this one from the official repository)

Lol. I used Ubuntu, not Centos so I guess it will be little different :sweat_smile:

Didn’t work for me too! but then I simply executed the bin files in the background using :slight_smile: bin_exec_command > /dev/null 2>&1 &
or if you want to log the startup output in a file then:
bin_exec_command > filename.log 2>&1 &

avnishs, thank you for your reply. If I can’t find the way to start OpenSearch as service, I will use the approach you suggested.

BlackMetalz, thank you for your reply. Are you sure that it is really principal in this case?)

Yes. :smiley:
( I don’t know why this post must have 20 characters requirement )

1 Like

I managed to start the OpenSearch as a service on CentOS 8 using the following workaround:

ExecStart=/bin/sh -c '/etc/opensearch/bin/opensearch'
1 Like