No alive nodes found in your cluster 表示 Magento 的搜索客户端没有找到可用节点,但它没有说明是端口拒绝、TLS 握手、账号错误,还是搜索服务本身不可用。先在运行 PHP 的同一台主机或容器中测试,避免“运维电脑能连”造成误判。

getent hosts opensearch
nc -vz opensearch 9200
curl -v http://opensearch:9200/
curl -vk https://opensearch:9200/
curl -sku 'search_user:REDACTED' https://opensearch:9200/_cluster/health?pretty

Connection refused 看监听地址和容器端口;超时看安全组、网络策略和防火墙;HTTP 请求收到“plain HTTP traffic was sent to HTTPS port”,说明 Magento 配置的协议不对;401/403 则继续检查认证和权限。

对照 Magento 实际读取的配置

bin/magento config:show catalog/search/engine
bin/magento config:show catalog/search/elasticsearch7_server_hostname
bin/magento config:show catalog/search/elasticsearch7_server_port
bin/magento config:show catalog/search/elasticsearch7_enable_auth
grep -n "catalog/search" app/etc/env.php app/etc/config.php

后台显示值不一定是运行时最终值,环境变量或 env.php 可能覆盖数据库配置。容器里不要把 localhost 当成搜索容器;localhost 指向当前 PHP 容器本身。

集群黄色不等于客户端一定不可用

curl -sku 'search_user:REDACTED' https://opensearch:9200/_cluster/health?pretty
curl -sku 'search_user:REDACTED' https://opensearch:9200/_cat/nodes?v
curl -sku 'search_user:REDACTED' https://opensearch:9200/_cat/indices?v | head

单节点集群因副本无法分配可能长期 yellow,但仍能处理请求;red、没有主分片或磁盘达到水位线才会直接影响索引。检查搜索日志中的磁盘、熔断器和 shard allocation 信息。

配置修复后再验证 Magento 调用

bin/magento indexer:reset catalogsearch_fulltext
bin/magento indexer:reindex catalogsearch_fulltext
bin/magento indexer:status catalogsearch_fulltext
curl -sk 'https://shop.example.com/catalogsearch/result/?q=test' -o /tmp/search.html

不要在搜索服务仍不可达时循环 reindex,这只会增加失败任务和日志。最终应同时确认:PHP 运行环境能请求集群、全文索引成功、前台搜索返回商品,并且日志不再产生新的连接异常。