Link Search Menu Expand Document Documentation Menu

Debian

Tarball 方法相比,使用高级打包工具 (APT) 包管理器安装 OpenSearch 显著简化了过程。一些技术考量,例如安装路径、配置文件位置以及由 systemd 管理服务的创建等,都由包管理器自动处理。

一般来说,从 Debian 发行版安装 OpenSearch 可以分解为几个步骤:

  1. 下载并安装 OpenSearch。
    • 从 Debian 包或 APT 仓库手动安装。
  2. (可选)测试 OpenSearch。
    • 在应用任何自定义配置之前,确认 OpenSearch 能够运行。
    • 这可以在没有任何安全设置(无密码、无证书)的情况下完成,或者使用一个可以通过打包脚本应用的演示安全配置来完成。
  3. 为您的环境配置 OpenSearch。
    • 将基本设置应用于 OpenSearch,并在您的环境中开始使用它。

Debian 发行版提供了在基于 Debian 的 Linux 发行版(如 Ubuntu)中运行 OpenSearch 所需的一切。

本指南假设您熟悉 Linux 命令行界面 (CLI) 操作。您应该了解如何输入命令、在目录之间导航以及编辑文本文件。某些示例命令引用了 vi 文本编辑器,但您可以使用任何可用的文本编辑器。

步骤 1:下载并安装 OpenSearch

从包安装 OpenSearch

  1. 直接从 OpenSearch 下载页面下载所需版本的 Debian 包。Debian 包可用于 x64arm64 架构。
  2. 从 CLI,使用 dpkg 安装包:

    对于 OpenSearch 2.12 及更高版本的新安装,您必须定义一个自定义管理员密码才能设置演示安全配置。使用以下命令之一定义自定义管理员密码:

    # x64
    sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> dpkg -i opensearch-3.1.0-linux-x64.deb
       
    # arm64
    sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> dpkg -i opensearch-3.1.0-linux-arm64.deb
    

    对于 OpenSearch 2.11 及更早版本,请使用以下命令:

    # x64
    sudo dpkg -i opensearch-3.1.0-linux-x64.deb
       
    # arm64
    sudo dpkg -i opensearch-3.1.0-linux-arm64.deb
    
  3. 安装成功后,将 OpenSearch 启用为服务。
     sudo systemctl enable opensearch
    

  4. 启动 OpenSearch 服务。
     sudo systemctl start opensearch
    

  5. 验证 OpenSearch 是否正确启动。
     sudo systemctl status opensearch
    

指纹验证

Debian 包未签名。如果您想验证指纹,OpenSearch 项目提供了 .sig 文件和 .deb 包以供 GNU Privacy Guard (GPG) 使用。

  1. 下载所需的 Debian 包。
    curl -SLO https://artifacts.opensearch.org/releases/bundle/opensearch/3.1.0/opensearch-3.1.0-linux-x64.deb
    

  2. 下载对应的签名文件。
    curl -SLO https://artifacts.opensearch.org/releases/bundle/opensearch/3.1.0/opensearch-3.1.0-linux-x64.deb.sig
    

  3. 下载并导入 GPG 密钥。
    curl -o- https://artifacts.opensearch.org/publickeys/opensearch-release.pgp | gpg --import -
    

  4. 验证签名。
    gpg --verify opensearch-3.1.0-linux-x64.deb.sig opensearch-3.1.0-linux-x64.deb
    

从 APT 仓库安装 OpenSearch

