OpenSearch 是一项强大的开源搜索引擎技术,允许用户创建和实施自定义搜索解决方案。该项目最初由 Elasticsearch 开发,由社区驱动,非常适合处理大型数据集、实时数据分析或构建自定义搜索应用程序。其可扩展性、灵活性以及以社区为中心的开发模式使其成为各行各业的必备工具。
本指南将向您展示如何在 Ubuntu 24 上安装OpenSearch ,并针对强大的电子商务平台的最新版本Magento 2.4.7进行了优化。
步骤 1:添加 OpenSearch 存储库
由于 OpenSearch 在 Ubuntu 24 的默认存储库中不可用,因此第一步是将 OpenSearch 存储库添加到您的系统中。
首先,安装必要的依赖项:
apt -y install curl lsb-release gnupg2 ca-certificates
然后,导入对 OpenSearch 包进行签名所需的 GPG 密钥:
curl -fsSL https://artifacts.opensearch.org/publickeys/opensearch.pgp | gpg --dearmor -o /etc/apt/trusted.gpg.d/opensearch.gpg
将 OpenSearch 存储库添加到您的源列表:
echo“deb https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main”| tee /etc/apt/sources.list.d/opensearch-2.x.list
更新软件包列表以反映更改:
apt update -y
步骤 2:安装和配置 OpenSearch
要在安装期间为 OpenSearch 设置初始管理员密码,请使用以下命令。将“Y0ur@SecurP4assword”替换为你选择的安全密码:
env OPENSEARCH_INITIAL_ADMIN_PASSWORD=Y0ur@SecurP4assword apt install opensearch
安装完成后,您需要调整配置文件以符合您的 Magento 商店要求。打开配置文件:
nano /etc/opensearch/opensearch.yml
根据您的需要修改这些设置:
cluster.name: magento2 network.host: localhost http.port: 9200 plugins.security.disabled: false plugins.security.ssl.http.enabled: false
安装成功后,启用OpenSearch作为服务。
root@lavm-od61ss3meu:~# sudo systemctl enable opensearch
Synchronizing state of opensearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable opensearch
Created symlink /etc/systemd/system/multi-user.target.wants/opensearch.service → /lib/systemd/system/opensearch.service.
启动 OpenSearch 服务。
root@lavm-od61ss3meu:~# sudo systemctl start opensearch
验证 OpenSearch 是否正确启动。
root@lavm-od61ss3meu:~# sudo systemctl status opensearch
● opensearch.service - OpenSearch
Loaded: loaded (/lib/systemd/system/opensearch.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2025-08-18 18:18:21 CST; 5min ago
Docs: https://opensearch.org/
Main PID: 3655956 (java)
Tasks: 81 (limit: 9403)
Memory: 773.4M
CPU: 57.913s
CGroup: /system.slice/opensearch.service
└─3655956 /usr/share/opensearch/jdk/bin/java -Xshare:auto -Dopensearch.networkaddress.cache.ttl=60 -Dopensearch.networkaddress.cache.negative.tt>
Aug 18 18:17:58 lavm-od61ss3meu systemd-entrypoint[3655956]: WARNING: System::setSecurityManager has been called by org.opensearch.bootstrap.OpenSearch (file>
Aug 18 18:17:58 lavm-od61ss3meu systemd-entrypoint[3655956]: WARNING: Please consider reporting this to the maintainers of org.opensearch.bootstrap.OpenSearch
Aug 18 18:17:58 lavm-od61ss3meu systemd-entrypoint[3655956]: WARNING: System::setSecurityManager will be removed in a future release
Aug 18 18:17:58 lavm-od61ss3meu systemd-entrypoint[3655956]: Aug 18, 2025 6:17:58 PM sun.util.locale.provider.LocaleProviderAdapter <clinit>
Aug 18 18:17:58 lavm-od61ss3meu systemd-entrypoint[3655956]: WARNING: COMPAT locale provider will be removed in a future release
Aug 18 18:17:59 lavm-od61ss3meu systemd-entrypoint[3655956]: WARNING: A terminally deprecated method in java.lang.System has been called
Aug 18 18:17:59 lavm-od61ss3meu systemd-entrypoint[3655956]: WARNING: System::setSecurityManager has been called by org.opensearch.bootstrap.Security (file:/>
Aug 18 18:17:59 lavm-od61ss3meu systemd-entrypoint[3655956]: WARNING: Please consider reporting this to the maintainers of org.opensearch.bootstrap.Security
Aug 18 18:17:59 lavm-od61ss3meu systemd-entrypoint[3655956]: WARNING: System::setSecurityManager will be removed in a future release
Aug 18 18:18:21 lavm-od61ss3meu systemd[1]: Started OpenSearch.
lines 1-21/21 (END)
如何使用终端正确检查 OpenSearch 集群状态
请尝试执行以下命令:
curl -XGET https://localhost:9201/_cluster/health?pretty
步骤3:在Magento 2中配置OpenSearch
现在 OpenSearch 已安装并运行,下一步是针对 Magento 2.4.7 进行配置。
要在 Magento 中从 Elasticsearch 迁移到 OpenSearch(版本 2.4.5 或更低版本),请按照以下步骤操作:
登录到您的 Magento 管理员。
导航至:商店 > 配置 > 目录 > 目录 > 目录搜索
更新搜索引擎配置如下:
搜索引擎:选择 Opensearch
OpenSearch 服务器主机名:localhost
Opensearch 服务器端口:9200
Opensearch 索引前缀:magento2
启用 Opensearch HTTP 身份验证:否
您还可以参考下图来了解如何设置这些配置

完成必要的调整后,请记住测试连接。
最后,运行以下命令重新索引并清除缓存:
php bin/magento indexer:reindex && php bin/magento cache:flush
本文参考: https://docs.opensearch.org/latest/install-and-configure/install-opensearch/debian/