es client connect failed:no active connection found: no Elasticsearch node available

golang 使用 github.com/olivere/elastic 包进行连接 远程 es 或者docker搭建的es时(只要golang所在主机与es所在主机不同),报错信息如下

 

es client connect failed:no active connection found: no Elasticsearch node available

 

检查es node 信息

curl -s -XGET 'http://localhost:9200/_nodes/http?pretty=true’


{

  "_nodes" : {

    "total" : 1,

    "successful" : 1,

    "failed" : 0

  },

  "cluster_name" : "docker-cluster",

  "nodes" : {

    "XSzTxWW9Q3OC9UWlfdncMw" : {

      "name" : "XSzTxWW",

      "transport_address" : "172.17.0.2:9300",

      "host" : "172.17.0.2",

      "ip" : "172.17.0.2",

      "version" : "6.6.2",

      "build_flavor" : "default",

      "build_type" : "tar",

      "build_hash" : "3bd3e59",

      "roles" : [

        "master",

        "data",

        "ingest"

      ],

      "attributes" : {

        "ml.machine_memory" : "2088206336",

        "xpack.installed" : "true",

        "ml.max_open_jobs" : "20",

        "ml.enabled" : "true"

      },

      "http" : {

        "bound_address" : [

          "0.0.0.0:9200"

        ],

        "publish_address" : "172.17.0.2:9200",

        "max_content_length_in_bytes" : 104857600

      }

    }

  }

}

发现 publish_address(172.17.0.2) 地址是一个内网地址,无法正常访问,所以 会报错上面的信息,无可用的node节点

 

解决方法(两种)

  1. 改变golang代码初始化client时的参数.   client, err := elastic.NewClient(elastic.SetSniff(false),elastic.SetURL(host…))  新增参数 elastic.SetSniff(false), 用于关闭 Sniff

  2. 调整es node 的 publish_address 配置,新增 network.publish_host: 127.0.0.1, 整体配置文件如下:

            [root@e33229400bf1 config]# cat elasticsearch.yml

            cluster.name: "docker-cluster"

            network.host: 0.0.0.0

            network.publish_host: 127.0.0.1 # 新增配置项

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值