@
Elasticsearch是一款开源的分布式搜索引擎,基于 JSON 开发而来,具有 RESTful 风格,基于 Apache Lucene 的基础上开发而成的
引用官网的说法:
官方文档已经做了比较详细的介绍,所以本博客不做详细介绍,只介绍,基于docker的Elasticsearch安装部署
环境准备:
相关工具软件:
docker入门博客可以参考我的docker系统博客专栏:链接
docker镜像搜索:
docker search elasticsearch
需要加上版本,不加版本默认是laster(最新)版本,貌似没提供laster版本
docker pull elasticsearch:7.2.0
查看所有镜像:
docker images
运行docker镜像:
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
目录 | 配置文件 | 描述 |
---|---|---|
bin | 脚本文件,包括启动 Elasticsearch、安装插件,运行统计数据等。 | |
config | elasticsearch.yml | 集群配置文件 |
JDK | Java 运行环境 | |
data | path.data | 数据文件 |
lib | Java 类库 | |
logs | path.logs | 日志文件 |
modules | 包含所有 ES 模块 | |
plugins | 包含所有已安装插件 |
[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
[root@localhost ~]# curl localhost:9200/_cat/master?v
id host ip node
8x63m-D8Q2CP4xRbq7rEFA 172.17.0.2 172.17.0.2 7610b4e6e11b
其它常用命令:
help参数
help 参数,来输出可以显示的列
[root@localhost ~]# curl localhost:9200/_cat/master?help
id | | node id
host | h | host name
ip | | ip address
node | n | node name
[root@localhost ~]# curl localhost:9200/_cat/master?h=host,ip,node
172.17.0.2 172.17.0.2 7610b4e6e11b
插件安装可以用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
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 : "*"
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
原文:https://www.cnblogs.com/mzq123/p/13301715.html