APT 是基于 Debian 的操作系统主要的包管理工具,它允许您从 APT 仓库下载并安装 Debian 包。

  1. 安装必要的包。
    sudo apt-get update && sudo apt-get -y install lsb-release ca-certificates curl gnupg2
    

  2. 导入公共 GPG 密钥。此密钥用于验证 APT 仓库是否已签名。
     curl -o- https://artifacts.opensearch.org/publickeys/opensearch-release.pgp | sudo gpg --dearmor --batch --yes -o /usr/share/keyrings/opensearch-release-keyring
    

  3. 为 OpenSearch 创建 APT 仓库
    echo "deb [signed-by=/usr/share/keyrings/opensearch-release-keyring] https://artifacts.opensearch.org/releases/bundle/opensearch/3.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch-3.x.list
    

  4. 验证仓库是否成功创建。
     sudo apt-get update
    

  5. 添加仓库信息后,列出 OpenSearch 的所有可用版本:
    sudo apt list -a opensearch
    

  6. 选择您要安装的 OpenSearch 版本:
    • 除非另有说明,否则将安装 OpenSearch 的最新可用版本。
    # 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.
    # Use one of the following commands to define a custom admin password:
    sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> apt-get install opensearch
    
    # Use the following command for OpenSearch versions 2.11 and earlier:
    sudo apt-get install opensearch
    

    • 要安装特定版本的 OpenSearch:
    # Specify the version manually using opensearch=<version>
    
    # 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.
    # Use one of the following commands to define a custom admin password:
    sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> apt-get install opensearch=3.1.0
    
    # Use the following command for OpenSearch versions 2.11 and earlier:
    sudo apt-get install opensearch=3.1.0
    
  7. 在安装过程中,安装程序将显示 GPG 密钥指纹。验证信息是否与以下内容匹配:
    Fingerprint: c5b7 4989 65ef d1c2 924b a9d5 39d3 1987 9310 d3fc
    

  8. 完成后,启用 OpenSearch。
     sudo systemctl enable opensearch
    

  9. 启动 OpenSearch。
     sudo systemctl start opensearch
    

  10. 验证 OpenSearch 是否正确启动。
     sudo systemctl status opensearch
    

步骤 2:(可选)测试 OpenSearch

在进行任何配置之前,您应该测试您的 OpenSearch 安装。否则,很难确定未来的问题是由于安装问题还是您在安装后应用的自定义设置造成的。

使用 Debian 包安装 OpenSearch 时,会自动应用一些演示安全设置。这包括自签名 TLS 证书以及一些用户和角色。如果您想自行配置这些,请参阅在您的环境中设置 OpenSearch

默认配置(带有演示证书和默认密码用户)的 OpenSearch 节点不适用于生产环境。如果您计划在生产环境中使用该节点,您至少应将演示 TLS 证书替换为自己的 TLS 证书,并更新内部用户和密码列表。有关确保您的节点根据安全要求进行配置的更多指导,请参阅安全配置

  1. 向服务器发送请求以验证 OpenSearch 是否正在运行。请注意使用 --insecure 标志,这是必需的,因为 TLS 证书是自签名的。
    • 向端口 9200 发送请求
       curl -X GET https://:9200 -u 'admin:<custom-admin-password>' --insecure
      

      您应该会收到如下响应:

       {
          "name":"hostname",
          "cluster_name":"opensearch",
          "cluster_uuid":"QqgpHCbnSRKcPAizqjvoOw",
          "version":{
             "distribution":"opensearch",
             "number":<version>,
             "build_type":<build-type>,
             "build_hash":<build-hash>,
             "build_date":<build-date>,
             "build_snapshot":false,
             "lucene_version":<lucene-version>,
             "minimum_wire_compatibility_version":"7.10.0",
             "minimum_index_compatibility_version":"7.0.0"
          },
          "tagline":"The OpenSearch Project: https://opensearch.org.cn/"
       }
      
    • 查询插件端点
       curl -X GET https://:9200/_cat/plugins?v -u 'admin:<custom-admin-password>' --insecure
      

    响应应如下所示:

     name          component                            version
     hostname      opensearch-alerting                  3.1.0
     hostname      opensearch-anomaly-detection         3.1.0
     hostname      opensearch-asynchronous-search       3.1.0
     hostname      opensearch-cross-cluster-replication 3.1.0
     hostname      opensearch-geospatial                3.1.0
     hostname      opensearch-index-management          3.1.0
     hostname      opensearch-job-scheduler             3.1.0
     hostname      opensearch-knn                       3.1.0
     hostname      opensearch-ml                        3.1.0
     hostname      opensearch-neural-search             3.1.0
     hostname      opensearch-notifications             3.1.0
     hostname      opensearch-notifications-core        3.1.0
     hostname      opensearch-observability             3.1.0
     hostname      opensearch-performance-analyzer      3.1.0
     hostname      opensearch-reports-scheduler         3.1.0
     hostname      opensearch-security                  3.1.0
     hostname      opensearch-security-analytics        3.1.0
     hostname      opensearch-sql                       3.1.0
    

