首页 > 网站 > 帮助中心 > 正文

Docker-compose 建立ELK集群的实现方法

2024-07-09 22:43:12
字体:
来源:转载
供稿:网友

全部编排文件和配置文件可以访问我的 Github ,大家只要修改配置文件中的路径即可快速搭建一个3实例的ES集群和一个Kibana实例。

规划

计划创建3个ES实例组成一个集群,同时创建一个Kibana实例连接该集群。每个ES实例使用本地配置文件,方便配置文件的保存和版本管理。Kibana的配置文件也放在本地,通过文件映射的方式挂载到容器内。

总的目录结构如下:

$ tree.├── docker-compose.yml├── kibana.yml├── node1│ └── es1.yml├── node2│ └── es2.yml└── node3 └── es3.yml3 directories, 5 files

编排文件

主要的编排文件是 docker-compose.yml

version: "2.1"services: es-node1: image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0 hostname: es-node1 expose: #不会将端口暴露给容器外应用 - "9001" ports: #将端口暴露到宿主机中 - "9200:9200" - "9300:9300" volumes: - ~/Projects/sh-valley/docker-conf/elasticstack/cluster/node1/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml environment: - cluster.name=es-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms256m -Xmx256m" ulimits: memlock: soft: -1 hard: -1 networks: es-cluster-network: ipv4_address: 172.21.0.10 es-node2: image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0 hostname: es-node2 expose: #不会将端口暴露给容器外应用 - "9002" ports: #将端口暴露到宿主机中 - "9201:9201" - "9301:9301" volumes: - ~/Projects/sh-valley/docker-conf/elasticstack/cluster/node2/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml environment: - cluster.name=es-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms256m -Xmx256m" ulimits: memlock: soft: -1 hard: -1 networks: es-cluster-network: ipv4_address: 172.21.0.11 es-node3: image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0 hostname: es-node3 expose: #不会将端口暴露给容器外应用 - "9003" ports: #将端口暴露到宿主机中 - "9202:9202" - "9302:9302" volumes: - ~/Projects/sh-valley/docker-conf/elasticstack/cluster/node3/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml environment: - cluster.name=es-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms256m -Xmx256m" ulimits: memlock: soft: -1 hard: -1 networks: es-cluster-network: ipv4_address: 172.21.0.12 kibana: image: docker.elastic.co/kibana/kibana:6.7.0 ports: - "5601:5601" volumes: - ~/Projects/sh-valley/docker-conf/elasticstack/cluster/kibana.yml:/usr/share/kibana/config/kibana.yml environment: - ELASTICSEARCH_URL=http://es-node1:9200 networks: - es-cluster-networknetworks: es-cluster-network: driver: bridge ipam: driver: default config: - subnet: 172.21.0.0/16 gateway: 172.21.0.1

ES配置文件只选取了一个示例如下:

cluster.name: elasticsearch-clusternode.name: es-node1network.bind_host: 0.0.0.0network.publish_host: 172.21.0.10http.port: 9200transport.tcp.port: 9300http.cors.enabled: truehttp.cors.allow-origin: "*"node.master: true node.data: true discovery.zen.ping.unicast.hosts: ["172.21.0.10:9300","172.21.0.11:9301","172.21.0.12:9302"]discovery.zen.minimum_master_nodes: 2
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表