我尝试使用2个泊坞窗容器配置ELK群集。
我使用以下图片:
我使用docker-compose
为该图片创建了2个泊坞窗容器;每个都在独立模式下完美运行。
我想以创建群集的方式在彼此之间链接2个ELK节点,但我还没有找到合适的解决方案。 container1 中的Elasticsearch节点与 container2 中的Elasticsearch节点无法通信。
这是两个docker-compose.yml
:
CONTAINER1:
version: '2'
services:
elasticsearch01:
image: sebp/elk:es241_l240_k461
ports:
- "5601:5601"
- "9200:9200"
- "9300:9300"
- "5044:5044"
volumes:
- /opt/ELK1/logstash/conf.d:/etc/logstash/conf.d
privileged: true
container2的:
version: '2'
services:
elasticsearch02:
image: sebp/elk:es241_l240_k461
ports:
- "5602:5601"
- "9201:9200"
- "9301:9300"
- "5045:5044"
volumes:
- /opt/ELK2/logstash/conf.d:/etc/logstash/conf.d
privileged: true
我已经以这种方式在docker容器中配置了elasticsearch.yml
:
NODE IN CONTAINER1:
cluster.name: elasticsearchcluster
node.name: node1
network.host: 0.0.0.0
network.bind_host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["127.0.0.1", "172.21.0.2"]
discovery.zen.minimum_master_nodes: 1
NODE IN CONTAINER2:
cluster.name: elasticsearchcluster
node.name: node2
network.host: 0.0.0.0
network.bind_host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["127.0.0.1", "172.22.0.2"]
discovery.zen.minimum_master_nodes: 1
关键是 discovery.zen.ping.unicast.hosts
参数:我没有真正的IP地址,因为它是一个泊坞广告容器。
我尝试docker inspect elasticsearch01
,我有以下"IPAddress"
属性:
"NetworkSettings": {
...
"Networks": {
"ELK1_default": {
...
"Gateway": "172.22.0.1",
"IPAddress": "172.22.0.2",
...
}
}
}
但如果我设置了该IP地址,它就不起作用。
如何正确配置群集?
修改
尝试主机ip-address和端口,节点1启动,节点2失败,没有错误。
discovery.zen.ping.unicast.hosts: ["127.0.0.1", "192.168.0.1:9300"] -> OK
discovery.zen.ping.unicast.hosts: ["127.0.0.1", "192.168.0.2:9300"] -> FAILS with no errors
答案 0 :(得分:2)
不是使用带有ELK堆栈的准备好的docker文件,而是可以使用以下内容:
pull
使用version: '3'
services:
elasticsearch:
image: elasticsearch:2.4.1
ports:
- 9200:9200
networks:
- elk
elasticsearch_slave:
image: elasticsearch:2.4.1
networks:
- elk
depends_on:
- elasticsearch
command: elasticsearch --discovery.zen.ping.unicast.hosts=elasticsearch
logstash:
image: logstash:2.3.3
hostname: logstash
networks:
- elk
volumes:
- ./logstash.conf:/config/logstash.conf
depends_on:
- elasticsearch
ports:
- 5044:5044
command: logstash -f /config/logstash.conf
kibana:
image: kibana:4.5.1
hostname: kibana
networks:
- elk
depends_on:
- elasticsearch
- logstash
ports:
- 5601:5601
networks:
elk:
driver: bridge
启动图像后,您可以使用以下命令docker-compose up -d
一旦完成 - 你将有5个从属+客户端节点,它打开端口9200作为整个集群的网关。
例如,执行此操作后,docker-compose scale elasticsearch_slave=5
会显示以下内容:
答案 1 :(得分:1)
感谢Evaldas Buinauskas,我已经找到了堆栈的解决方案!
首先,我们只需要一个docker-compose.yml 。 在该文件中,我们需要配置两个服务(每个容器一个用于创建),一个网络在两个服务之间共享。
这是新的docker-compose.yml
:
version: '2'
services:
elk1:
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms2048m -Xmx2048m"
image: sebp/elk:es241_l240_k461
networks:
- elk_net
ports:
- "5601:5601"
- "9200:9200"
- "9300:9300"
- "5044:5044"
volumes:
- /opt/elk/logstash/conf.d:/etc/logstash/conf.d
privileged: true
elk2:
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms2048m -Xmx2048m"
image: sebp/elk:es241_l240_k461
networks:
- elk_net
ports:
- "5602:5601"
- "9201:9200"
- "9301:9300"
- "5045:5044"
depends_on:
- elk1
volumes:
- /opt/elk/logstash/conf.d:/etc/logstash/conf.d
privileged: true
networks:
elk_net:
driver: bridge
命令docker-compose up
将创建3个元素:
使用docker network inspect elk_net
命令,我们可以查看分配给2个容器的(docker)IP地址。
elasticsearch.yml文件必须配置如下:
cluster.name: elasticsearchcluster
node.name: node1
network.host: 0.0.0.0
network.bind_host: 0.0.0.0
network.publish_host: ${IP_ADDRESS_ELK1}
discovery.zen.ping.unicast.hosts: ["${IP_ADDRESS_ELK2}"]
discovery.zen.minimum_master_nodes: 1
cluster.name: elasticsearchcluster
node.name: node2
network.host: 0.0.0.0
network.bind_host: 0.0.0.0
network.publish_host: ${IP_ADDRESS_ELK2}
discovery.zen.ping.unicast.hosts: ["${IP_ADDRESS_ELK1}"]
discovery.zen.minimum_master_nodes: 1
使用此配置,群集可以正常工作:两个节点正确合并,Http get到每个elasticsearch服务器返回保存在2个节点中的所有文档。