专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

Docker系列之Elasticsearch安装教程

@TOC

50_1.png

1、什么Elasticsearch?

Elasticsearch是一款开源的分布式搜索引擎,基于 JSON 开发而来,具有 RESTful 风格,基于 Apache Lucene 的基础上开发而成的

引用官网的说法:

50_2.png

官方文档已经做了比较详细的介绍,所以本博客不做详细介绍,只介绍,基于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

50_3.png运行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

50_4.png浏览器直接访问也是可以的: http://your_ip_addr:920050_5.png

3、目录结构

50_6.png

目录 配置文件 描述
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

50_7.png启动容器

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

50_8.png50_9.png可能遇到问题:

  • 点连接后台报错,可能是不支持跨域访问,需要设置跨域
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

附录:参考资料 www.elastic.co/guide/en/el…

www.lixueduan.com/post/elasti…

www.elastic.co/guide/cn/el…

segmentfault.com/a/119000002…

文章永久链接:https://tech.souyunku.com/26820

未经允许不得转载:搜云库技术团队 » Docker系列之Elasticsearch安装教程

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们