步骤 3:在您的环境中设置 OpenSearch

没有 OpenSearch 使用经验的用户可能需要一份推荐设置列表,以便开始使用该服务。默认情况下,OpenSearch 不绑定到网络接口,外部主机无法访问。此外,安全设置由默认用户名和密码填充。以下建议将使用户能够将 OpenSearch 绑定到网络接口,创建和签名 TLS 证书,并配置基本身份验证。

以下推荐设置将允许您:

  • 将 OpenSearch 绑定到主机上的 IP 或网络接口。
  • 设置初始和最大 JVM 堆大小。
  • 定义一个指向捆绑 JDK 的环境变量。
  • 配置您自己的 TLS 证书——无需第三方证书颁发机构 (CA)。
  • 创建具有自定义密码的管理员用户。

如果您运行了安全演示脚本,则需要手动重新配置已修改的设置。在继续之前,请参阅安全配置以获取指导。

在修改任何配置文件之前,最好先保存备份副本,以防配置错误导致问题。

  1. 打开 opensearch.yml
    sudo vi /etc/opensearch/opensearch.yml
    

  2. 添加以下行:
    # Bind OpenSearch to the correct network interface. Use 0.0.0.0
    # to include all available interfaces or specify an IP address
    # assigned to a specific interface.
    network.host: 0.0.0.0
    
    # Unless you have already configured a cluster, you should set
    # discovery.type to single-node, or the bootstrap checks will
    # fail when you try to start the service.
    discovery.type: single-node
    
    # If you previously disabled the Security plugin in opensearch.yml,
    # be sure to re-enable it. Otherwise you can skip this setting.
    plugins.security.disabled: false
    

  3. 保存更改并关闭文件。
  4. 指定初始和最大 JVM 堆大小。
    1. 打开 jvm.options
        vi /etc/opensearch/jvm.options
      

    2. 修改初始和最大堆大小的值。作为起点,您应该将这些值设置为可用系统内存的一半。对于专用主机,此值可以根据您的工作流要求增加。
      • 例如,如果主机有 8 GB 内存,则您可能希望将初始和最大堆大小设置为 4 GB:
        -Xms4g
        -Xmx4g
        

    3. 保存更改并关闭文件。

配置 TLS

