Docker系列之Elasticsearch安装教程

网友投稿 485 2022-05-29

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

Docker系列之Elasticsearch安装教程

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小时内删除侵权内容。

上一篇:ps命令使用详解
下一篇:华为云企业主机安全 3+3步开启防护
相关文章