[TOC] # 1. ElasticSearch简介 ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。ElasticSearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。官方客户端在Java、.NET(C#)、PHP、Python、Apache Groovy、Ruby和许多其他语言中都是可用的。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr,也是基于Lucene。 ElasticSearch 是一个分布式、高扩展、高实时的搜索与数据分析引擎,其应用范围非常广泛。它能很方便的使大量数据具有搜索、分析和探索的能力。充分利用ElasticSearch的水平伸缩性,能使数据在生产环境变得更有价值。ElasticSearch 的实现原理主要分为以下几个步骤,首先用户将数据提交到Elastic Search 数据库中,再通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据,当用户搜索数据时候,再根据权重将结果排名,打分,最后将返回结果呈现给用户。 # 2. ElasticSearch安装与配置 ## 2.1 下载安装包 ElasticSearch目前支持Linux、Windows、MacOS操作系统,最新版还支持docker、rpm、msi、deb、brew等安装方式。具体安装包的下载地址请参考:https://www.elastic.co/cn/downloads/elasticsearch ## 2.2 各平台的安装说明 截止目前,最新ES(ElasticSearch)的版本是7.4.2,以下安装说明在elastic官网上如有调整,请参考7.4版本的文档进行操作。需要强调的是ES更新的速度较快,是名副其实的版本帝,确定了使用某个版本,请保存好安装包以及相关的插件,确保后期集群扩展、安装调试等工作能顺利进行。之前介绍中已经说明ES是基于java语言的,请在安装之前配置好java的运行环境,当前最低java版本要求是JDK8,JDK下载地址:https://www.oracle.com/technetwork/java/javase/downloads/index.html 由于平台较多,本文档不具体介绍某个操作系统的安装,具体请参考官方的安装说明。 Linux或MacOS安装:https://www.elastic.co/guide/en/elasticsearch/reference/current/targz.html Windows安装(ZIP方式):https://www.elastic.co/guide/en/elasticsearch/reference/current/zip-windows.html Windows安装(msi方式,需要 至少需要.NET 4.5 framework以上版本的软件支持):https://www.elastic.co/guide/en/elasticsearch/reference/current/windows.html deb安装方式(支持Debian, Ubuntu等):https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html rpm安装方式(支持Red Hat, Centos, SLES, OpenSuSE等):https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html docker安装方式:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html MacOS安装(Homebrew方式):https://www.elastic.co/guide/en/elasticsearch/reference/current/brew.html 如果版本发生变化,请进入以下地址: [https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html "https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html") 选择您要查阅的版本号,具体请参考如下面的2张图: ![]( https://private-showapi.oss-cn-hangzhou.aliyuncs.com/doc/elastic/2019-11-06_104417.jpg) ![]( https://private-showapi.oss-cn-hangzhou.aliyuncs.com/doc/elastic/2019-11-06_104418.jpg) ## 2.3安装IK中文分词插件(可选) 先下载分词:https://github.com/medcl/elasticsearch-analysis-ik/releases IK的安装说明和使用帮助:https://github.com/medcl/elasticsearch-analysis-ik ## 2.4开启用户名密码访问 1. 修改config目录下面的elasticsearch.yml文件,在里面添加如下内容,并重启: xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true 2. 在安装目录的/bin文件夹下,执行如下命令,根据提示调整elastic, kibana等6个账号的用户名密码: bin/elasticsearch-setup-passwords interactive 3. 在Chrome下安装elastic数据查询管理插件:ElasticSearch Head 安装好后,可以使用浏览器操作您的ElasticSearch了,具体操作界面如下: ![]( https://private-showapi.oss-cn-hangzhou.aliyuncs.com/doc/elastic/2019-11-06_104419.jpg)