TLS 证书通过允许客户端确认主机的身份并加密客户端和主机之间的流量,为您的集群提供额外的安全保障。有关更多信息,请参阅配置 TLS 证书生成证书,这些都包含在安全插件文档中。在开发环境中执行的工作,自签名证书通常就足够了。本节将指导您完成生成自己的 TLS 证书并将其应用于 OpenSearch 主机所需的基本步骤。

  1. 导航到将存储证书的目录。
    cd /etc/opensearch
    

  2. 删除演示证书。
    sudo rm -f *pem
    

  3. 生成根证书。您将使用此证书来签署其他证书。
    # Create a private key for the root certificate
    sudo openssl genrsa -out root-ca-key.pem 2048
       
    # Use the private key to create a self-signed root certificate. Be sure to
    # replace the arguments passed to -subj so they reflect your specific host.
    sudo 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
    
  4. 接下来,创建管理员证书。此证书用于获取提升的权限,以执行与安全插件相关的管理任务。
    # Create a private key for the admin certificate.
    sudo openssl genrsa -out admin-key-temp.pem 2048
    
    # Convert the private key to PKCS#8.
    sudo openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem
       
    # Create the certficiate signing request (CSR). A common name (CN) of "A" is acceptable because this certificate is
    # used for authenticating elevated access and is not tied to a host.
    sudo openssl req -new -key admin-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=A" -out admin.csr
       
    # Sign the admin certificate with the root certificate and private key you created earlier.
    sudo openssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem -days 730
    
  5. 为正在配置的节点创建证书。
    # Create a private key for the node certificate.
    sudo openssl genrsa -out node1-key-temp.pem 2048
       
    # Convert the private key to PKCS#8.
    sudo openssl pkcs8 -inform PEM -outform PEM -in node1-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out node1-key.pem
    
    # Create the CSR and replace the arguments passed to -subj so they reflect your specific host.
    # The CN should match a DNS A record for the host-do not use the hostname.
    sudo 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
       
    # Create an extension file that defines a SAN DNS name for the host. This
    # should match the DNS A record of the host.
    sudo sh -c 'echo subjectAltName=DNS:node1.dns.a-record > node1.ext'
       
    # Sign the node certificate with the root certificate and private key that you created earlier.
    sudo 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
    
  6. 删除不再需要的临时文件。
    sudo rm -f *temp.pem *csr *ext
    

  7. 确保其余证书由 opensearch 用户拥有。
    sudo chown opensearch:opensearch admin-key.pem admin.pem node1-key.pem node1.pem root-ca-key.pem root-ca.pem root-ca.srl
    

  8. 生成证书中所述,将这些证书添加到 opensearch.yml 中。高级用户也可以选择使用脚本附加设置:
    #! /bin/bash
    
    # Before running this script, make sure to replace the CN in the 
    # node's distinguished name with a real DNS A record.
    
    echo "plugins.security.ssl.transport.pemcert_filepath: /etc/opensearch/node1.pem" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.ssl.transport.pemkey_filepath: /etc/opensearch/node1-key.pem" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.ssl.transport.pemtrustedcas_filepath: /etc/opensearch/root-ca.pem" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.ssl.http.enabled: true" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.ssl.http.pemcert_filepath: /etc/opensearch/node1.pem" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.ssl.http.pemkey_filepath: /etc/opensearch/node1-key.pem" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.ssl.http.pemtrustedcas_filepath: /etc/opensearch/root-ca.pem" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.allow_default_init_securityindex: true" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.authcz.admin_dn:" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "  - 'CN=A,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.nodes_dn:" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "  - 'CN=node1.dns.a-record,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.audit.type: internal_opensearch" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.enable_snapshot_restore_privilege: true" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.check_snapshot_restore_write_privileges: true" | sudo tee -a /etc/opensearch/opensearch.yml
    echo "plugins.security.restapi.roles_enabled: [\"all_access\", \"security_rest_api_access\"]" | sudo tee -a /etc/opensearch/opensearch.yml
    

  9. (可选)为自签名根证书添加信任。
    # Copy the root certificate to the correct directory
    sudo cp /etc/opensearch/root-ca.pem /etc/pki/ca-trust/source/anchors/
       
    # Add trust
    sudo update-ca-trust
    

配置用户

OpenSearch 以多种方式定义和验证用户。一种不需要额外后端基础设施的方法是手动配置 internal_users.yml 中的用户。有关配置用户的更多信息,请参阅YAML 文件。以下步骤解释了如何添加新的内部用户以及如何使用脚本替换 admin 默认密码。

  1. 导航到安全插件工具目录。
    cd /usr/share/opensearch/plugins/opensearch-security/tools
    

  2. 运行hash.sh以生成新密码。
    • 如果未定义 JDK 路径,此脚本将失败。
       # Example output if a JDK isn't found...
       $ ./hash.sh
       **************************************************************************
       ** This tool will be deprecated in the next major release of OpenSearch **
       ** https://github.com/opensearch-project/security/issues/1755           **
       **************************************************************************
       which: no java in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user/.local/bin:/home/user/bin)
       WARNING: nor OPENSEARCH_JAVA_HOME nor JAVA_HOME is set, will use 
       ./hash.sh: line 35: java: command not found
      

    • 在调用脚本时声明环境变量,以避免问题。
       OPENSEARCH_JAVA_HOME=/usr/share/opensearch/jdk ./hash.sh
      

    • 在提示符处输入所需密码,并记下输出的哈希值。
  3. 打开internal_users.yml
    sudo vi /etc/opensearch/opensearch-security/internal_users.yml
    

  4. 添加新的内部用户,并将 internal_users.yml 中的哈希替换为步骤 2 中 hash.sh 提供的输出。该文件应类似于以下示例:
    ---
    # This is the internal user database
    # The hash value is a bcrypt hash and can be generated with plugin/tools/hash.sh
    
    _meta:
       type: "internalusers"
       config_version: 2
    
    # Define your internal users here
    
    admin:
       hash: "$2y$1EXAMPLEQqwS8TUcoEXAMPLEeZ3lEHvkEXAMPLERqjyh1icEXAMPLE."
       reserved: true
       backend_roles:
       - "admin"
       description: "Admin user"
    
    user1:
       hash: "$2y$12$zoHpvTCRjjQr6h0PEaabueCaGam3/LDvT6rZZGDGMusD7oehQjw/O"
       reserved: false
       backend_roles: []
       description: "New internal user"
    
    # Other users 
    ...
    

