Tarball

    Generally speaking, the installation of OpenSearch from a tarball can be broken down into a few steps:

    1. Download and unpack OpenSearch.
    2. Configure important system settings.
      • These settings are applied to the host before modifying any OpenSearch files.
    3. (Optional) Test OpenSearch.
      • Confirm that OpenSearch is able to run before you apply any custom configuration.
      • This can be done without any security (no password, no certificates) or with a demo security configuration that can be applied by a packaged script.
    4. Configure OpenSearch for your environment.
      • Apply basic settings to OpenSearch and start using it in your environment.

    The tarball is a self-contained directory with everything needed to run OpenSearch, including an integrated Java Development Kit (JDK). This installation method is compatible with most Linux distributions, including CentOS 7, Amazon Linux 2, and Ubuntu 18.04. If you have your own Java installation and set the environment variable in the terminal, macOS works as well.

    This guide assumes that you are comfortable working from the Linux command line interface (CLI). You should understand how to input commands, navigate between directories, and edit text files. Some example commands reference the vi text editor, but you may use any text editor available.

    1. Download the appropriate tar.gz archive from the or by using the command line (such as with wget).

    2. Extract the contents of the tarball.

      1. # x64
      2. tar -xvf opensearch-2.7.0-linux-x64.tar.gz
      3. # ARM64
      4. tar -xvf opensearch-2.7.0-linux-arm64.tar.gz

    Before launching OpenSearch you should review some .

    1. Disable memory paging and swapping performance on the host to improve performance.

      1. sudo swapoff -a

      copy

    2. Increase the number of memory maps available to OpenSearch.

      1. # Edit the sysctl config file
      2. sudo vi /etc/sysctl.conf
      3. # Add a line to define the desired value
      4. # or change the value if the key exists,
      5. # and then save your changes.
      6. vm.max_map_count=262144
      7. # Reload the kernel parameters using sysctl
      8. sudo sysctl -p
      9. # Verify that the change was applied by checking the value
      10. cat /proc/sys/vm/max_map_count

    Before proceeding you should test your installation of OpenSearch. Otherwise, it can be difficult to determine whether future problems are due to installation issues or custom settings you applied after installation. There are two quick methods for testing OpenSearch at this stage:

    1. (Security enabled) Apply a generic configuration using the demo security script included in the tar archive.
    2. (Security disabled) Manually disable the Security plugin and test the instance before applying your own custom security settings.

    The demo security script will apply a generic configuration to your instance of OpenSearch. This configuration defines some environment variables and also applies self-signed TLS certificates. If you would like to configure these yourself, see .

    If you only want to verify that the service is properly configured and you intend to configure security settings yourself, then you may want to disable the Security plugin and launch the service without encryption or authentication.

    An OpenSearch node configured by the demo security script is not suitable for a production environment. If you plan to use the node in a production environment after running opensearch-tar-install.sh, you should, at a minimum, replace the demo TLS certificates with your own TLS certificates and update the list of internal users and passwords. See for additional guidance to ensure that your nodes are configured according to your security requirements.

    1. Change to the top directory of your OpenSearch installation.

      1. cd /path/to/opensearch-2.7.0

      copy

    2. Run the demo security script.

      1. ./opensearch-tar-install.sh

      copy

    3. Open another terminal session and send requests to the server to verify that OpenSearch is running. Note the use of the --insecure flag, which is required because the TLS certificates are self-signed.

      • Send a request to port 9200:

        1. curl -X GET https://localhost:9200 -u 'admin:admin' --insecure

        copy

        You should get a response that looks like this:

        1. {
        2. "name" : "hostname",
        3. "cluster_name" : "opensearch",
        4. "cluster_uuid" : "6XNc9m2gTUSIoKDqJit0PA",
        5. "version" : {
        6. "distribution" : "opensearch",
        7. "number" : <version>,
        8. "build_type" : <build-type>,
        9. "build_hash" : <build-hash>,
        10. "build_date" : <build-date>,
        11. "build_snapshot" : false,
        12. "lucene_version" : <lucene-version>,
        13. "minimum_wire_compatibility_version" : "7.10.0",
        14. "minimum_index_compatibility_version" : "7.0.0"
        15. },
        16. "tagline" : "The OpenSearch Project: https://opensearch.org/"
        17. }
      • Query the plugins endpoint:

        1. curl -X GET https://localhost:9200/_cat/plugins?v -u 'admin:admin' --insecure

        copy

        The response should look like this:

        1. name component version
        2. hostname opensearch-alerting 2.7.0
        3. hostname opensearch-anomaly-detection 2.7.0
        4. hostname opensearch-asynchronous-search 2.7.0
        5. hostname opensearch-cross-cluster-replication 2.7.0
        6. hostname opensearch-index-management 2.7.0
        7. hostname opensearch-job-scheduler 2.7.0
        8. hostname opensearch-knn 2.7.0
        9. hostname opensearch-ml 2.7.0
        10. hostname opensearch-notifications 2.7.0
        11. hostname opensearch-notifications-core 2.7.0
        12. hostname opensearch-observability 2.7.0
        13. hostname opensearch-performance-analyzer 2.7.0
        14. hostname opensearch-reports-scheduler 2.7.0
        15. hostname opensearch-security 2.7.0
        16. hostname opensearch-sql 2.7.0
    4. Return to the original terminal session and stop the process by pressing CTRL + C.

    Option 2: Test your OpenSearch settings with security disabled

    1. Open the configuration file.

      1. vi /path/to/opensearch-2.7.0/config/opensearch.yml

      copy

    2. Add the following line to disable the Security plugin:

      1. plugins.security.disabled: true

      copy

    3. Save the change and close the file.

    4. Open another terminal session and send requests to the server to verify that OpenSearch is running. Because the Security plugin has been disabled, you will be sending commands using HTTP rather than HTTPS.

      • Send a request to port 9200.

        1. curl -X GET http://localhost:9200

        copy

        You should get a response that looks like this:

        1. {
        2. "name" : "hostname",
        3. "cluster_name" : "opensearch",
        4. "cluster_uuid" : "6XNc9m2gTUSIoKDqJit0PA",
        5. "version" : {
        6. "distribution" : "opensearch",
        7. "number" : <version>,
        8. "build_type" : <build-type>,
        9. "build_hash" : <build-hash>,
        10. "build_date" : <build-date>,
        11. "build_snapshot" : false,
        12. "lucene_version" : <lucene-version>,
        13. "minimum_wire_compatibility_version" : "7.10.0",
        14. "minimum_index_compatibility_version" : "7.0.0"
        15. "tagline" : "The OpenSearch Project: https://opensearch.org/"
        16. }
      • Query the plugins endpoint.

        1. curl -X GET http://localhost:9200/_cat/plugins?v

        The response should look like this:

    Users who do not have prior experience with OpenSearch may want a list of recommended settings in order to get started with the service. By default, OpenSearch is not bound to a network interface and cannot be reached by external hosts. Additionally, security settings are either undefined (greenfield install) or populated by default usernames and passwords if you ran the security demo script by invoking opensearch-tar-install.sh. The following recommendations will enable a user to bind OpenSearch to a network interface, create and sign TLS certificates, and configure basic authentication.

    The following recommended settings will allow you to:

    • Bind OpenSearch to an IP or network interface on the host.
    • Set initial and maximum JVM heap sizes.
    • Define an environment variable that points to the bundled JDK.
    • Configure your own TLS certificates - no third-party certificate authority (CA) is required.
    • Create an admin user with a custom password.

    If you ran the security demo script, then you will need to manually reconfigure settings that were modified. Refer to for guidance before proceeding.

    Before modifying any configuration files, it’s always a good idea to save a backup copy before making changes. The backup file can be used to revert any issues caused by a bad configuration.

    1. Open opensearch.yml.

      1. vi /path/to/opensearch-2.7.0/config/opensearch.yml

      copy

    2. Add the following lines.

      1. # Bind OpenSearch to the correct network interface. Use 0.0.0.0
      2. # to include all available interfaces or specify an IP address
      3. # assigned to a specific interface.
      4. network.host: 0.0.0.0
      5. # discovery.type to single-node, or the bootstrap checks will
      6. # fail when you try to start the service.
      7. discovery.type: single-node
      8. # If you previously disabled the Security plugin in opensearch.yml,
      9. # be sure to re-enable it. Otherwise you can skip this setting.
      10. plugins.security.disabled: false

      copy

    3. Save your changes and close the file.

    4. Specify initial and maximum JVM heap sizes.

      1. Open jvm.options.

        1. vi /path/to/opensearch-2.7.0/config/jvm.options

        copy

      2. Modify the values for initial and maximum heap sizes. As a starting point, you should set these values to half of the available system memory. For dedicated hosts this value can be increased based on your workflow requirements.

        • As an example, if the host machine has 8 GB of memory then you might want to set the initial and maximum heap sizes to 4 GB:

          1. -Xms4g
          2. -Xmx4g

          copy

      3. Save your changes and close the file.

    5. Specify the location of the included JDK.

      1. export OPENSEARCH_JAVA_HOME=/path/to/opensearch-2.7.0/jdk

      copy

    TLS certificates provide additional security for your cluster by allowing clients to confirm the identity of hosts and encrypt traffic between the client and host. For more information, refer to and Generate Certificates, which are included in the documentation. For work performed in a development environment, self-signed certificates are usually adequate. This section will guide you through the basic steps required to generate your own TLS certificates and apply them to your OpenSearch host.

    1. Navigate to the OpenSearch config directory. This is where the certificates will be stored.

      1. cd /path/to/opensearch-2.7.0/config/

      copy

    2. Generate a root certificate. This is what you will use to sign your other certificates.

      1. # Create a private key for the root certificate
      2. openssl genrsa -out root-ca-key.pem 2048
      3. # Use the private key to create a self-signed root certificate. Be sure to
      4. # replace the arguments passed to -subj so they reflect your specific host.
      5. openssl req -new -x509 -sha256 -key root-ca-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=ROOT" -out root-ca.pem -days 730
    3. Next, create the admin certificate. This certificate is used to gain elevated rights for performing administrative tasks relating to the Security plugin.

      1. # Create a private key for the admin certificate.
      2. openssl genrsa -out admin-key-temp.pem 2048
      3. # Convert the private key to PKCS#8.
      4. openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem
      5. # Create the CSR. A common name (CN) of "A" is acceptable because this certificate is
      6. # used for authenticating elevated access and is not tied to a host.
      7. openssl req -new -key admin-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=A" -out admin.csr
      8. # Sign the admin certificate with the root certificate and private key you created earlier.
      9. openssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem -days 730
    4. Create a certificate for the node being configured.

      1. # Create a private key for the node certificate.
      2. openssl genrsa -out node1-key-temp.pem 2048
      3. # Convert the private key to PKCS#8.
      4. openssl pkcs8 -inform PEM -outform PEM -in node1-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out node1-key.pem
      5. # Create the CSR and replace the arguments passed to -subj so they reflect your specific host.
      6. # The CN should match a DNS A record for the host--do not use the hostname.
      7. openssl req -new -key node1-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=node1.dns.a-record" -out node1.csr
      8. # Create an extension file that defines a SAN DNS name for the host. This
      9. # should match the DNS A record of the host.
      10. echo 'subjectAltName=DNS:node1.dns.a-record' > node1.ext
      11. # Sign the node certificate with the root certificate and private key that you created earlier.
      12. openssl x509 -req -in node1.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out node1.pem -days 730 -extfile node1.ext
    5. Remove temporary files that are no longer required.

      1. rm *temp.pem *csr *ext

      copy

    6. Add these certificates to opensearch.yml as described in Generate Certificates. Advanced users might also choose to append the settings using a script:

      1. #! /bin/bash
      2. # Before running this script, make sure to replace the /path/to your OpenSearch directory,
      3. # and remember to replace the CN in the node's distinguished name with a real
      4. # DNS A record.
      5. echo "plugins.security.ssl.transport.pemcert_filepath: /path/to/opensearch-2.7.0/config/node1.pem" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      6. echo "plugins.security.ssl.transport.pemkey_filepath: /path/to/opensearch-2.7.0/config/node1-key.pem" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      7. echo "plugins.security.ssl.transport.pemtrustedcas_filepath: /path/to/opensearch-2.7.0/config/root-ca.pem" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      8. echo "plugins.security.ssl.http.enabled: true" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      9. echo "plugins.security.ssl.http.pemcert_filepath: /path/to/opensearch-2.7.0/config/node1.pem" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      10. echo "plugins.security.ssl.http.pemkey_filepath: /path/to/opensearch-2.7.0/config/node1-key.pem" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      11. echo "plugins.security.ssl.http.pemtrustedcas_filepath: /path/to/opensearch-2.7.0/config/root-ca.pem" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      12. echo "plugins.security.allow_default_init_securityindex: true" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      13. echo "plugins.security.authcz.admin_dn:" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      14. echo " - 'CN=A,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      15. echo "plugins.security.nodes_dn:" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      16. echo " - 'CN=node1.dns.a-record,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      17. echo "plugins.security.audit.type: internal_opensearch" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      18. echo "plugins.security.enable_snapshot_restore_privilege: true" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      19. echo "plugins.security.check_snapshot_restore_write_privileges: true" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml
      20. echo "plugins.security.restapi.roles_enabled: [\"all_access\", \"security_rest_api_access\"]" | sudo tee -a /path/to/opensearch-2.7.0/config/opensearch.yml

      copy

    7. (Optional) Add trust for the self-signed root certificate.

      1. # Copy the root certificate to the correct directory
      2. sudo cp /path/to/opensearch-2.7.0/config/root-ca.pem /etc/pki/ca-trust/source/anchors/
      3. # Add trust
      4. sudo update-ca-trust

    Configure a user

    Users are defined and authenticated by OpenSearch in a variety of ways. One method, which does not require additional backend infrastructure, is to manually configure users in internal_users.yml. See YAML files for more information about configuring users. The following steps explain how to remove all demo users except for the admin user and how to replace the admin default password using a script.

    1. Make the Security plugin scripts executable.

      1. chmod 755 /path/to/opensearch-2.7.0/plugins/opensearch-security/tools/*.sh

      copy

    2. Run hash.sh to generate a new password.

      • This script will fail if a path to the JDK has not been defined.

        1. $ ./hash.sh
        2. **************************************************************************
        3. ** This tool will be deprecated in the next major release of OpenSearch **
        4. ** https://github.com/opensearch-project/security/issues/1755 **
        5. **************************************************************************
        6. which: no java in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user/.local/bin:/home/user/bin)
        7. WARNING: nor OPENSEARCH_JAVA_HOME nor JAVA_HOME is set, will use
        8. ./hash.sh: line 35: java: command not found
      • Declare an environment variable when you invoke the script in order to avoid issues:

        copy

      • Enter the desired password at the prompt and make a note of the output hash.

    3. Open internal_users.yml.

      copy

    4. Remove all demo users except for admin and replace the hash with the output provided by hash.sh in a previous step. The file should look similar to the following example:

      1. ---
      2. # This is the internal user database
      3. # The hash value is a bcrypt hash and can be generated with plugin/tools/hash.sh
      4. _meta:
      5. type: "internalusers"
      6. config_version: 2
      7. # Define your internal users here
      8. admin:
      9. hash: "$2y$1EXAMPLEQqwS8TUcoEXAMPLEeZ3lEHvkEXAMPLERqjyh1icEXAMPLE."
      10. reserved: true
      11. backend_roles:
      12. - "admin"
      13. description: "Admin user"

      copy

    Now that TLS certificates are installed and demo users were removed or assigned new passwords, the last step is to apply the configuration changes. This last configuration step requires invoking securityadmin.sh while OpenSearch is running on the host.

    1. Start OpenSearch. It must be running for securityadmin.sh to apply changes.

      1. # Change directories
      2. cd /path/to/opensearch-2.7.0/bin
      3. # Run the service in the foreground
      4. ./opensearch
    2. Open a separate terminal session with the host and navigate to the directory containing securityadmin.sh.

      1. # Change to the correct directory
      2. cd /path/to/opensearch-2.7.0/plugins/opensearch-security/tools
    3. Invoke the script. See Apply changes using securityadmin.sh for definitions of the arguments you must pass.

      1. # You can omit the environment variable if you declared this in your $PATH.
      2. OPENSEARCH_JAVA_HOME=/path/to/opensearch-2.7.0/jdk ./securityadmin.sh -cd /path/to/opensearch-2.7.0/config/opensearch-security/ -cacert /path/to/opensearch-2.7.0/config/root-ca.pem -cert /path/to/opensearch-2.7.0/config/admin.pem -key /path/to/opensearch-2.7.0/config/admin-key.pem -icl -nhnv
    4. Stop and restart the running OpenSearch process to apply the changes.

    Verify that the service is running

    OpenSearch is now running on your host with custom TLS certificates and a secure user for basic authentication. You can verify external connectivity by sending an API request to your OpenSearch node from another host.

    During previous tests you directed requests to localhost. Now that TLS certificates have been applied and the new certificates reference your host’s actual DNS record, requests to localhost will fail the CN check and the certificate will be considered invalid. Instead, requests should be sent to the address you specified while generating the certificate.

    You should add trust for the root certificate to your client before sending requests. If you do not add trust, then you must use the -k option so that cURL ignores CN and root certificate validation.

    1. $ curl https://your.host.address:9200 -u admin:yournewpassword -k
    2. {
    3. "name" : "hostname-here",
    4. "cluster_name" : "opensearch",
    5. "cluster_uuid" : "efC0ANNMQlGQ5TbhNflVPg",
    6. "version" : {
    7. "distribution" : "opensearch",
    8. "number" : "2.1.0",
    9. "build_type" : "tar",
    10. "build_hash" : "388c80ad94529b1d9aad0a735c4740dce2932a32",
    11. "build_date" : "2022-06-30T21:31:04.823801692Z",
    12. "build_snapshot" : false,
    13. "lucene_version" : "9.2.0",
    14. "minimum_wire_compatibility_version" : "7.10.0",
    15. "minimum_index_compatibility_version" : "7.0.0"
    16. },
    17. "tagline" : "The OpenSearch Project: https://opensearch.org/"
    18. }

    This section will guide you through creating a service for OpenSearch and registering 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 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.

    1. Create a user for the OpenSearch service.

      1. sudo adduser --system --shell /bin/bash -U --no-create-home opensearch

      copy

    2. Add your user to the opensearch user group.

      1. sudo usermod -aG opensearch $USER

      copy

    3. Change the file owner to opensearch. Make sure to change the path if your OpenSearch files are in a different directory.

      1. sudo chown -R opensearch /opt/opensearch/

      copy

    4. Create the service file and open it for editing.

      1. sudo vi /etc/systemd/system/opensearch.service

      copy

    5. Enter the following example service configuration. Make sure to change references to the path if your OpenSearch files are in a different directory.

      1. [Unit]
      2. Description=OpenSearch
      3. Wants=network-online.target
      4. After=network-online.target
      5. [Service]
      6. Type=forking
      7. RuntimeDirectory=data
      8. WorkingDirectory=/opt/opensearch
      9. ExecStart=/opt/opensearch/bin/opensearch -d
      10. User=opensearch
      11. Group=opensearch
      12. StandardOutput=journal
      13. StandardError=inherit
      14. LimitNOFILE=65535
      15. LimitNPROC=4096
      16. LimitAS=infinity
      17. LimitFSIZE=infinity
      18. TimeoutStopSec=0
      19. KillSignal=SIGTERM
      20. KillMode=process
      21. SendSIGKILL=no
      22. SuccessExitStatus=143
      23. TimeoutStartSec=75
      24. [Install]
      25. WantedBy=multi-user.target

      copy

    6. Reload systemd manager configuration.

      1. sudo systemctl daemon-reload

      copy

    7. Enable the OpenSearch service.

      1. sudo systemctl enable opensearch.service

      copy

    8. Start the OpenSearch service.

      copy

    9. Verify that the service is running.

      copy