全部編排文件和配置文件可以訪問(wèn)我的 Github ,大家只要修改配置文件中的路徑即可快速搭建一個(gè)3實(shí)例的ES集群和一個(gè)Kibana實(shí)例。
規(guī)劃
計(jì)劃創(chuàng)建3個(gè)ES實(shí)例組成一個(gè)集群,同時(shí)創(chuàng)建一個(gè)Kibana實(shí)例連接該集群。每個(gè)ES實(shí)例使用本地配置文件,方便配置文件的保存和版本管理。Kibana的配置文件也放在本地,通過(guò)文件映射的方式掛載到容器內(nèi)。
總的目錄結(jié)構(gòu)如下:
$ tree
.
├── docker-compose.yml
├── kibana.yml
├── node1
│ └── es1.yml
├── node2
│ └── es2.yml
└── node3
└── es3.yml
3 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: #不會(huì)將端口暴露給容器外應(yīng)用
- "9001"
ports: #將端口暴露到宿主機(jī)中
- "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: #不會(huì)將端口暴露給容器外應(yīng)用
- "9002"
ports: #將端口暴露到宿主機(jī)中
- "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: #不會(huì)將端口暴露給容器外應(yīng)用
- "9003"
ports: #將端口暴露到宿主機(jī)中
- "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-network
networks:
es-cluster-network:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.21.0.0/16
gateway: 172.21.0.1
ES配置文件只選取了一個(gè)示例如下:
cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 172.21.0.10
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.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
Kibana的配置文件如下
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://es-node1:9200", "http://es-node2:9201", "http://es-node3:9202" ]
xpack.monitoring.ui.container.elasticsearch.enabled: false
啟動(dòng)命令
配置文件準(zhǔn)備好之后,就可以啟動(dòng)集群了
啟動(dòng)過(guò)程可能會(huì)比較慢,通過(guò)命令行可以看到集群節(jié)點(diǎn)
$ curl http://localhost:9200/_cat/nodes
172.21.0.12 51 96 29 6.53 6.43 3.72 md - es-node3
172.21.0.11 47 96 30 6.53 6.43 3.72 mdi - es-node2
172.21.0.10 49 96 30 6.53 6.43 3.72 mdi * es-node1
后續(xù)使用過(guò)程中可以通過(guò) docker-compose 命令啟動(dòng)、停止服務(wù),如果不想保留相關(guān)的實(shí)例,可以使用 docker-compose down 關(guān)閉并刪除容器。
參考資料
elasticsearch document
docker-compose自定義網(wǎng)絡(luò),固定容器ip地址
docker-compose ports和expose的區(qū)別
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。