elasticsearch入門系列">elasticsearch入門系列
661
2025-04-02
docker系列之elasticsearch安裝教程
1、什么elasticsearch?
2、安裝elasticsearch
3、Elasticsearch目錄結構
4、Elasticsearch常用命令
5、Elasticsearch插件安裝
6、elasticsearch-head
1、什么Elasticsearch?
Elasticsearch是一款開源的分布式搜索引擎,基于 JSON 開發而來,具有 RESTful 風格,基于 Apache Lucene 的基礎上開發而成的
引用官網的說法:
官方文檔已經做了比較詳細的介紹,所以本博客不做詳細介紹,只介紹,基于docker的Elasticsearch安裝部署
2、安裝elasticsearch
環境準備:
elasticsearch7.2.0
docker環境
相關工具軟件:
VM VisualBox
xShell,Xftp
docker入門博客可以參考我的docker系統博客專欄:鏈接
docker鏡像搜索:
docker search elasticsearch
1
需要加上版本,不加版本默認是laster(最新)版本,貌似沒提供laster版本
docker pull elasticsearch:7.2.0
1
查看所有鏡像:
docker images
1
運行docker鏡像:
-p 隱射端口
-e 設置參數,discovery.type=single-node,設置單節點,ES_JAVA_OPTS="-Xms256m -Xmx256m",設置JVM參數
-d 后臺運行
–name 節點名稱
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d --name ES01 elasticsearch:7.2.0
1
linux內用curl訪問:
curl http://localhost:9200
1
瀏覽器直接訪問也是可以的:http://your_ip_addr:9200
3、Elasticsearch目錄結構
4、Elasticsearch常用命令
_cat 參數
_cat 參數可以查看支持的命令
[root@localhost ~]# curl localhost:9200/_cat =^.^= /_cat/allocation /_cat/shards /_cat/shards/{index} /_cat/master /_cat/nodes /_cat/tasks /_cat/indices /_cat/indices/{index} /_cat/segments /_cat/segments/{index} /_cat/count /_cat/count/{index} /_cat/recovery /_cat/recovery/{index} /_cat/health /_cat/pending_tasks /_cat/aliases /_cat/aliases/{alias} /_cat/thread_pool /_cat/thread_pool/{thread_pools} /_cat/plugins /_cat/fielddata /_cat/fielddata/{fields} /_cat/nodeattrs /_cat/repositories /_cat/snapshots/{repository} /_cat/templates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
?v 參數
?v 參數,來顯示詳細的信息
[root@localhost ~]# curl localhost:9200/_cat/master?v id host ip node 8x63m-D8Q2CP4xRbq7rEFA 172.17.0.2 172.17.0.2 7610b4e6e11b
1
2
3
其它常用命令:
查看所有插件:http://your_ip_addr:9200/_cat/plugins?v
查看所有索引:http://your_ip_addr:9200/_cat/indices?v
對ES進行健康檢查:http://your_ip_addr:9200/_cat/health?v
查看當前的磁盤占用率:http://your_ip_addr:9200/_cat/allocation?v
help參數
help 參數,來輸出可以顯示的列
[root@localhost ~]# curl localhost:9200/_cat/master?help id | | node id host | h | host name ip | | ip address node | n | node name
1
2
3
4
5
h參數
h 參數,可以指定輸出的字段
[root@localhost ~]# curl localhost:9200/_cat/master?h=host,ip,node 172.17.0.2 172.17.0.2 7610b4e6e11b
1
2
3
5、Elasticsearch插件安裝
插件安裝可以用elasticsearch-plugin install url命令
比如安裝:elasticsearch-analysis-ik
docker進入容器命令,id為9689b3dc982e
docker exec -it 9689b3dc982e /bin/bash
1
plugins安裝步驟:
# cd plugins cd /usr/share/elasticsearch/plugins/ # 安裝插件 elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.2.0/elasticsearch-analysis-ik-7.2.0.zip # 退出容器 exit # 重啟docker容器 docker restart 9689b3dc982e
1
2
3
4
5
6
7
8
6、elasticsearch-head
elasticsearch-head是用于Elasticsearch監控的插件
鏡像 pull
docker pull mobz/elasticsearch-head:5
1
2
啟動容器
docker run -d -p 9100:9100 docker.io/mobz/elasticsearch-head:5
1
可能遇到問題:
點連接后臺報錯,可能是不支持跨域訪問,需要設置跨域
cd /usr/share/elasticsearch/config/ vi elasticsearch.yml
1
2
在elasticsearch.yml的文件末尾加上:
http.cors.enabled : true http.cors.allow-origin : "*"
1
2
遇到 max virtual memory areas vm.maxmapcount [65530] is too low 報錯,可以執行下述命令
sysctl -w vm.max_map_count=262144
1
附錄:參考資料
https://www.elastic.co/guide/en/elasticsearch/reference/7.2/docker.html
https://www.lixueduan.com/post/elasticsearch/01-install-by-docker/
https://www.elastic.co/guide/cn/elasticsearch/guide/current/_indexing_employee_documents.html
https://segmentfault.com/a/1190000020140461
Docker Elasticsearch
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。