【Linux】【elasticsearch】docker部署elasticsearch及elasticsearch-head

前言

  Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎。不管在开源仍是专有领域,Lucene能够被认为是迄今为止最早进、性能最好的、功能最全的搜索引擎库。可是,Lucene只是一个库。想要使用它,你必须使用Java来做为开发语言并将其直接集成到你的应用中,更糟糕的是,Lucene很是复杂,你须要深刻了解检索的相关知识来理解它是如何工做的。Elasticsearch也使用Java开发并使用Lucene做为其核心来实现全部索引和搜索的功能,可是它的目的是经过简单的RESTful API来隐藏Lucene的复杂性,从而让全文搜索变得简单。html

  不过,Elasticsearch不单单是Lucene和全文搜索,咱们还能这样去描述它:node

  -分布式的实时文件存储,每一个字段都被索引并可被搜索   -分布式的实时分析搜索引擎   -能够扩展到上百台服务器,处理PB级结构化或非结构化数据

  并且,全部的这些功能被集成到一个服务里面,你的应用能够经过简单的RESTful API、各类语言的客户端甚至命令行与之交互。web

  ElasticSearch-head 是一个web端的ElasticSearch管理工具。docker

安装

1、docker安装Elasticsearch

1.docker拉取Elasticsearch镜像跨域

https://www.docker.elastic.co/ 选择适用的版本。这里选择6.3.2浏览器

 

docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2

 若是docker pull error,请添加国内镜像加速源,参考:http://www.javashuo.com/article/p-hjkpulhp-ko.htmlbash

 1 # 拉取镜像  2 [root@localhost ~]# docker pull docker.elastic.co/elasticsearch/elasticsearch:6.3.2  3 6.3.2: Pulling from elasticsearch/elasticsearch  4 7dc0dca2b151: Pull complete  5 72d60ff53590: Pull complete  6 ca55c9f7cc1f: Pull complete  7 822d6592a660: Pull complete  8 22eceb1ece84: Pull complete  9 30e73cf19e42: Pull complete 10 f05e800ca884: Pull complete 11 3e6ee2f75301: Pull complete 12 Digest: sha256:8f06aecf7227dbc67ee62d8d05db680f8a29d0296ecd74c60d21f1fe665e04b0 13 Status: Downloaded newer image for docker.elastic.co/elasticsearch/elasticsearch:6.3.2 14 # 查看镜像 15 [root@localhost ~]# docker images 16 REPOSITORY TAG IMAGE ID CREATED SIZE 17 docker.elastic.co/elasticsearch/elasticsearch 6.3.2 96dd1575de0f 14 months ago 826MB

2.运行容器服务器

docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2

-p 9200 9300:映射虚拟机端口到宿主机端口app

  9200 http协议,为elasticsearch默认端口,用于外部通信。cors

  9300 tcp协议,用于集群之间通讯。.

-e 设置elasticsearch为单节点启动

1 # 启动容器 2 [root@localhost ~]# docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.3.2 3 af895f4ddc62a981c72217f547a2a67fea9695b5b113c4317a1965cc76153bd4 4 # 查看容器 5 [root@localhost ~]# docker ps 6 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7 af895f4ddc62        docker.elastic.co/elasticsearch/elasticsearch:6.3.2   "/usr/local/bin/dock…"   4 seconds ago       Up 3 seconds        0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp es

3.设置跨域

 1 # 进入es容器,es为容器的name,bash为命令行  2 [root@localhost ~]# docker exec -it es bash  3 # 查看文件  4 [root@af895f4ddc62 elasticsearch]# ls  5 LICENSE.txt README.textile config lib modules  6 NOTICE.txt bin data logs plugins  7 # 进入elasticsearch的配置文件夹  8 [root@af895f4ddc62 elasticsearch]# cd config  9 [root@af895f4ddc62 config]# ls 10 elasticsearch.keystore ingest-geoip log4j2.properties roles.yml users_roles 11 elasticsearch.yml jvm.options role_mapping.yml users 12 # 修改elasticsearch的配置文件 13 [root@af895f4ddc62 config]# vi elasticsearch.yml 14 # 增长跨域配置 15  http.cors.enabled: true 16  http.cors.allow-origin: "*" 17 # :wq保存 18 # exit退出容器 19 [root@af895f4ddc62 config]# exit 20 exit 21 # 重启es容器 22 [root@localhost ~]# docker restart es 23 es
# curl "http://localhost:9200" { "name" : "rSLhlFi", "cluster_name" : "docker-cluster", "cluster_uuid" : "QTLXwiz_Sx-udJAofc2RIQ", "version" : { "number" : "6.3.2", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "053779d", "build_date" : "2018-07-20T05:20:23.451332Z", "build_snapshot" : false, "lucene_version" : "7.3.1", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }

2、docker安装Elasticsearch-head

1.docker search elasticsearch-head搜索镜像

  • docker search elasticsearch-head

2.拉取 mobz/elasticsearch-head 镜像

  • docker pull mobz/elasticsearch-head:5

3.运行容器

  • docker run -d --name es_admin -p 9000:9100 mobz/elasticsearch-head:5

因为我宿主机9100端口被占用,因此这里将容器的9100端口映射到宿主机的9000端口

4.访问elasticsearch-head

浏览器打开http://192.168.8.10:9000/

相关文章
相关标签/搜索