Docker搭建Elasticsearch集群和Kibana全過(guò)程
Docker搭建Elasticsearch集群
集群規(guī)劃,采用三個(gè)節(jié)點(diǎn)
# 準(zhǔn)備3個(gè)es節(jié)點(diǎn) es 9200 9300 - web 9201 tcp:9301 node-1 elasticsearch.yml - web 9202 tcp:9302 node-2 elasticsearch.yml - web 9203 tcp:9303 node-3 elasticsearch.yml
注意:
- 所有節(jié)點(diǎn)集群名稱(chēng)必須保持一致cluster.name
- 每個(gè)節(jié)點(diǎn)必須有唯一的名字 node.name
- 開(kāi)啟每個(gè)節(jié)點(diǎn)的遠(yuǎn)程連接network.host:0.0.0.0
- 指定IP地址進(jìn)行集群節(jié)點(diǎn)通信network_publish_host:
- 修改web端口tcp端口http.port:transport.tcp.port
- 指定集群中所有系節(jié)點(diǎn)通信列表discovery.seed_hosts:node-1 node-2 node-3相同
- 允許集群初始化master節(jié)點(diǎn)節(jié)點(diǎn)數(shù):cluster.initial_master_nodes:[“node-1”, “node-2”, “node-3”]
- 集群最少幾個(gè)節(jié)點(diǎn)可用gateway.recover_after_nodes:2
- 開(kāi)啟每個(gè)節(jié)點(diǎn)的跨域訪(fǎng)問(wèn)http.cors.enabled:true http.cors.allow.-origin:"*"
配置文件
cluster node-1 config/elasticsearch.yml # 集群名稱(chēng) cluster.name: es-cluster #節(jié)點(diǎn)名稱(chēng) node.name: node-1 # 發(fā)布地址,一個(gè)單一地址,用于通知集群中的其他節(jié)點(diǎn),以便其他的節(jié)點(diǎn)能夠和它通信。當(dāng)前,一個(gè) elasticsearch 節(jié)點(diǎn)可能被綁定到多個(gè)地址,但是僅僅有一個(gè)發(fā)布地址 # docker宿主機(jī)ip network.publish_host: 172.30.38.46 # 開(kāi)放遠(yuǎn)程連接,bind_host和publish_host一起設(shè)置 network.host: 0.0.0.0 # 對(duì)外暴露的http請(qǐng)求端口 http.port: 9201 # 集群節(jié)點(diǎn)之間通信用的TCP端口 transport.tcp.port: 9301 # 一個(gè)集群中最小主節(jié)點(diǎn)個(gè)數(shù)(防止腦裂,一般為n/2 + 1,n為集群節(jié)點(diǎn)個(gè)數(shù))(7.10.1版本已取消?) discovery.zen.minimum_master_nodes: 2 # 新節(jié)點(diǎn)啟動(dòng)時(shí)能被發(fā)現(xiàn)的節(jié)點(diǎn)列表(新增節(jié)點(diǎn)需要添加自身) discovery.zen.ping.unicast.hosts: ["172.30.38.46:9301","172.30.38.46:9302","172.30.38.46:9303"] # 集群初始話(huà)指定主節(jié)點(diǎn)(節(jié)點(diǎn)名),7版本必須設(shè)置 cluster.initial_master_nodes: ["node-1","node-2","node-3"] # 跨域問(wèn)題解決 http.cors.enabled: true http.cors.allow-origin: "*" node-2 config/elasticsearch.yml # 集群名稱(chēng) cluster.name: es-cluster #節(jié)點(diǎn)名稱(chēng) node.name: node-1 # 發(fā)布地址,一個(gè)單一地址,用于通知集群中的其他節(jié)點(diǎn),以便其他的節(jié)點(diǎn)能夠和它通信。當(dāng)前,一個(gè) elasticsearch 節(jié)點(diǎn)可能被綁定到多個(gè)地址,但是僅僅有一個(gè)發(fā)布地址 network.publish_host: 172.30.38.46 # 開(kāi)放遠(yuǎn)程連接,bind_host和publish_host一起設(shè)置 network.host: 0.0.0.0 # 對(duì)外暴露的http請(qǐng)求端口 http.port: 9202 # 集群節(jié)點(diǎn)之間通信用的TCP端口 transport.tcp.port: 9302 # 一個(gè)集群中最小主節(jié)點(diǎn)個(gè)數(shù)(防止腦裂,一般為n/2 + 1,n為集群節(jié)點(diǎn)個(gè)數(shù))(7.10.1版本已取消?) discovery.zen.minimum_master_nodes: 2 # 新節(jié)點(diǎn)啟動(dòng)時(shí)能被發(fā)現(xiàn)的節(jié)點(diǎn)列表(新增節(jié)點(diǎn)需要添加自身) discovery.zen.ping.unicast.hosts: ["172.30.38.46:9301","172.30.38.46:9302","172.30.38.46:9303"] # 集群初始話(huà)指定主節(jié)點(diǎn)(節(jié)點(diǎn)名),7版本必須設(shè)置 cluster.initial_master_nodes: ["node-1","node-2","node-3"] # 跨域問(wèn)題解決 http.cors.enabled: true http.cors.allow-origin: "*" node-3 config/elasticsearch.yml # 集群名稱(chēng) cluster.name: es-cluster #節(jié)點(diǎn)名稱(chēng) node.name: node-1 # 發(fā)布地址,一個(gè)單一地址,用于通知集群中的其他節(jié)點(diǎn),以便其他的節(jié)點(diǎn)能夠和它通信。當(dāng)前,一個(gè) elasticsearch 節(jié)點(diǎn)可能被綁定到多個(gè)地址,但是僅僅有一個(gè)發(fā)布地址 network.publish_host: 172.30.38.46 # 開(kāi)放遠(yuǎn)程連接,bind_host和publish_host一起設(shè)置 network.host: 0.0.0.0 # 對(duì)外暴露的http請(qǐng)求端口 http.port: 9203 # 集群節(jié)點(diǎn)之間通信用的TCP端口 transport.tcp.port: 9303 # 一個(gè)集群中最小主節(jié)點(diǎn)個(gè)數(shù)(防止腦裂,一般為n/2 + 1,n為集群節(jié)點(diǎn)個(gè)數(shù))(7.10.1版本已取消?) discovery.zen.minimum_master_nodes: 2 # 新節(jié)點(diǎn)啟動(dòng)時(shí)能被發(fā)現(xiàn)的節(jié)點(diǎn)列表(新增節(jié)點(diǎn)需要添加自身) discovery.zen.ping.unicast.hosts: ["172.30.38.46:9301","172.30.38.46:9302","172.30.38.46:9303"] # 集群初始話(huà)指定主節(jié)點(diǎn)(節(jié)點(diǎn)名),7版本必須設(shè)置 cluster.initial_master_nodes: ["node-1","node-2","node-3"] # 跨域問(wèn)題解決 http.cors.enabled: true http.cors.allow-origin: "*"
創(chuàng)建/elk/escluster-kibana-compose/node-1,/elk/escluster-kibana-compose/node-2,/elk/escluster-kibana-compose/node-3文件夾。
分別在三個(gè)文件夾下創(chuàng)建config文件夾并在config文件夾下創(chuàng)建elasticsearch.yml
文件,
cluster node-1 config/elasticsearch.yml cluster.name: es-cluster node.name: node-1 network.publish_host: 172.30.38.46 network.host: 0.0.0.0 http.port: 9201 transport.tcp.port: 9301 discovery.zen.minimum_master_nodes: 2 discovery.zen.ping.unicast.hosts: ["172.30.38.46:9301","172.30.38.46:9302","172.30.38.46:9303"] cluster.initial_master_nodes: ["node-1","node-2","node-3"] http.cors.enabled: true http.cors.allow-origin: "*" node-2 config/elasticsearch.yml cluster.name: es-cluster node.name: node-2 network.publish_host: 172.30.38.46 network.host: 0.0.0.0 http.port: 9202 transport.tcp.port: 9302 discovery.zen.minimum_master_nodes: 2 discovery.zen.ping.unicast.hosts: ["172.30.38.46:9301","172.30.38.46:9302","172.30.38.46:9303"] cluster.initial_master_nodes: ["node-1","node-2","node-3"] http.cors.enabled: true http.cors.allow-origin: "*" node-3 config/elasticsearch.yml cluster.name: es-cluster node.name: node-3 network.publish_host: 172.30.38.46 network.host: 0.0.0.0 http.port: 9203 transport.tcp.port: 9303 discovery.zen.minimum_master_nodes: 2 discovery.zen.ping.unicast.hosts: ["172.30.38.46:9301","172.30.38.46:9302","172.30.38.46:9303"] cluster.initial_master_nodes: ["node-1","node-2","node-3"] http.cors.enabled: true http.cors.allow-origin: "*"
/elk/escluster-kibana-compose/kibana.yml
server.name: kibana server.port: 5606 server.host: "0" elasticsearch.hosts: [ "http://es01:9201","http://es02:9202","http://es03:9203" ] xpack.monitoring.ui.container.elasticsearch.enabled: true
docker-compose.yml文件
version: "2" networks: escluster: services: es01: image: elasticsearch:7.6.0 ports: - "9201:9201" - "9301:9301" networks: - "escluster" environment: - "ES_JAVA_OPTS=-Xms512m -Xmx512m" volumes: - /elk/escluster-kibana-compose/node-1/data:/usr/share/elasticsearch/data - /elk/escluster-kibana-compose/node-1/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - /elk/escluster-kibana-compose/node-1/plugins/ik-7.6.0:/usr/share/elasticsearch/plugins/ik-7.6.0 es02: image: elasticsearch:7.6.0 ports: - "9202:9202" - "9302:9302" networks: - "escluster" environment: - "ES_JAVA_OPTS=-Xms512m -Xmx512m" volumes: - /elk/escluster-kibana-compose/node-2/data:/usr/share/elasticsearch/data - /elk/escluster-kibana-compose/node-2/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - /elk/escluster-kibana-compose/node-2/plugins/ik-7.6.0:/usr/share/elasticsearch/plugins/ik-7.6.0 es03: image: elasticsearch:7.6.0 ports: - "9203:9203" - "9303:9303" networks: - "escluster" environment: - "ES_JAVA_OPTS=-Xms512m -Xmx512m" volumes: - /elk/escluster-kibana-compose/node-3/data:/usr/share/elasticsearch/data - /elk/escluster-kibana-compose/node-3/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - /elk/escluster-kibana-compose/node-3/plugins/ik-7.6.0:/usr/share/elasticsearch/plugins/ik-7.6.0 kibana: image: kibana:7.6.0 ports: - "5606:5606" networks: - "escluster" volumes: - /elk/escluster-kibana-compose/kibana.yml:/usr/share/kibana/config/kibana.yml
執(zhí)行docker-compose
# 啟動(dòng) docker-compose up -d # 查看日志 docker-compose logs -f
啟動(dòng)完成之后分別訪(fǎng)問(wèn)
- http://172.30.38.46:9201/
- http://172.30.38.46:9202/
- http://172.30.38.46:9203/
{ "name": "node-1", "cluster_name": "es-cluster", "cluster_uuid": "gC1ZHP8uSOqnqof0-Rdlcg", "version": { "number": "7.6.0", "build_flavor": "default", "build_type": "docker", "build_hash": "7f634e9f44834fbc12724506cc1da681b0c3b1e3", "build_date": "2020-02-06T00:09:00.449973Z", "build_snapshot": false, "lucene_version": "8.4.0", "minimum_wire_compatibility_version": "6.8.0", "minimum_index_compatibility_version": "6.0.0-beta1" }, "tagline": "You Know, for Search" } { "name": "node-2", "cluster_name": "es-cluster", "cluster_uuid": "gC1ZHP8uSOqnqof0-Rdlcg", "version": { "number": "7.6.0", "build_flavor": "default", "build_type": "docker", "build_hash": "7f634e9f44834fbc12724506cc1da681b0c3b1e3", "build_date": "2020-02-06T00:09:00.449973Z", "build_snapshot": false, "lucene_version": "8.4.0", "minimum_wire_compatibility_version": "6.8.0", "minimum_index_compatibility_version": "6.0.0-beta1" }, "tagline": "You Know, for Search" } { "name": "node-3", "cluster_name": "es-cluster", "cluster_uuid": "gC1ZHP8uSOqnqof0-Rdlcg", "version": { "number": "7.6.0", "build_flavor": "default", "build_type": "docker", "build_hash": "7f634e9f44834fbc12724506cc1da681b0c3b1e3", "build_date": "2020-02-06T00:09:00.449973Z", "build_snapshot": false, "lucene_version": "8.4.0", "minimum_wire_compatibility_version": "6.8.0", "minimum_index_compatibility_version": "6.0.0-beta1" }, "tagline": "You Know, for Search" }
訪(fǎng)問(wèn)kibana
- http://172.30.38.46:5606/
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Docker安裝ClickHouse并初始化數(shù)據(jù)測(cè)試
clickhouse作為現(xiàn)在流行的數(shù)據(jù)分析數(shù)據(jù)庫(kù),非常熱門(mén),docker如何安裝ClickHouse,很多朋友并不是很明白,今天小編抽空給大家分享一篇教程關(guān)于Docker安裝ClickHouse并初始化數(shù)據(jù)測(cè)試的問(wèn)題,一起看看吧2021-06-06詳解Windows?利用?WSL2?安裝?Docker?的2種方式
這篇文章主要介紹了Windows?利用?WSL2?安裝?Docker?的2種方式,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-10-10Docker容器啟動(dòng)時(shí)初始化Mysql數(shù)據(jù)庫(kù)的方法
這篇文章給大家介紹Docker容器啟動(dòng)時(shí)初始化Mysql數(shù)據(jù)庫(kù)的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2013-11-11Docker時(shí)間不一致,時(shí)區(qū)設(shè)置方式
這篇文章主要介紹了Docker時(shí)間不一致,時(shí)區(qū)設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11docker.service啟動(dòng)失?。篣nit not found的原因及解決辦法
這篇文章主要介紹了docker.service啟動(dòng)失敗:Unit not found的原因分析及解決辦法,需要的朋友可以參考下2017-04-04如何利用Docker部署一個(gè)簡(jiǎn)單的springboot項(xiàng)目
這篇文章主要介紹了如何利用Docker部署一個(gè)簡(jiǎn)單的springboot項(xiàng)目,本文通過(guò)實(shí)例圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-02-02