From d55288339a77861a0f4e6ce06a356c625ebc5584 Mon Sep 17 00:00:00 2001 From: Jeff Huss Date: Mon, 14 Nov 2022 12:23:31 -0800 Subject: [PATCH] Added instructions for enabling opensearch as a service with systemd (#1771) * Added instructions for enabling opensearch as a service with systemd Signed-off-by: JeffH-AWS * Placeholder changes Signed-off-by: JeffH-AWS * Added disclaimer and cleaned up some wording Signed-off-by: JeffH-AWS * Fixed wording Signed-off-by: JeffH-AWS Signed-off-by: JeffH-AWS --- _opensearch/cluster.md | 5 ++- _opensearch/install/tar.md | 80 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/_opensearch/cluster.md b/_opensearch/cluster.md index c4a2bd05..8a2be2bd 100644 --- a/_opensearch/cluster.md +++ b/_opensearch/cluster.md @@ -152,6 +152,9 @@ After you set the configurations, start OpenSearch on all nodes: sudo systemctl start opensearch.service ``` +Installing OpenSearch from a tar archive will not automatically create a service with `systemd`. See [Run OpenSearch as a service with systemd]({{site.url}}{{site.baseurl}}/opensearch/install/tar/#run-opensearch-as-a-service-with-systemd) for instructions on how to create and start the service if you receive an error like `Failed to start opensearch.service: Unit not found.` +{: .tip} + Then go to the logs file to see the formation of the cluster: ```bash @@ -172,7 +175,7 @@ x.x.x.x 34 38 0 0.12 0.07 0.06 md - o x.x.x.x 23 38 0 0.12 0.07 0.06 md - opensearch-c1 ``` -To better understand and monitor your cluster, use the [cat API]({{site.url}}{{site.baseurl}}/opensearch/catapis/). +To better understand and monitor your cluster, use the [CAT API]({{site.url}}{{site.baseurl}}/opensearch/catapis/). ## (Advanced) Step 6: Configure shard allocation awareness or forced awareness diff --git a/_opensearch/install/tar.md b/_opensearch/install/tar.md index 40dfd911..8df218d4 100644 --- a/_opensearch/install/tar.md +++ b/_opensearch/install/tar.md @@ -453,6 +453,86 @@ $ curl https://your.host.address:9200 -u admin:yournewpassword -k } ``` +### Run OpenSearch as a service with systemd + +Create a service for OpenSearch and register it with `systemd`. After the service has been defined, you can enable, start, and stop the OpenSearch service using `systemctl` commands. The commands in this section reflect an environment where OpenSearch has been installed to `/opt/opensearch` and should be changed depending on your installation path. + +The following configuration is only suitable for testing in a non-production environment. We do not recommend using the following configuration in a production environment. You should install OpenSearch with the [RPM]({{site.url}}{{site.baseurl}}/opensearch/install/rpm/) distribution if you want to run OpenSearch as a systemd-managed service on your host. The tarball installation does not define a specific installation path, users, roles, or permissions. Failure to properly secure your host environment can result in unexpected behavior. +{: .warning} + +1. Create a user for the OpenSearch service. + ```bash + sudo adduser --system --shell /bin/bash -U --no-create-home opensearch + ``` + +1. Add your user to the `opensearch` user group. + ```bash + sudo usermod -aG opensearch $USER + ``` + +1. Change the file owner to `opensearch`. Make sure to change the path if your OpenSearch files are in a different directory. + ```bash + sudo chown -R opensearch /opt/opensearch/ + ``` + +1. Create the service file and open it for editing. + ```bash + sudo vi /etc/systemd/system/opensearch.service + ``` + +1. Enter the following example service configuration. Make sure to change references to the path if your OpenSearch files are in a different directory. + ```bash + [Unit] + Description=OpenSearch + Wants=network-online.target + After=network-online.target + + [Service] + Type=forking + RuntimeDirectory=data + + WorkingDirectory=/opt/opensearch + ExecStart=/opt/opensearch/bin/opensearch -d + + User=opensearch + Group=opensearch + StandardOutput=journal + StandardError=inherit + LimitNOFILE=65535 + LimitNPROC=4096 + LimitAS=infinity + LimitFSIZE=infinity + TimeoutStopSec=0 + KillSignal=SIGTERM + KillMode=process + SendSIGKILL=no + SuccessExitStatus=143 + TimeoutStartSec=75 + + [Install] + WantedBy=multi-user.target + ``` + +1. Reload `systemd` manager configuration. + ```bash + sudo systemctl daemon-reload + ``` + +1. Enable the OpenSearch service. + ```bash + sudo systemctl enable opensearch.service + ``` + +1. Start the OpenSearch service. + ```bash + sudo systemctl start opensearch + ``` + +1. Verify that the service is running. + ```bash + sudo systemctl status opensearch + ``` + ## Related links - [OpenSearch configuration]({{site.url}}{{site.baseurl}}/opensearch/configuration/)