環(huán)境準(zhǔn)備:
3臺centos7.9的服務(wù)器
vim /etc/sysctl.conf添加:vm.max_map_count=262144
sysctl -w vm.max_map_count=262144 即時生效
cat /proc/sys/vm/max_map_count 查看
#創(chuàng)建es配置目錄
mkdir /home/es/config -p
#創(chuàng)建es數(shù)據(jù)目錄
mkdir /home/es/data
#創(chuàng)建es插件目錄
mkdir /home/es/plugins
#授權(quán)目錄
chmod -R 777 /home/es
在/home/es/config創(chuàng)建elasticsearch.yml的配置文件
# ======================== Elasticsearch Configuration =========================
# 配置es的集群名稱,es會自動發(fā)現(xiàn)在同一網(wǎng)段下的es,如果在同一網(wǎng)段下有多個集群,就可以用這個屬性來區(qū)分不同的集群
cluster.name: es-cluster
# 節(jié)點(diǎn)名稱
node.name: es-node-1
# 指定該節(jié)點(diǎn)是否有資格被選舉成為node
node.master: true
# 指定初始主節(jié)點(diǎn)
cluster.initial_master_nodes: ["10.161.3.12:9300"]
# 指定該節(jié)點(diǎn)是否存儲索引數(shù)據(jù),默認(rèn)為true
node.data: true
# 設(shè)置綁定的ip地址還有其他節(jié)點(diǎn)和該節(jié)點(diǎn)交換的ip地址,本機(jī)ip
network.host: 0.0.0.0
network.publish_host: 10.161.3.12
# 指定http端口
http.port: 9200
# 設(shè)置節(jié)點(diǎn)間交互的tcp端口,默認(rèn)是9300
transport.tcp.port: 9300
# 設(shè)置集群中master節(jié)點(diǎn)的初始列表,可以通過這些節(jié)點(diǎn)來自動發(fā)現(xiàn)新加入集群的節(jié)點(diǎn)
discovery.zen.ping.unicast.hosts: ["10.161.3.12:9300","10.161.3.13:9300","10.161.3.14:9300"]
# 如果要使用head,那么需要解決跨域問題,使head插件可以訪問es
http.cors.enabled: true
http.cors.allow-origin: "*"
# ======================== Elasticsearch Configuration =========================
# 配置es的集群名稱,es會自動發(fā)現(xiàn)在同一網(wǎng)段下的es,如果在同一網(wǎng)段下有多個集群,就可以用這個屬性來區(qū)分不同的集群
cluster.name: es-cluster
# 節(jié)點(diǎn)名稱
node.name: es-node-2
# 指定該節(jié)點(diǎn)是否有資格被選舉成為node
node.master: true
# 指定初始主節(jié)點(diǎn)
cluster.initial_master_nodes: ["10.161.3.12:9300"]
# 指定該節(jié)點(diǎn)是否存儲索引數(shù)據(jù),默認(rèn)為true
node.data: true
# 設(shè)置綁定的ip地址還有其他節(jié)點(diǎn)和該節(jié)點(diǎn)交換的ip地址,本機(jī)ip
network.host: 0.0.0.0
network.publish_host: 10.161.3.13
# 指定http端口
http.port: 9200
# 設(shè)置節(jié)點(diǎn)間交互的tcp端口,默認(rèn)是9300
transport.tcp.port: 9300
# 設(shè)置集群中master節(jié)點(diǎn)的初始列表,可以通過這些節(jié)點(diǎn)來自動發(fā)現(xiàn)新加入集群的節(jié)點(diǎn)
discovery.zen.ping.unicast.hosts: ["10.161.3.12:9300","10.161.3.13:9300","10.161.3.14:9300"]
# 如果要使用head,那么需要解決跨域問題,使head插件可以訪問es
http.cors.enabled: true
http.cors.allow-origin: "*"
# ======================== Elasticsearch Configuration =========================
# 配置es的集群名稱,es會自動發(fā)現(xiàn)在同一網(wǎng)段下的es,如果在同一網(wǎng)段下有多個集群,就可以用這個屬性來區(qū)分不同的集群
cluster.name: es-cluster
# 節(jié)點(diǎn)名稱
node.name: es-node-3
# 指定該節(jié)點(diǎn)是否有資格被選舉成為node
node.master: true
# 指定初始主節(jié)點(diǎn)
cluster.initial_master_nodes: ["10.161.3.12:9300"]
# 指定該節(jié)點(diǎn)是否存儲索引數(shù)據(jù),默認(rèn)為true
node.data: true
# 設(shè)置綁定的ip地址還有其他節(jié)點(diǎn)和該節(jié)點(diǎn)交換的ip地址,本機(jī)ip
network.host: 0.0.0.0
network.publish_host: 10.161.3.14
# 指定http端口
http.port: 9200
# 設(shè)置節(jié)點(diǎn)間交互的tcp端口,默認(rèn)是9300
transport.tcp.port: 9300
# 設(shè)置集群中master節(jié)點(diǎn)的初始列表,可以通過這些節(jié)點(diǎn)來自動發(fā)現(xiàn)新加入集群的節(jié)點(diǎn)
discovery.zen.ping.unicast.hosts: ["10.161.3.12:9300","10.161.3.13:9300","10.161.3.14:9300"]
# 如果要使用head,那么需要解決跨域問題,使head插件可以訪問es
http.cors.enabled: true
http.cors.allow-origin: "*"
# es無法訪問互聯(lián)的的配置
ingest.geoip.downloader.enabled: false
分別啟動容器:
docker run -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -d \
--name es717 \
-v /home/es/data:/usr/share/elasticsearch/data \
-v /home/es/plugins:/usr/share/elasticsearch/plugins \
-v /home/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
--network=host \
elasticsearch:7.17.4
查看集群健康狀態(tài)
curl http://10.161.3.13:9200/_cat/health?v
查看集群的節(jié)點(diǎn)信息
curl http://10.161.3.13:9200/_cat/nodes?v
配置es集群的密碼:
編輯每個節(jié)點(diǎn)的elasticsearch.yml
加入如下配置:
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.keystore.type: PKCS12
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/elastic-certificates.p12
#xpack.security.transport.ssl.keystore.password: 一會兒生成 elastic-certificates.p12 設(shè)置的密碼,沒有不要這個配置
#xpack.security.transport.ssl.truststore.password: 一會兒生成 elastic-certificates.p12 設(shè)置的密碼,沒有不要這個配置
xpack.security.transport.ssl.truststore.type: PKCS12
xpack.security.audit.enabled: true
進(jìn)入一臺容器中
docker exec -it es717 /bin/bash
./bin/elasticsearch-certutil ca 一直回車

