[英]Packetbeat not able to connect to elasticsearch docker
我正在嘗試將我需要使用的所有彈性服務進行碼頭化。 docker-compose文件如下所示
version: '3'
services:
redis:
build: ./docker/redis
postgresql:
build: ./docker/postgresql
ports:
- "5433:5432"
env_file:
- .env
graphql:
build: .
command: npm run start
volumes:
- ./logs/:/usr/app/logs/
ports:
- "3000:3000"
env_file:
- .env
depends_on:
- "redis"
- "postgresql"
links:
- "redis"
- "postgresql"
elasticsearch:
build: ./docker/elasticsearch
container_name: elasticsearch
networks:
- elastic
ports:
- "9200:9200"
depends_on:
- "graphql"
links:
- "kibana"
kibana:
build: ./docker/kibana
container_name: kibana
ports:
- "5601:5601"
depends_on:
- "graphql"
networks:
- elastic
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
metricbeat:
build: ./docker/metricbeat
depends_on:
- "graphql"
- "elasticsearch"
- "kibana"
volumes:
- /proc:/hostfs/proc:ro
- /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro
- /:/hostfs:ro
networks:
- elastic
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
command:
- "-system.hostfs=/hostfs"
packetbeat:
build: ./docker/packetbeat
depends_on:
- "graphql"
- "elasticsearch"
- "kibana"
cap_add:
- NET_ADMIN
networks:
- elastic
environment:
- ELASTICSEARCH_URL=http://127.0.0.1:9200
logstash:
build: ./docker/logstash
ports:
- "9600:9600"
volumes:
- ./logs:/usr/logs
depends_on:
- "graphql"
- "elasticsearch"
- "kibana"
networks:
- elastic
environment:
- ELASTICSEARCH_URL=http://elasticsearch:9200
networks:
elastic:
driver: bridge
現在一切都運行良好,但問題是packetbeat只在自己的docker容器內捕獲網絡。 在彈性文檔參考中-https : //www.elastic.co/guide/zh-CN/beats/packetbeat/master/running-on-docker.html它說我需要啟用“主機”網絡才能捕獲所有物理主機的始發和到達網絡。 但是,由於我已將網絡配置為-elastic
無法將其他主機網絡接口添加到packetbeat。 如果我刪除-elastic
網絡並添加-host
網絡,則無法連接到elasticsearch,因為DNS elasticsearch在另一個網絡中不再存在。 我該如何克服這個問題?
這是一個很常見的問題,Docker的良好隔離會影響您的工作。 例如,在使用Prometheus node_exporter來收集主機度量的情況下,也會發生同樣的情況,當在沒有訪問主機網絡的容器中運行時,這也幾乎沒有用。
正如您已經提到的,不可能同時使用network_mode: host
和docker networks
。 因此,對於您的用例,您可以使packetbeat容器與主機網絡一起運行,而不將其附加到docker網絡。 因此,您不再能夠通過http://elasticsearch:9200
將其連接到elasticsearch實例,因此您需要將此配置值替換為您已經在其中配置的http://your-host-ip:9200
。您的Elasticsearch服務作為映射端口。 當使用network_mode: host
運行時,可能http://127.0.0.1
也可以使用network_mode: host
因為它應該是您的主機網絡中的localhost
主機-因此,elasticsearch端口映射到的主機。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.