docker部署ES集群的實(shí)現(xiàn)
一. 安裝環(huán)境說明
Ubuntu 20.04.2 LTS
elasticsearch 7.10.1
二. 從docker鏡像倉庫拉取es鏡像
docker pull elasticsearch:7.10.1
若鏡像拉取不到可以使用騰訊云的docker鏡像源https://mirror.ccs.tencentyun.com
三. 創(chuàng)建文件映射目錄
# 在當(dāng)前用戶下創(chuàng)建es集群文件夾 mkdir ./elasticsearch # 該集群共創(chuàng)建三個(gè)節(jié)點(diǎn) 分別是es-master、es-node01、es-node02 # 為這三個(gè)節(jié)點(diǎn)分別創(chuàng)建數(shù)據(jù)和插件映射文件夾 cd elasticsearch mkdir ./es-{master,node01,node02} ./es-{master,node01,node02}/data ./es-{master,node01,node02}/plugins # 授予文件夾訪問權(quán)限 chmod 777 ./es-{master,node01,node02}/data ./es-{master,node01,node02}/plugins
四. 運(yùn)行docker容器
#master docker run -d \ --name=es-master \ --restart=always \ -e "http.host=0.0.0.0" \ -e "ES_JAVA_OPTS=-Xms4g -Xmx4g" \ -e "cluster.name=es-cluster" \ -e "cluster.initial_master_nodes=es-master" \ -v /etc/localtime:/etc/localtime \ -v /home/ubuntu/elasticsearch/es-master/data:/usr/share/elasticsearch/data \ -v /home/ubuntu/elasticsearch/es-master/plugins:/usr/share/elasticsearch/plugins \ -p 9200:9200 \ -p 9300:9300 \ elasticsearch:7.10.1 #01 docker run -d \ --name=es-node01 \ --restart=always \ -e "http.host=0.0.0.0" \ -e "ES_JAVA_OPTS=-Xms2g -Xmx2g" \ -e "cluster.name=es-cluster" \ -e "cluster.initial_master_nodes=es-master" \ -v /etc/localtime:/etc/localtime \ -v /home/ubuntu/elasticsearch/es-node01/data:/usr/share/elasticsearch/data \ -v /home/ubuntu/elasticsearch/es-node01/plugins:/usr/share/elasticsearch/plugins \ -p 9201:9201 \ -p 9301:9301 \ elasticsearch:7.10.1 #02 docker run -d \ --name=es-node02 \ --restart=always \ -e "http.host=0.0.0.0" \ -e "ES_JAVA_OPTS=-Xms2g -Xmx2g" \ -e "cluster.name=es-cluster" \ -e "cluster.initial_master_nodes=es-master" \ -v /etc/localtime:/etc/localtime \ -v /home/ubuntu/elasticsearch/es-node02/data:/usr/share/elasticsearch/data \ -v /home/ubuntu/elasticsearch/es-node02/plugins:/usr/share/elasticsearch/plugins \ -p 9202:9202 \ -p 9302:9302 \ elasticsearch:7.10.1
docker ps 查看啟動(dòng)狀態(tài)
Elasticsearch 的 9200 端口和 9300 端口分別承擔(dān)著不同的職責(zé):
9200 端口
- 用途:9200 端口主要用于 HTTP 協(xié)議的 RESTful 接口,允許客戶端通過 HTTP 協(xié)議與 Elasticsearch 進(jìn)行交互。
- 功能:
- 提供了一個(gè) RESTful API,用于執(zhí)行 CRUD(創(chuàng)建、讀取、更新、刪除)操作。
- 支持查詢、索引管理和集群管理等功能。
- 通常用于客戶端應(yīng)用、Web 界面(如 Kibana)或任何希望與 Elasticsearch 交互的應(yīng)用程序。
9300 端口
- 用途:9300 端口主要用于節(jié)點(diǎn)間的 TCP 通信,是 Elasticsearch 集群內(nèi)部通信的基礎(chǔ)。
- 功能:
- 用于 Elasticsearch 節(jié)點(diǎn)之間的通信,包括數(shù)據(jù)傳輸、心跳檢測(cè)等。
- 支持集群發(fā)現(xiàn)和節(jié)點(diǎn)加入集群的過程。
- 通常用于集群內(nèi)部節(jié)點(diǎn)之間的通信,而不是客戶端直接使用。
啟動(dòng)出現(xiàn)的問題及解決方案
AccessDeniedException[/usr/share/elasticsearch/data/nodes]
映射文件夾沒有權(quán)限,通過chmod授予文件夾權(quán)限即可
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
虛擬內(nèi)存限制:vm.max_map_count
的值太低,需要增加到至少 262144。
1). 修改系統(tǒng)參數(shù):
2). 使更改生效:
3). 驗(yàn)證設(shè)置:
在宿主機(jī)上編輯 /etc/sysctl.conf
文件,添加以下行:
vm.max_map_count=262144
運(yùn)行以下命令使更改立即生效:
sysctl -p
查看當(dāng)前的 vm.max_map_count
設(shè)置:
cat /proc/sys/vm/max_map_count
the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
發(fā)現(xiàn)設(shè)置:默認(rèn)的發(fā)現(xiàn)設(shè)置不適合生產(chǎn)使用,需要配置至少一個(gè) discovery.seed_hosts
、discovery.seed_providers
或 cluster.initial_master_nodes
。
配置 cluster.initial_master_nodes
:
為 es-master
節(jié)點(diǎn)配置 cluster.initial_master_nodes
,使其知道哪些節(jié)點(diǎn)可以成為主節(jié)點(diǎn)。
五. 生成證書
# 進(jìn)入master容器 docker exec -it es-master bash # 進(jìn)入bin目錄 cd bin # 執(zhí)行生成證書命令并一路回車 elasticsearch-certutil cert # 生成的證書 elastic-certificates.p12 默認(rèn)會(huì)放在當(dāng)前目錄下 即/usr/share/elasticsearch # 將證書拷貝到config文件夾下 mv elastic-certificates.p12 ./config # 修改證書所有者 chown elasticsearch:elasticsearch elastic-certificates.p12
將證書拷貝到另外兩個(gè)服務(wù)的容器中
# 先將證書從當(dāng)前容器中拷貝出來 docker cp es-master:/usr/share/elasticsearch/config/elastic-certificates.p12 ./ # 將證書拷貝到目標(biāo)容器中并修改所有者(需進(jìn)入容器修改,命令略) docker cp ./elastic-certificates.p12 es-node01:/usr/share/elasticsearch/config docker cp ./elastic-certificates.p12 es-node02:/usr/share/elasticsearch/config
六. 修改 elasticsearch.yml文件
進(jìn)入es容器,編輯elasticsearch.yml文件
docker exec -it es-master bash vi /usr/share/elasticsearch/config/elasticsearch.yml
三個(gè)容器的配置分別為(根據(jù)實(shí)際情況修改ip地址):
master
cluster.name: "es-cluster" network.host: 0.0.0.0 network.publish_host: 127.0.0.1 http.port: 9200 transport.tcp.port: 9300 http.cors.enabled: true http.cors.allow-origin: "*" node.name: es-master node.master: true node.data: false node.ingest: false indices.queries.cache.size: 5% indices.fielddata.cache.size: 5% indices.breaker.fielddata.limit: 70% indices.breaker.request.limit: 60% indices.breaker.total.limit: 90% http.max_content_length: 200m discovery.zen.ping_timeout: 10s discovery.zen.fd.ping_timeout: 10000s discovery.zen.fd.ping_retries: 10 discovery.zen.minimum_master_nodes: 1 discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9302","127.0.0.1:9303"] cluster.initial_master_nodes: ["es-master"] # 添加xpack證書配置 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.client_authentication: required xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
node01
cluster.name: "es-cluster" network.host: 0.0.0.0 network.publish_host: 127.0.0.1 http.port: 9201 transport.tcp.port: 9301 http.cors.enabled: true http.cors.allow-origin: "*" node.name: es-node01 node.master: false node.data: true node.ingest: true indices.queries.cache.size: 5% indices.fielddata.cache.size: 5% indices.breaker.fielddata.limit: 70% indices.breaker.request.limit: 60% indices.breaker.total.limit: 90% http.max_content_length: 200m discovery.zen.ping_timeout: 10s discovery.zen.fd.ping_timeout: 10000s discovery.zen.fd.ping_retries: 10 discovery.zen.minimum_master_nodes: 1 discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"] cluster.initial_master_nodes: ["es-master"] # 添加xpack證書配置 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.client_authentication: required xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
node02
cluster.name: "es-cluster" network.host: 0.0.0.0 network.publish_host: 127.0.0.1 http.port: 9202 transport.tcp.port: 9302 http.cors.enabled: true http.cors.allow-origin: "*" node.name: es-node02 node.master: false node.data: true node.ingest: true indices.queries.cache.size: 5% indices.fielddata.cache.size: 5% indices.breaker.fielddata.limit: 70% indices.breaker.request.limit: 60% indices.breaker.total.limit: 90% http.max_content_length: 200m discovery.zen.ping_timeout: 10s discovery.zen.fd.ping_timeout: 10000s discovery.zen.fd.ping_retries: 10 discovery.zen.minimum_master_nodes: 1 discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"] cluster.initial_master_nodes: ["es-master"] # 添加xpack證書配置 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.client_authentication: required xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
七. 重啟服務(wù)
docker restart es-master docker restart es-node01 docker restart es-node02
八. 修改默認(rèn)密碼
# 進(jìn)入es-master容器 docker exec -it es-master bash # 執(zhí)行修改密碼命令并一次輸入密碼和確認(rèn)密碼 ./bin/elasticsearch-setup-passwords interactive
九. 查看集群狀態(tài)
訪問http://127.0.0.1:9200/_cluster/health?pretty 或者 http://127.0.0.1:9200/_cluster/state?pretty 查看集群狀態(tài)
{ "cluster_name" : "es-cluster", "status" : "green", "timed_out" : false, "number_of_nodes" : 3, "number_of_data_nodes" : 2, "active_primary_shards" : 1, "active_shards" : 2, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "delayed_unassigned_shards" : 0, "number_of_pending_tasks" : 0, "number_of_in_flight_fetch" : 0, "task_max_waiting_in_queue_millis" : 0, "active_shards_percent_as_number" : 100.0 }
到此這篇關(guān)于docker部署ES集群的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)docker部署ES集群內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Docker中conda環(huán)境的導(dǎo)出和導(dǎo)入
現(xiàn)在很多的應(yīng)用程序系統(tǒng)都會(huì)選擇使用docker容器進(jìn)行部署,本文主要介紹了Docker中conda環(huán)境的導(dǎo)出和導(dǎo)入,具有一定的參考價(jià)值,感興趣的可以了解一下2024-02-02docker-compose管理容器network與ip問題
這篇文章主要介紹了docker-compose管理容器network與ip問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01docker啟動(dòng)Nginx的兩種方式小結(jié)
本文介紹了兩種獲取Nginx鏡像的方式:直接從DockerHub拉取和通過Dockerfile構(gòu)建,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-10-10docker mysql修改root賬號(hào)密碼并賦予權(quán)限
本文主要介紹了docker mysql修改root賬號(hào)密碼并賦予權(quán)限,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07