环境:ES-5.4.0版本,部署方式:3master node+2client node+3data node

说明:data node和client node都配置了http.enabled: false,程序在写数据时报错:No data nodes with HTTP-enabled available

源码分析:

 public static void filterNonDataNodesIfNeeded(Settings settings, Log log) {
if (!settings.getNodesDataOnly()) {
return;
} RestClient bootstrap = new RestClient(settings);
try {
String message = "No data nodes with HTTP-enabled available";
List<NodeInfo> dataNodes = bootstrap.getHttpDataNodes();
    // 找不到dataNodes就会报错
if (dataNodes.isEmpty()) {
throw new EsHadoopIllegalArgumentException(message);
}
...
} finally {
bootstrap.close();
}
}

接下来看看RestClient.getHttpDataNodes()方法的取值逻辑

 public List<NodeInfo> getHttpDataNodes() {
List<NodeInfo> nodes = getHttpNodes(false);
  // 遍历上面获取到的节点
Iterator<NodeInfo> it = nodes.iterator();
while (it.hasNext()) {
NodeInfo node = it.next();
    // 如果不是数据节点,则移除
if (!node.isData()) {
it.remove();
}
}
return nodes;
} // 获取http节点_nodes/http
public List<NodeInfo> getHttpNodes(boolean clientNodeOnly) {
  // 通过es接口“_nodes/http”来获取nodes的信息
Map<String, Map<String, Object>> nodesData = get("_nodes/http", "nodes");
List<NodeInfo> nodes = new ArrayList<NodeInfo>(); for (Entry<String, Map<String, Object>> entry : nodesData.entrySet()) {
NodeInfo node = new NodeInfo(entry.getKey(), entry.getValue());
    // 如果不是查找client节点,则只要节点运行网络访问就可以add了;如果查找client节点,则还要通过isClient验证才能add
if (node.hasHttp() && (!clientNodeOnly || node.isClient())) {
nodes.add(node);
}
}
return nodes;
}

最后再来看看node.hasHttp(),isClient(),isData()的方法

     private final String id;
private final String name;
private final String host;
private final String ip;
private final String publishAddress;
private final boolean hasHttp;
private final boolean isClient;
private final boolean isData;
private final boolean isIngest; public NodeInfo(String id, Map<String, Object> map) {
this.id = id;
EsMajorVersion version = EsMajorVersion.parse((String) map.get("version"));
this.name = (String) map.get("name");
this.host = (String) map.get("host");
this.ip = (String) map.get("ip");
    // 5.0以下版本的分支
if (version.before(EsMajorVersion.V_5_X)) {
Map<String, Object> attributes = (Map<String, Object>) map.get("attributes");
if (attributes == null) {
this.isClient = false;
this.isData = true;
} else {
String data = (String) attributes.get("data");
this.isClient = data == null ? true : !Boolean.parseBoolean(data);
this.isData = data == null ? true : Boolean.parseBoolean(data);
}
this.isIngest = false;
    // 5.0版本以上的分支
} else {
List<String> roles = (List<String>) map.get("roles");
      // 如果roles列表中不包含"data",则此节点是client
this.isClient = roles.contains("data") == false;
      // 如果roles列表中包含"data",则此节点是data
this.isData = roles.contains("data");
      // 如果roles列表中包含"ingest",则此节点是ingest
this.isIngest = roles.contains("ingest");
}
Map<String, Object> httpMap = (Map<String, Object>) map.get("http");
    // 如果节点数据中包含key:http
if (httpMap != null) {
String addr = (String) httpMap.get("publish_address");
      // 如果http数据中包含key:publish_address
if (addr != null) {
StringUtils.IpAndPort ipAndPort = StringUtils.parseIpAddress(addr);
this.publishAddress = ipAndPort.ip + ":" + ipAndPort.port;
        // 则此节点可以提供http服务,即:http.enabled: true
this.hasHttp = true;
} else {
this.publishAddress = null;
this.hasHttp = false;
}
} else {
this.publishAddress = null;
this.hasHttp = false;
}
}

从上面的源码分析可以得出:如果一个data节点不配置http.enabled:true,则此节点不会被getHttpDataNodes()方法搜索到,那么就会直接抛出异常:No data nodes with HTTP-enabled available

解决的方法无非两种:

第一:数据节点配置 http.enabled:true

第二:绕过filterNonDataNodesIfNeeded()校验,需要settings.getNodesDataOnly()返回false;看下面源码可知,默认es.nodes.data.only是true,在客户端中将其设置为false即可。

 /** Clients only */
String ES_NODES_CLIENT_ONLY = "es.nodes.client.only";
String ES_NODES_CLIENT_ONLY_DEFAULT = "false"; /** Data only */
String ES_NODES_DATA_ONLY = "es.nodes.data.only";
String ES_NODES_DATA_ONLY_DEFAULT = "true"; /** Ingest only */
String ES_NODES_INGEST_ONLY = "es.nodes.ingest.only";
String ES_NODES_INGEST_ONLY_DEFAULT = "false"; /** WAN only */
String ES_NODES_WAN_ONLY = "es.nodes.wan.only";
String ES_NODES_WAN_ONLY_DEFAULT = "false"; ... public boolean getNodesDataOnly() {
// by default, if not set, return a value compatible with the other settings
  // 默认es.nodes.data.only是true,在客户端中将其设置为false即可
return Booleans.parseBoolean(getProperty(ES_NODES_DATA_ONLY), !getNodesWANOnly() && !getNodesClientOnly() && !getNodesIngestOnly());
} public boolean getNodesIngestOnly() {
return Booleans.parseBoolean(getProperty(ES_NODES_INGEST_ONLY, ES_NODES_INGEST_ONLY_DEFAULT));
} public boolean getNodesClientOnly() {
return Booleans.parseBoolean(getProperty(ES_NODES_CLIENT_ONLY, ES_NODES_CLIENT_ONLY_DEFAULT));
} public boolean getNodesWANOnly() {
return Booleans.parseBoolean(getProperty(ES_NODES_WAN_ONLY, ES_NODES_WAN_ONLY_DEFAULT));
}

