环境: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. POJ 3057 Evacuation (二分匹配)

    题意:给定一个图,然后有几个门,每个人要出去,但是每个门每个秒只能出去一个,然后问你最少时间才能全部出去. 析:初一看,应该是像搜索,但是怎么保证每个人出去的时候都不冲突呢,毕竟每个门每次只能出一个人 ...

  2. linux计划任务(一)

    一次性计划任务 at /etc/init.d/atd [root@localhost ~]# at : at> /bin/ls /etc |wc -l > /tmp/yimiao_demo ...

  3. cron.c

    /* $OpenBSD: cron.c,v 1.39 2007/02/18 23:59:03 jmc Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul ...

  4. ZOJ2388 Beat the Spread! 2017-04-16 19:18 91人阅读 评论(0) 收藏

    Beat the Spread! Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbowl Sunday is nearly here. ...

  5. ETL开发

    要进入开发阶段,了解不同的ETL产品. 整个ETL系统中,时间或更精确的,吞吐量是主要关心的内容.这种转换处理任务设计的主要目的归根结底是使得数据装载到展现表中最快并使得最终用户能快速的从这些表中得到 ...

  6. Oracle FND API–Create User

    --API - fnd_user_pkg.createuser----Example -- -- ---------------------------------------- API to CRE ...

  7. 结对项目— 词频统计2(语言C++)

    结对对象:季天梦 博客地址:http://www.cnblogs.com/jitianmeng/ github链接:https://github.com/liuyutianlyt/EX_4.md 比例 ...

  8. 自我简介与Github的注册和使用

    我叫陈鑫,学号1413042059,来自网络工程142班.喜欢打乒乓球,玩策略类游戏,团队竞技.                                                     ...

  9. linux系统上查看硬件信息

    一:查看CPU more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo 如 ...

  10. Spring中ApplicationContext和beanfactory区别---解析一

    BeanFacotry是spring中比较原始的Factory.如XMLBeanFactory就是一种典型的BeanFactory.原始的BeanFactory无法支持spring的许多插件,如AOP ...