RPM
与 Tarball 方法相比,使用 RPM 包管理器 (RPM) 安装 OpenSearch 极大地简化了过程。软件包管理器会自动处理多项技术考量,例如安装路径、配置文件位置以及由 systemd
管理的服务的创建等。
一般来说,从 RPM 分发包安装 OpenSearch 可以分为几个步骤
- 下载并安装 OpenSearch。
- 从 RPM 包或 YUM 仓库手动安装。
- (可选)测试 OpenSearch。
- 在应用任何自定义配置之前,确认 OpenSearch 能够运行。
- 这可以在没有任何安全设置(无密码、无证书)的情况下完成,或者使用一个可以通过打包脚本应用的演示安全配置来完成。
- 为您的环境配置 OpenSearch。
- 将基本设置应用于 OpenSearch,并在您的环境中开始使用它。
RPM 分发包提供了在 Red Hat 或基于 Red Hat 的 Linux 发行版中运行 OpenSearch 所需的一切。有关支持的操作系统的列表,请参阅操作系统兼容性。
本指南假定您熟悉使用 Linux 命令行界面 (CLI)。您应该了解如何输入命令、在目录之间导航以及编辑文本文件。某些示例命令引用了 vi
文本编辑器,但您可以使用任何可用的文本编辑器。
步骤 1:下载并安装 OpenSearch
从软件包安装 OpenSearch
- 直接从 OpenSearch 下载页面下载所需版本的 RPM 包。RPM 包可用于 x64 和 arm64 架构。
-
导入公共 GNU Privacy Guard (GPG) 密钥。此密钥用于验证您的 OpenSearch 实例是否已签名。
sudo rpm --import https://artifacts.opensearch.org/publickeys/opensearch-release.pgp
-
在 CLI 中,您可以使用
rpm
或yum
安装软件包# 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: ## Install the x64 package using yum. sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> yum install opensearch-3.1.0-linux-x64.rpm ## Install the x64 package using rpm. sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> rpm -ivh opensearch-3.1.0-linux-x64.rpm ## Install the arm64 package using yum. sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> yum install opensearch-3.1.0-linux-arm64.rpm ## Install the arm64 package using rpm. sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> rpm -ivh opensearch-3.1.0-linux-arm64.rpm # Use the following command for OpenSearch versions 2.11 and earlier: ## Install the x64 package using yum. sudo yum install opensearch-3.1.0-linux-x64.rpm ## Install the x64 package using rpm. sudo rpm -ivh opensearch-3.1.0-linux-x64.rpm ## Install the arm64 package using yum. sudo yum install opensearch-3.1.0-linux-arm64.rpm ## Install the arm64 package using rpm. sudo rpm -ivh opensearch-3.1.0-linux-arm64.rpm
-
安装成功后,将 OpenSearch 启用为服务。
sudo systemctl enable opensearch
-
启动 OpenSearch。
sudo systemctl start opensearch
-
验证 OpenSearch 是否正确启动
sudo systemctl status opensearch
从 YUM 仓库安装 OpenSearch
YUM 是基于 Red Hat 的操作系统的主要软件包管理工具,它允许您从 YUM 仓库下载并安装 RPM 软件包。
- 为 OpenSearch 创建本地仓库文件
sudo curl -SL https://artifacts.opensearch.org/releases/bundle/opensearch/3.x/opensearch-3.x.repo -o /etc/yum.repos.d/opensearch-3.x.repo
- 清除 YUM 缓存以确保顺利安装
sudo yum clean all
- 验证仓库是否成功创建。
sudo yum repolist
- 下载仓库文件后,列出所有可用的 OpenSearch 版本
sudo yum list opensearch --showduplicates
- 选择您要安装的 OpenSearch 版本:
- 除非另有说明,否则将安装 OpenSearch 的最新可用版本。
# For OpenSearch versions 2.12 and later, a custom admin password is required in order to set up a demo security configuration for a new installation. # To set a custom admin password, use the following commands: sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> yum install opensearch # Use the following command for OpenSearch versions 2.11 and earlier: sudo yum install opensearch
- 要安装特定版本的 OpenSearch
# For OpenSearch versions 2.12 and later, a custom admin password is required in order to set up a demo security configuration for a new installation. # To set a custom admin password, use the following commands: sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> yum install 'opensearch-3.1.0' # Use the following command for OpenSearch versions 2.11 and earlier: sudo yum install 'opensearch-3.1.0'
- 在安装过程中,安装程序将显示 GPG 密钥指纹。验证信息是否与以下内容匹配:
Fingerprint: c5b7 4989 65ef d1c2 924b a9d5 39d3 1987 9310 d3fc
- 如果正确,请输入
yes
或y
。OpenSearch 安装将继续。
- 如果正确,请输入
- 完成后,您可以运行 OpenSearch。
sudo systemctl start opensearch
- 验证 OpenSearch 是否正确启动。
sudo systemctl status opensearch
步骤 2:(可选)测试 OpenSearch
在进行任何配置之前,您应该测试 OpenSearch 的安装。否则,很难确定未来出现的问题是由于安装问题还是您在安装后应用的自定义设置造成的。
使用 RPM 软件包安装 OpenSearch 时,会自动应用一些演示安全设置。这包括自签名 TLS 证书以及多个用户和角色。如果您想自行配置这些,请参阅在您的环境中设置 OpenSearch。
默认配置的 OpenSearch 节点(带演示证书和使用默认密码的用户)不适用于生产环境。如果您计划在生产环境中使用该节点,则至少应将演示 TLS 证书替换为自己的 TLS 证书,并更新内部用户和密码列表。有关确保节点根据您的安全要求进行配置的其他指南,请参阅安全配置。
- 向服务器发送请求以验证 OpenSearch 是否正在运行。请注意使用
--insecure
标志,这是必需的,因为 TLS 证书是自签名的。- 向端口 9200 发送请求
curl -X GET https://:9200 -u 'admin:<custom-admin-password>' --insecure
您应该会收到如下响应:
{ "name" : "hostname", "cluster_name" : "opensearch", "cluster_uuid" : "6XNc9m2gTUSIoKDqJit0PA", "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-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-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-sql 3.1.0
- 向端口 9200 发送请求
步骤 3:在您的环境中设置 OpenSearch
没有 OpenSearch 使用经验的用户可能需要一份推荐设置列表才能开始使用该服务。默认情况下,OpenSearch 不绑定到网络接口,也无法由外部主机访问。此外,安全设置由默认用户名和密码填充。以下建议将使用户能够将 OpenSearch 绑定到网络接口、创建和签名 TLS 证书以及配置基本身份验证。
以下推荐设置将允许您:
- 将 OpenSearch 绑定到主机上的 IP 或网络接口。
- 设置初始和最大 JVM 堆大小。
- 定义一个指向捆绑 JDK 的环境变量。
- 配置您自己的 TLS 证书——无需第三方证书颁发机构 (CA)。
- 创建具有自定义密码的管理员用户。
如果您运行了安全演示脚本,则需要手动重新配置已修改的设置。在继续之前,请参阅安全配置以获取指导。
在修改任何配置文件之前,最好先保存一份备份副本。备份文件可用于缓解因错误配置引起的任何问题。
- 打开
opensearch.yml
。sudo vi /etc/opensearch/opensearch.yml
- 添加以下行:
# 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
- 保存更改并关闭文件。
- 指定初始和最大 JVM 堆大小。
- 打开
jvm.options
。vi /etc/opensearch/jvm.options
- 修改初始和最大堆大小的值。作为起点,您应该将这些值设置为可用系统内存的一半。对于专用主机,此值可以根据您的工作流要求增加。
- 例如,如果主机有 8 GB 内存,则您可能希望将初始和最大堆大小设置为 4 GB:
-Xms4g -Xmx4g
- 例如,如果主机有 8 GB 内存,则您可能希望将初始和最大堆大小设置为 4 GB:
- 保存更改并关闭文件。
- 打开
配置 TLS
TLS 证书通过允许客户端确认主机的身份并加密客户端和主机之间的流量,为您的集群提供额外的安全性。有关更多信息,请参阅配置 TLS 证书和生成证书,这些内容包含在安全插件文档中。对于在开发环境中进行的工作,自签名证书通常就足够了。本节将指导您完成生成自己的 TLS 证书并将其应用于 OpenSearch 主机所需的基本步骤。
- 导航到将存储证书的目录。
cd /etc/opensearch
- 删除演示证书。
sudo rm -f *pem
- 生成根证书。您将使用此证书来签署其他证书。
# 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
- 接下来,创建管理员证书。此证书用于获取提升的权限,以执行与安全插件相关的管理任务。
# 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
- 为正在配置的节点创建证书。
# 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
- 删除不再需要的临时文件。
sudo rm -f *temp.pem *csr *ext
- 确保剩余的证书由 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
- 按照生成证书中的说明,将这些证书添加到
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
- (可选)为自签名根证书添加信任。
# 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
用户之外的所有演示用户,以及如何使用脚本替换 admin
默认密码。
- 导航到安全插件工具目录。
cd /usr/share/opensearch/plugins/opensearch-security/tools
- 运行
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
- 在提示符处输入所需密码,并记下输出的哈希值。
- 如果未定义 JDK 路径,此脚本将失败。
- 打开
internal_users.yml
。sudo vi /etc/opensearch/opensearch-security/internal_users.yml
- 删除除
admin
之外的所有演示用户,并将哈希值替换为上一步中由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"
应用更改
现在 TLS 证书已安装,演示用户已删除或分配了新密码,最后一步是应用配置更改。这最后一个配置步骤需要在 OpenSearch 在主机上运行时调用 securityadmin.sh
。
- OpenSearch 必须运行,
securityadmin.sh
才能应用更改。如果您修改了opensearch.yml
,请重新启动 OpenSearch。sudo systemctl restart opensearch
- 打开一个单独的主机终端会话,并导航到包含
securityadmin.sh
的目录。# Change to the correct directory cd /usr/share/opensearch/plugins/opensearch-security/tools
- 调用脚本。有关您必须传递的参数的定义,请参阅使用 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-here",
"cluster_name" : "opensearch",
"cluster_uuid" : "efC0ANNMQlGQ5TbhNflVPg",
"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/"
}
升级到新版本
使用 RPM 或 YUM 安装的 OpenSearch 实例可以轻松升级到新版本。我们推荐使用 YUM 进行更新,但您也可以使用 RPM 进行升级。
使用 RPM 手动升级
直接从 OpenSearch 项目下载页面下载所需升级版本的 RPM 包。
导航到包含发行版的目录并运行以下命令:
rpm -Uvh opensearch-3.1.0-linux-x64.rpm
YUM
要使用 YUM 升级到最新版本的 OpenSearch
sudo yum update opensearch
您也可以升级到特定的 OpenSearch 版本
sudo yum update opensearch-<version-number>
软件包升级后自动重启服务
OpenSearch RPM 软件包目前不支持在软件包升级后自动重启服务。