【问题标题】:Using tcp port "9300" in the application.properties file but still getting "None of the configured nodes are available"在 application.properties 文件中使用 tcp 端口“9300”,但仍然得到“没有配置的节点可用”
【发布时间】:2019-08-13 13:38:16
【问题描述】:

错误:

failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{uyXiOMnyRpyTSXqUoNxTyg}{localhost}{127.0.0.1:9300}]

版本:

Spring-Boot 版本:2.1.6 和 Elasticsearch 版本:7.3.0

这是我的 elasticsearch.yml 文件:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
cluster.name: elastic
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
path.data: D:\JEE_Projects\spring\Spring_WorkSpace\spring-boot-with-mongodb
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
# http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

这是我的 application.properties 文件:

#Local MongoDB config
spring.data.mongodb.uri=mongodb://localhost:27017/newtest


# App config
server.port=8080
spring.application.name=BootMongo
server.address=localhost

# elastic search

spring.data.elasticsearch.cluster-name=elastic

#spring.main.allow-bean-definition-overriding=true

#spring.data.elasticsearch.repositories.enabled = true
spring.data.elasticsearch.cluster-nodes =localhost:9300

我重新启动了应用程序,重新启动了 elasticsearch.bat,甚至重新启动了整个计算机,但没有任何效果。

此外,我认为其他一些应用程序会占用该端口,但它被 elasticsearch 本身占用。 (我在浏览器中输入“localhost:9300”,它的响应是“这不是 HTTP 端口”)。

【问题讨论】:

    标签: spring-boot elasticsearch


    【解决方案1】:

    这个问题是我提出来的,我找到了解决办法。

    有两个主要的内部问题:

    1. 在 Elasticsearch 的最新版本(我猜是从 7.x 开始)中,每个索引只能有一个“类型”(尽管不推荐在索引中拥有多个“类型”,但我们仍然强制可以使用)。我通过 @Document 注释为每个实体提供了不同的“类型”,但在相同的索引下。
    2. 我下载了最新版本的 Elasticsearch,即 7.3.0。由于它是一项新兴技术,因此更新非常频繁。但是在春季,默认情况下,Elasticsearch jar 的版本是 6.4.3(您可以通过单击 Maven Dependencies 看到这一点)

    解决方案:

    对于第一个问题,您可以为每个实体创建单独的索引。要解决第二个问题,您可以将 Elasticsearch 的版本降级到 6.4.3,也可以将 Maven 依赖项中的 jar 版本升级到 7.3.0(但是在 7.3.0 jar 中,一些内置方法有点不同并且您可能不知道)。

    【讨论】:

      【解决方案2】:

      我猜 'cluster-name=elastic' 可能是错误的。你确定 elastic 使用这样的集群名称运行吗?

      【讨论】:

      • 不,这不是问题所在。实际上我发现了错误(总共3个错误)并将自己回答问题。不过我现在有点忙。我很快就会写出解决方案。顺便感谢您抽出时间回答这个问题。
      • 你好@Dario,我已经添加了答案。看看吧。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 2018-05-15
      • 1970-01-01
      • 2019-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多