./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 一直回車
會多出兩個文件

cp elastic-certificates.p12 ./config
exit退出容器
docker cp es7.17.4:/usr/share/elasticsearch/elastic-certificates.p12 ./考出文件到config文件夾
增加讀的權(quán)限chmod +r elastic-certificates.p12
把elastic-certificates.p12分別拷貝到3個主機(jī)的config目錄下
刪除3臺容器
重新生成3臺容器運(yùn)行
docker run -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -d \
> --name es717 \
> -v /home/es/data:/usr/share/elasticsearch/data \
> -v /home/es/plugins:/usr/share/elasticsearch/plugins \
> -v /home/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
> -v /home/es/config/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12 \
> --network=host \
> elasticsearch:7.17.4
進(jìn)入到一臺容器執(zhí)行:
docker exec -it es717 /bin/sh
./bin/elasticsearch-setup-passwords interactive
然后一一設(shè)置密碼,一定要記住密碼。

瀏覽器打開
http://10.161.3.12:9200/_cat/nodes?v輸入賬號密碼查看es節(jié)點(diǎn)信息

安裝kibana:
mkdir /home/kibana/ -p
vim /home/kibana/kibana.yml,如下配置:
server.name: kibana
server.host: "0.0.0.0"
# 可以填容器名加端口,也可以用宿主機(jī)ip和映射的端口
elasticsearch.hosts: ["http://10.161.3.12:9200","http://10.161.3.13:9200","http://10.161.3.14:9200"]
xpack.monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: zh-CN
elasticsearch.username: "elastic"
elasticsearch.password: "*******"
server.port: 5601
server.publicBaseUrl: "http://10.161.3.14:560"
# es用xpack做認(rèn)證證書必須加下面三個配置
# 注意:參數(shù)值至少32位,否則啟動會報(bào)錯提示
xpack.encryptedSavedObjects.encryptionKey: encryptedSavedObjects12345678909876543210
xpack.security.encryptionKey: encryptionKeysecurity12345678909876543210
xpack.reporting.encryptionKey: encryptionKeyreporting12345678909876543210
啟動:
docker run -e XPACK_GRAPH_ENABLED=true -d \
-e TIMELION_ENABLED=true \
--name kbn717 \
-v /home/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml \
--network=host \
kibana:7.17.4
瀏覽器打開:http://10.161.3.14:5601
搭建完成
報(bào)錯server.publicBaseUrl is missing and should be configured when running in a production environment. Some features may not behave correctly. See the documentation.文章來源:http://www.zghlxwxcb.cn/news/detail-498511.html
在kibana.yml中添加配置:server.publicBaseUrl: "http://10.161.3.14:5601"文章來源地址http://www.zghlxwxcb.cn/news/detail-498511.html
到了這里,關(guān)于docker部署Elasticsearch7.17集群和kibana的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!