在docker中運行elasticsearch時go程序無法連接到節點


錯誤信息:

panic: no active connection found: no Elasticsearch node available

在docker中運行es時,默認啟動sniffing 模式,es自動查找節點, 要確保Elasticsearch返回可從容器外部訪問的IP地址。

解決方式為關閉sniffing或者配置es返回的主機地址,參考 https://github.com/olivere/elastic/wiki/Docker

1. 配置elasticsearch

    - 將network.publish_host和network.bind_host配置為可從容器外部訪問的地址

    - 配置network.host (不用再單獨配置network.bind_host 和 network.publish_host

2. 禁用 sniffing

     elastic.SetSniff(false)

# 查看節點信息,詳細返回參數:Nodes Info
curl -XGET '0.0.0.0:9200/_nodes/http?pretty' { "_nodes" : { "total" : 1, "successful" : 1, "failed" : 0 }, "cluster_name" : "escluster", "nodes" : { "nodename" : { "name" : "name", "transport_address" : "xxxx:9300", "host" : "xxxx", "ip" : "xxxx", "version" : "6.4.1", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "e36acdb", "roles" : [ "master", "data", "ingest" ], "attributes" : { "ml.machine_memory" : "16826724352", "xpack.installed" : "true", "ml.max_open_jobs" : "20", "ml.enabled" : "true" }, "http" : { "bound_address" : [ "0.0.0.0:9200" //http服務綁定的主機地址,配置為可從容器外部訪問的地址 ], "publish_address" : "xxxx:9200", //http客戶端發布的主機地址,配置為可從容器外部訪問的地址 "max_content_length_in_bytes" : 104857600 } } } }

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM