Docker系列之Elasticsearch安裝教程


@

在這里插入圖片描述

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

需要加上版本,不加版本默認是laster(最新)版本,貌似沒提供laster版本

docker pull elasticsearch:7.2.0

查看所有鏡像:

docker images

在這里插入圖片描述
運行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

linux內用curl訪問:

curl http://localhost:9200

在這里插入圖片描述
瀏覽器直接訪問也是可以的:http://your_ip_addr:9200
在這里插入圖片描述

3、目錄結構

在這里插入圖片描述

目錄 配置文件 描述
bin 腳本文件,包括啟動 Elasticsearch、安裝插件,運行統計數據等。
config elasticsearch.yml 集群配置文件
JDK Java 運行環境
data path.data 數據文件
lib Java 類庫
logs path.logs 日志文件
modules 包含所有 ES 模塊
plugins 包含所有已安裝插件

4、常用命令

  • _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

  • ?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
  • 其它常用命令:

    • 查看所有插件: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  
  • h參數
    h 參數,可以指定輸出的字段
[root@localhost ~]# curl localhost:9200/_cat/master?h=host,ip,node
172.17.0.2 172.17.0.2 7610b4e6e11b

5、插件安裝

插件安裝可以用elasticsearch-plugin install url命令

比如安裝:elasticsearch-analysis-ik

docker進入容器命令,id為9689b3dc982e

docker exec -it 9689b3dc982e /bin/bash

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 

6、elasticsearch-head

elasticsearch-head是用於Elasticsearch監控的插件

鏡像 pull

docker pull mobz/elasticsearch-head:5

在這里插入圖片描述
啟動容器

docker run -d -p 9100:9100 docker.io/mobz/elasticsearch-head:5

在這里插入圖片描述
在這里插入圖片描述
可能遇到問題:

  • 點連接后台報錯,可能是不支持跨域訪問,需要設置跨域
cd /usr/share/elasticsearch/config/
vi elasticsearch.yml

在elasticsearch.yml的文件末尾加上:

http.cors.enabled : true
http.cors.allow-origin : "*"
  • 遇到 max virtual memory areas vm.maxmapcount [65530] is too low 報錯,可以執行下述命令
sysctl -w vm.max_map_count=262144

附錄:參考資料
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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM