Fork me on GitHub

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

posted @ 2020-07-14 21:12  smileNicky  阅读(927)  评论(0编辑  收藏  举报