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)集群名稱必須保持一致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)的跨域訪問(wèn)http.cors.enabled:true http.cors.allow.-origin:"*"
配置文件
cluster node-1 config/elasticsearch.yml # 集群名稱 cluster.name: es-cluster #節(jié)點(diǎn)名稱 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"] # 集群初始話指定主節(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 # 集群名稱 cluster.name: es-cluster #節(jié)點(diǎn)名稱 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"] # 集群初始話指定主節(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 # 集群名稱 cluster.name: es-cluster #節(jié)點(diǎn)名稱 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"] # 集群初始話指定主節(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)完成之后分別訪問(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"
}訪問(wèn)kibana
- http://172.30.38.46:5606/
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
CentOS 7.x docker使用overlay2存儲(chǔ)方式
這篇文章主要介紹了CentOS 7.x docker使用overlay2存儲(chǔ)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11
Docker如何使用nginx搭建tomcat集群(圖文詳解)
這篇文章主要介紹了Docker使用nginx搭建tomcat集群的教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
docker常用命令及設(shè)置開(kāi)機(jī)自啟方式
這篇文章主要介紹了docker常用命令及設(shè)置開(kāi)機(jī)自啟方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
docker-compose搭建mongodb、mysql的詳細(xì)過(guò)程
這篇文章主要介紹了docker-compose搭建mongodb、mysql的詳細(xì)過(guò)程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-11-11
Docker Namespace容器隔離的實(shí)現(xiàn)
Namespace是Docker容器中的一種隔離機(jī)制,通過(guò)劃分資源獨(dú)立空間,確保容器之間互不干擾,本文主要介紹一下Docker Namespace容器隔離的實(shí)現(xiàn),感興趣的可以了解一下2024-11-11
docker拉取阿里云鏡像倉(cāng)庫(kù)報(bào)錯(cuò)解決辦法
最近很多朋友遇到docker拉取鏡像失敗的問(wèn)題,下面這篇文章主要介紹了docker拉取阿里云鏡像倉(cāng)庫(kù)報(bào)錯(cuò)的解決辦法,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-06-06

