Docker 08 部署Elasticsearch
阿新 • • 發佈:2021-12-10
部署 Elasticsearch 可以參考 Docker Hub 官方文件:https://hub.docker.com/_/elasticsearch
啟動 Elasticsearch
Elasticsearch 十分耗記憶體,建議啟動前先儘量騰出記憶體空間。
Elasticsearch 需要暴露的埠很多,啟動時需要比較複雜的配置。
Elasticsearch 的資料一般需要放置到安全目錄,這裡又涉及到資料卷技術了。
[root@sail sail]# docker run -d --name elasticsearch01 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2 Unable to find image 'elasticsearch:7.6.2' locally 7.6.2: Pulling from library/elasticsearch ab5ef0e58194: Pull complete c4d1ca5c8a25: Pull complete 941a3cc8e7b8: Pull complete 43ec483d9618: Pull complete c486fd200684: Pull complete 1b960df074b2: Pull complete 1719d48d6823: Pull complete Digest: sha256:1b09dbd93085a1e7bca34830e77d2981521a7210e11f11eda997add1c12711fa Status: Downloaded newer image for elasticsearch:7.6.2 6eccd8a777d91764963c2464b30db78b189f5c867633255e996bae088ace6029
[root@sail sail]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6eccd8a777d9 elasticsearch:7.6.2 "/usr/local/bin/dock…" 8 seconds ago Up 7 seconds 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch01
[root@sail sail]# docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
6eccd8a777d9 elasticsearch01 0.00% 1.238GiB / 1.694GiB 73.06% 0B / 0B 292MB / 389kB 43
由此可以看出,Elasticsearch 是多麼的耗記憶體。
所以啟動 Elasticsearch 時建議限制其最大記憶體佔用。
[root@sail sail]# docker run -d --name elasticsearch02 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2 e6d7fe80cf2961817bd1184b98fd320dce4d9071b80ffb78aa413f484fa498ae
[root@sail sail]# docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
e6d7fe80cf29 elasticsearch02 0.78% 379.8MiB / 1.694GiB 21.89% 0B / 0B 106MB / 733kB 44
這樣 Elasticsearch 的記憶體佔用就會小很多了。
測試驗證
[root@sail sail]# curl localhost:9200
{
"name" : "e6d7fe80cf29",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "MIfPING6SFGVR88knFCf6w",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"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"
}
至此 Elasticsearch 部署完成。
本文來自部落格園,作者:程式航,轉載請註明原文連結:https://www.cnblogs.com/codesail/p/15672816.html