最后附上一段"_nodes/http"接口的返回值:

"nodes": {
"YgwRm4j1RwiK3jjDHY8Hzw": {
"name": "node-02",
"transport_address": "192.168.100.10:9300",
"host": "192.168.100.10",
"ip": "192.168.100.10",
"version": "5.4.0",
"build_hash": "780f8c4",
"roles": [
"master",
"ingest"
],
"attributes": {
"ml.enabled": "true"
},
"http": {
"bound_address": [
"192.168.100.10:9200"
],
"publish_address": "192.168.100.10:9200",
"max_content_length_in_bytes": 104857600
}
}
...
}

ElasticSearch 问题分析:No data nodes with HTTP-enabled available的更多相关文章

  1. Elasticsearch提示low disk watermark [85%] exceeded on [UTyrLH40Q9uIzHzX-yMFXg][Sonofelice][/Users/baidu/Documents/work/soft/data/nodes/0] free: 15.2gb[13.4%], replicas will not be assigned to this node

    mac本地启动es之后发现运行一段时间一分钟就能打印好几条info日志: [--13T10::,][INFO ][o.e.c.r.a.DiskThresholdMonitor] [Sonofelice ...

  2. ElasticSearch评分分析 explian 解释和一些查询理解

    ElasticSearch评分分析 explian 解释和一些查询理解 按照es-ik分析器安装了ik分词器.创建索引:PUT /index_ik_test.索引包含2个字段:content和nick ...

  3. Elasticsearch日志分析系统

    Elasticsearch日志分析系统 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是Elasticsearch 一个采用Restful API标准的高扩展性的和高可用性 ...

  4. 图解Janusgraph系列-图数据底层序列化源码分析(Data Serialize)

    图解Janusgraph系列-图数据底层序列化源码分析(Data Serialize) 大家好,我是洋仔,JanusGraph图解系列文章,实时更新~ 图数据库文章总目录: 整理所有图相关文章,请移步 ...

  5. Change the default MySQL data directory with SELinux enabled

    转载:https://rmohan.com/?p=4605 Change the default MySQL data directory with SELinux enabled This is a ...

  6. Elasticsearch 技术分析(九):Elasticsearch的使用和原理总结

    前言 之前已经分享过Elasticsearch的使用和原理的知识,由于近期在公司内部做了一次内部分享,所以本篇主要是基于之前的博文的一个总结,希望通过这篇文章能让读者大致了解Elasticsearch ...

  7. org.elasticsearch.transport.ReceiveTimeoutTransportException[cluster:monitor/nodes/liveness] request_id [31] timed out after [5000ms]

    ES连接超时,异常信息 2017-09-07 10:42:45.042 [elasticsearch[Bantam][transport_client_worker][T#17]{New I/O wo ...

  8. elasticsearch之hello(spring data整合)

    1.书写pom.xml文件 <dependencies> <dependency> <groupId>org.springframework.data</gr ...

  9. ElasticSearch聚合分析

    聚合用于分析查询结果集的统计指标,我们以观看日志分析为例,介绍各种常用的ElasticSearch聚合操作. 目录: 查询用户观看视频数和观看时长 聚合分页器 查询视频uv 单个视频uv 批量查询视频 ...

随机推荐

  1. .NET基础 (09)常用集合和泛型

    常用集合和泛型1 int[]是引用类型还是值类型2 数组之间如何进行转换3 解释泛型的基本原理4 什么是泛型的主要约束和次要约束 常用集合和泛型1 int[]是引用类型还是值类型 数组类型是一族类型, ...

  2. POJ 3685 Matrix (二分套二分)

    Matrix Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8674   Accepted: 2634 Descriptio ...

  3. 在Github注册账户

    https://github.com/JasonHaoz

  4. LR中的迭代次数设置

    在参数化时,对于一次压力测试中均只能用一次的资源应该怎么参数化呢?就是说这些资源用了一次就不能在用了的. --参数化时,在select  next row选择unique,update value o ...

  5. 【转发】在SQL Server中通过字段值查询存储该字段的表

    -- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.     -- Purpose: To search all colu ...

  6. DNS本机可解析,其他主机通过本机无法解析问题

    新建了一个redhat虚拟机,将此虚拟机作为dns服务器使用,配置完以后宿主机的dns服务器设置为配置好的虚拟机地址,结果总是显示no Server Reached,没有服务器可以到达,花了很长时间终 ...

  7. linux下使用supervisor启动.net core mvc website的配置

    发布好的asp.net core mvc项目, 如果想在window或linux下的以控制台程序启动的话,可以用下面的命令 dotnet MyProject.dll --urls="http ...

  8. IIS服务器添加网站

    1.添加IIS服务:对“我的电脑”右键,管理,点击服务和应用程序,如果下面没有”Internet Information Services(IIS)管理器“,打开控制面板,点击程序,启用或者关闭Win ...

  9. Code Chef February Challenge 2019题解

    传送门 \(HMAPPY2\) 咕 话说这题居然卡\(scanf\)的么??? int T;cin>>T; while(T--){ cin>>n>>a>> ...

  10. HTTP报文语法/HTTP组成

        一.HTTP报文分类:请求报文和响应报文 请求报文会向Web服务器请求一个动作,响应报文会将请求的结果返回给客户端 请求报文格式: <method>  <request-UR ...