应用更改

现在 TLS 证书已安装,演示用户已被删除或分配了新密码,最后一步是应用配置更改。这最后一个配置步骤需要在 OpenSearch 在主机上运行时调用 securityadmin.sh

  1. OpenSearch 必须正在运行,securityadmin.sh 才能应用更改。如果您对 opensearch.yml 进行了更改,请重新启动 OpenSearch。
    sudo systemctl restart opensearch
    

  2. 打开一个单独的主机终端会话,并导航到包含securityadmin.sh的目录。
    # Change to the correct directory
    cd /usr/share/opensearch/plugins/opensearch-security/tools
    
  3. 调用脚本。有关您必须传递的参数的定义,请参阅使用 securityadmin.sh 应用更改
    # You can omit the environment variable if you declared this in your $PATH.
    OPENSEARCH_JAVA_HOME=/usr/share/opensearch/jdk ./securityadmin.sh -cd /etc/opensearch/opensearch-security/ -cacert /etc/opensearch/root-ca.pem -cert /etc/opensearch/admin.pem -key /etc/opensearch/admin-key.pem -icl -nhnv
    

验证服务是否正在运行

OpenSearch 现在已在您的主机上运行,并带有自定义 TLS 证书和用于基本身份验证的安全用户。您可以通过从另一台主机向 OpenSearch 节点发送 API 请求来验证外部连接。

在之前的测试中,您将请求定向到 localhost。现在 TLS 证书已应用,新证书引用了您主机的实际 DNS 记录,对 localhost 的请求将无法通过 CN 检查,并且证书将被视为无效。相反,请求应发送到您在生成证书时指定的地址。

在发送请求之前,您应该为您的客户端添加对根证书的信任。如果您不添加信任,则必须使用 -k 选项,以便 cURL 忽略 CN 和根证书验证。

$ curl https://your.host.address:9200 -u admin:yournewpassword -k
{
   "name":"hostname",
   "cluster_name":"opensearch",
   "cluster_uuid":"QqgpHCbnSRKcPAizqjvoOw",
   "version":{
      "distribution":"opensearch",
      "number":<version>,
      "build_type":<build-type>,
      "build_hash":<build-hash>,
      "build_date":<build-date>,
      "build_snapshot":false,
      "lucene_version":<lucene-version>,
      "minimum_wire_compatibility_version":"7.10.0",
      "minimum_index_compatibility_version":"7.0.0"
   },
   "tagline":"The OpenSearch Project: https://opensearch.org.cn/"
}

升级到新版本

使用 dpkgapt-get 安装的 OpenSearch 实例可以轻松升级到新版本。

使用 DPKG 手动升级

直接从 OpenSearch 项目下载页面下载所需升级版本的 Debian 包。

导航到包含发行版的目录并运行以下命令:

sudo dpkg -i opensearch-3.1.0-linux-x64.deb

APT-GET

要使用 apt-get 升级到 OpenSearch 的最新版本:

sudo apt-get upgrade opensearch

您也可以升级到特定的 OpenSearch 版本:

sudo apt-get upgrade opensearch=<version>

包升级后自动重启服务 (2.13.0+)

要在包升级后自动重启 OpenSearch,请通过 systemd 启用 opensearch.service

sudo systemctl enable opensearch.service