Docker部署Elastic Exporter遇连接拒绝及指标缺失问题求助
问题描述
我正在本地环境部署Elastic Exporter,使用的Elasticsearch版本为8.1.2,版本信息如下:
{ "name" : "0a166124ca20", "cluster_name" : "docker-cluster", "cluster_uuid" : "xxxxxxxxxxxxxxx", "version" : { "number" : "8.1.2", "build_flavor" : "default", "build_type" : "docker", "build_hash" : "xxxxxxxxxxxxxxx", "build_date" : "2022-03-29T21:18:59.991429448Z", "build_snapshot" : false, "lucene_version" : "9.0.0", "minimum_wire_compatibility_version" : "7.17.0", "minimum_index_compatibility_version" : "7.0.0" }, "tagline" : "You Know, for Search" }
已在Elasticsearch配置中禁用X-Pack安全,配置如下:
xpack.license.self_generated.type: basic xpack.security.enabled: false xpack.monitoring.collection.enabled: true xpack.monitoring.exporters.my_local_exporter: type: local bootstrap.memory_lock: true search.allow_expensive_queries: true indices.memory.index_buffer_size: 30%
但在Docker中运行Elastic Exporter时仍出现连接被拒绝错误,且只能获取少量指标(如elasticsearch_node_stats_up为0)。我的docker-compose配置如下:
elasticsearch_exporter: image: quay.io/prometheuscommunity/elasticsearch-exporter:latest command: - '--es.uri=http://localhost:9200' - '--es.ssl-skip-verify' - '--es.all' restart: always environment: - 'ES_API_KEY=Apikey xxxxxxxxxx' ports: - "9114:9114"
解决步骤
1. 修正Docker内部的Elasticsearch地址
Docker容器内的localhost指向容器自身,而非宿主机的Elasticsearch服务:
- 若Elasticsearch通过同一docker-compose部署,将
--es.uri改为Elasticsearch服务的名称(比如服务名是elasticsearch,则写为http://elasticsearch:9200) - 若Elasticsearch运行在宿主机,Linux/macOS环境可使用
host.docker.internal:9200,Windows需额外配置Docker宿主机访问权限
2. 移除无效的认证配置
已禁用X-Pack安全,ES_API_KEY环境变量完全多余,直接删除该配置,避免exporter执行无效认证流程。
3. 清理冗余参数
既然禁用了SSL,--es.ssl-skip-verify参数无需保留,可直接删除。
修正后的docker-compose配置示例:
elasticsearch_exporter: image: quay.io/prometheuscommunity/elasticsearch-exporter:latest command: - '--es.uri=http://elasticsearch:9200' # 替换为实际Elasticsearch地址 - '--es.all' restart: always ports: - "9114:9114" # 若和Elasticsearch在同一自定义网络,需添加networks字段关联对应网络
4. 验证网络连通性
进入exporter容器,手动测试与Elasticsearch的连通性:
docker exec -it [exporter容器ID/名称] curl http://[elasticsearch地址]:9200
若能返回Elasticsearch版本信息,说明网络正常;否则检查网络配置、Elasticsearch是否正常启动、端口是否开放。
5. 检查Elasticsearch监听配置
确保Elasticsearch的network.host设置为允许外部访问(如0.0.0.0),默认可能仅监听localhost导致容器无法访问,在Elasticsearch配置文件中添加:
network.host: 0.0.0.0 http.port: 9200
内容的提问来源于stack exchange,提问作者Alon212
相关产品推荐
相关产品推荐

