elasticsearch5.0.0连接服务器NoNodeAvailableException

Elasticsearch | 作者 Left | 发布于2018年03月13日 | 阅读数:734

client连接elasticsearch时报错

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{ft4xJAm1Q4q6icux3lyvFQ}{192.168.52.189}{192.168.52.189:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:314)
pom文件如下:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>
创建client:
     String  esName="myelastic";
String esServerIps="192.168.52.189";
int port=9300;
Settings settings = Settings.builder()
// .put("cluster.name",EsSearchConstant.ESClUSTERNAME)// 集群名
//.put("node.name","node-2")
.put("client.transport.ping_timeout", "60s")
.put("client.transport.sniff", true)
.build();
client = new PreBuiltTransportClient(settings);
String esIps[] = esServerIps.split(",");
for (String esIp : esIps) {//添加集群IP列表
//需要使用9300端口,指定es集群中的节点信息, 这个地方指定的端口是节点和节点之间的通信端口是9300,不是Http请求的端口9200.
TransportAddress transportAddress = new InetSocketTransportAddress(InetAddresses.forString(esIp),port);
client.addTransportAddresses(transportAddress);
}
linux服务器上的elasticsearch为elasticsearch-5.0.0-alpha3,其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 see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en ... gt%3B
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name : my-elastic2
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name : node-2
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# path.data: /path/to/data
#
# Path to log files:
#
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# bootstrap.mlockall: 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 : 0.0.0.0
#
# 设置节点间交互的tcp端口,默认是9300
transport.tcp.port : 9300
#
# Set a custom port for HTTP:
#
http.port : 9201
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en ... gt%3B
#
network.publish_host : 192.168.52.189
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes : 3
#
# 设置是否打开多播发现节点,默认是true
# discovery.zen.ping.multicast.enabled: true
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en ... gt%3B
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en ... gt%3B
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true
#

http.enabled : true

http.cors.allow-origin : "*"

不知道是哪里出错了,求助大神
 
已邀请:

laoyang360 - [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:blog.csdn.net/laoyang360

赞同来自:

network.host : 0.0.0.0  这里改成你本机ip,
network.publish_host : 192.168.52.189 这一行注释掉
 

skay50

赞同来自:

你好,我也遇到这个问题,已经两天了,实在没折了!!!您解决了吗?

eric930721

赞同来自:

1、代码配置端口号错误

2、es集群起了clustername,需要在setting中put进去

3、还有就是所用jar包跟服务器上的不一致

4、防火墙防火墙。。。。。。。。。。

5、还有就是ElasticSearch 5.0x之后 有个xpack插件,装了这东西获取连接方式有所不同

xiangxiaolu - 菜鸟

赞同来自:

你好,我现在也遇到了这个问题,请问你解决了吗?谢谢

AlixMu - Elasticsearch小轿车司机

赞同来自:

"client.transport.sniff", 改为false。给个赞哦

要回复问题请先登录注册