博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
es 2.3.3 向es添加数据报NoNodeAvailableException[None of the configured nodes are available
阅读量:4287 次
发布时间:2019-05-27

本文共 4345 字,大约阅读时间需要 14 分钟。

一.问题描述

    在windows中搭建了一个单机版的es2.3.3 ,定时向es中添加数据,第一次添加没有问题,第二次提示NoNodeAvailableException[None of the configured nodes are available,奶奶的,经过一上午的调试排查,终于解决了。

用了一个公共的客户端连接,报错,初始化新的客户端,通过debug查看,还是同样的hashcode值,也就是说还是同一个,

原来在这里:

public class ESUtils {    public static Client client=null;    private static int hostPort=32016;    private static String  hostClusterNode1="192.168.168.160";    private static String  hostClusterNode2="192.168.168.161";    private static String  hostClusterNode3="192.168.168.162";    /**     * 方法描述:    公共获取连接     * @param:     * @return:     **/    public static Client getESClientConnection(String indexName,String typeName,String clusterName,String nodes) {        if (client == null) {            System.err.println("-------连接es----------------------------");            System.setProperty("es.set.netty.runtime.available.processors", "false");            try {                //设置集群名称                Settings settings = Settings.builder().put("cluster.name", clusterName)                        .put("client.transport.sniff", true)                        .put("client.transport.ping_timeout", "600s").build();                   String esNodes[]=nodes.split(",");                //创建client                String host=esNodes[0].split(":")[0];                int port=Integer.parseInt(esNodes[0].split(":")[1]);                client = TransportClient.builder().settings(settings).build()                        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));                       // .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostClusterNode1), hostPort))                       // .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostClusterNode2), hostPort))                        //.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostClusterNode3), hostPort));            } catch (Exception ex) {                ex.printStackTrace();                System.out.println(ex.getMessage());                if (client != null) {                    client.close();                }            }        }        return client;    }

二.解决思路:

将初始化链接es的客户端,公共客户端,改为单次客户端,执行完一次,关闭掉,下次使用,再次初始化。

如果报异常,捕获到,重新初始化客户端。

public class ESUtils {    //public static Client client=null;    private static int hostPort=32016;    private static String  hostClusterNode1="192.168.168.160";    private static String  hostClusterNode2="192.168.168.161";    private static String  hostClusterNode3="192.168.168.162";    /**     * 方法描述:    公共获取连接     * @auther:    ypy     * @data:      2019/3/4 17:44     * @param:     * @return:     **/    public static Client getESClientConnection(String indexName,String typeName,String clusterName,String nodes) {        Client    singleEsClient=null;        if (singleEsClient == null) {            System.err.println("-------连接es----------------------------");            System.setProperty("es.set.netty.runtime.available.processors", "false");            try {                //设置集群名称                Settings settings = Settings.builder().put("cluster.name", clusterName)                        .put("client.transport.sniff", true)                        .put("client.transport.ping_timeout", "600s").build();                   String esNodes[]=nodes.split(",");                //创建client                String host=esNodes[0].split(":")[0];                int port=Integer.parseInt(esNodes[0].split(":")[1]);                singleEsClient = TransportClient.builder().settings(settings).build()                        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));                       // .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostClusterNode1), hostPort))                       // .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostClusterNode2), hostPort))                        //.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostClusterNode3), hostPort));            } catch (Exception ex) {                ex.printStackTrace();                System.out.println(ex.getMessage());                if (singleEsClient != null) {                    singleEsClient.close();                }            }        }        return singleEsClient;    }

 

 

转载地址:http://watgi.baihongyu.com/

你可能感兴趣的文章
PHP之lnmp和服务器集群设计思路
查看>>
PHP之微信公众平台开发
查看>>
iOS 之文件操作NSFileMange和NSFileHandle
查看>>
iOS之UIButton的封装和常用属性\按钮UIButton的常用属性及方法总结(二)、多按钮排列、cell上多图片布局
查看>>
nodejs基础(一)创建服务器,分发路由,读文件,写文件,读取图片,图文一起显示
查看>>
iOS之新特性轮播
查看>>
iOS 之网络下载图片
查看>>
iOS之UILabel------分类创建label,计算文本大小
查看>>
iOS之xib创建view、initWithCoder、awakeFromNib
查看>>
nodejs之异常的处理
查看>>
nodejs之参数的接收GET 和POST
查看>>
iOS之app的运行原理
查看>>
nodejs之异步流程控制ASYNC
查看>>
iOS之跑马灯的实现
查看>>
nodejs之npm的使用、nvm
查看>>
iOS之javascript调用oc
查看>>
nodejs之express(一)简单实现路由
查看>>
nodejs之代码操作mysql(直连和连接池连接mysql)\mysql权限操作
查看>>
nodejs之事件处理机制(抛出事件、监听事件)
查看>>
iOS常用之绑卡或实名认证、收货地址
查看>>