docker部署ES集群的實現(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)建文件映射目錄
# 在當前用戶下創(chuàng)建es集群文件夾 mkdir ./elasticsearch # 該集群共創(chuàng)建三個節(jié)點 分別是es-master、es-node01、es-node02 # 為這三個節(jié)點分別創(chuàng)建數據和插件映射文件夾 cd elasticsearch mkdir ./es-{master,node01,node02} ./es-{master,node01,node02}/data ./es-{master,node01,node02}/plugins # 授予文件夾訪問權限 chmod 777 ./es-{master,node01,node02}/data ./es-{master,node01,node02}/plugins
四. 運行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 查看啟動狀態(tài)
Elasticsearch 的 9200 端口和 9300 端口分別承擔著不同的職責:
9200 端口
- 用途:9200 端口主要用于 HTTP 協(xié)議的 RESTful 接口,允許客戶端通過 HTTP 協(xié)議與 Elasticsearch 進行交互。
- 功能:
- 提供了一個 RESTful API,用于執(zhí)行 CRUD(創(chuàng)建、讀取、更新、刪除)操作。
- 支持查詢、索引管理和集群管理等功能。
- 通常用于客戶端應用、Web 界面(如 Kibana)或任何希望與 Elasticsearch 交互的應用程序。
9300 端口
- 用途:9300 端口主要用于節(jié)點間的 TCP 通信,是 Elasticsearch 集群內部通信的基礎。
- 功能:
- 用于 Elasticsearch 節(jié)點之間的通信,包括數據傳輸、心跳檢測等。
- 支持集群發(fā)現(xiàn)和節(jié)點加入集群的過程。
- 通常用于集群內部節(jié)點之間的通信,而不是客戶端直接使用。
啟動出現(xiàn)的問題及解決方案
AccessDeniedException[/usr/share/elasticsearch/data/nodes]
映射文件夾沒有權限,通過chmod授予文件夾權限即可
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
虛擬內存限制:vm.max_map_count
的值太低,需要增加到至少 262144。
1). 修改系統(tǒng)參數:
2). 使更改生效:
3). 驗證設置:
在宿主機上編輯 /etc/sysctl.conf
文件,添加以下行:
vm.max_map_count=262144
運行以下命令使更改立即生效:
sysctl -p
查看當前的 vm.max_map_count
設置:
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)設置:默認的發(fā)現(xiàn)設置不適合生產使用,需要配置至少一個 discovery.seed_hosts
、discovery.seed_providers
或 cluster.initial_master_nodes
。
配置 cluster.initial_master_nodes
:
為 es-master
節(jié)點配置 cluster.initial_master_nodes
,使其知道哪些節(jié)點可以成為主節(jié)點。
五. 生成證書
# 進入master容器 docker exec -it es-master bash # 進入bin目錄 cd bin # 執(zhí)行生成證書命令并一路回車 elasticsearch-certutil cert # 生成的證書 elastic-certificates.p12 默認會放在當前目錄下 即/usr/share/elasticsearch # 將證書拷貝到config文件夾下 mv elastic-certificates.p12 ./config # 修改證書所有者 chown elasticsearch:elasticsearch elastic-certificates.p12
將證書拷貝到另外兩個服務的容器中
# 先將證書從當前容器中拷貝出來 docker cp es-master:/usr/share/elasticsearch/config/elastic-certificates.p12 ./ # 將證書拷貝到目標容器中并修改所有者(需進入容器修改,命令略) docker cp ./elastic-certificates.p12 es-node01:/usr/share/elasticsearch/config docker cp ./elastic-certificates.p12 es-node02:/usr/share/elasticsearch/config
六. 修改 elasticsearch.yml文件
進入es容器,編輯elasticsearch.yml文件
docker exec -it es-master bash vi /usr/share/elasticsearch/config/elasticsearch.yml
三個容器的配置分別為(根據實際情況修改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
七. 重啟服務
docker restart es-master docker restart es-node01 docker restart es-node02
八. 修改默認密碼
# 進入es-master容器 docker exec -it es-master bash # 執(zhí)行修改密碼命令并一次輸入密碼和確認密碼 ./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 }
到此這篇關于docker部署ES集群的實現(xiàn)的文章就介紹到這了,更多相關docker部署ES集群內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
docker-compose管理容器network與ip問題
這篇文章主要介紹了docker-compose管理容器network與ip問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01