介绍
- 基于Lucene 的高扩展的分布式搜索服务器,支持开箱即用
- 隐藏了 Lucene 的复杂性,对外提供 RestFul 接口操作索引、搜索
- 优点:
- 扩展性好,可部署上百台服务器集群,处理PB级数据
- 近实时的去索引数据,搜索数据
- 支持全文检索
原理
逻辑结构 ==> 倒排索引表:
将要搜索的文档内容分词,所有不重复的词组成分词列表
将搜索的文档最终以Document方式存储
每个词和document都有关联
示例:
安装
jdk 1.8 以上
支持 tar、zip、rpm等多种安装方式
windows下开发建议使用 ZIP 安装支持 docker 安装
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-linux-x86_64.tar.gz
tar -avxf elasticsearch-7.6.2-linux-x86_64.tar.gz -C /home/morr/
cd elasticsearch-7.6.2 > mkdir data
vim config/elasticsearch.yml
// 关闭防火墙
systemctl stop firewalld.service
// 禁止防火墙开机启动
systemctl disable firewalld.service
// 创建es用户
useradd es
passwd es
// 把目录权限赋予给es用户
chown -R es /home/morr/elasticsearch-7.6.2
// 切换至es用户
su es
vi /usr/local/elasticsearch-6.2.4/config/elasticsearch.yml
sh /usr/local/elasticsearch-6.2.4/bin/elasticsearch
vim /etc/security/limits.conf
vim /etc/security/limits.d/20-nproc.conf
vim /etc/sysctl.conf
跨域问题
es.yml配置文件
http.cors.enabled: true
http.cors.allow-origin: "*"
目录结构
bin: 脚本目录,启动、停止等可执行脚本
config: 配置文件
data: 索引目录,存放索引文件
logs: 日志目录
modules: 模块目录,包含es的功能模块
plugins: 插件目录,es 支持插件机制
配置文件
zip、tar: config
RPM: /etc/elasticsearch
elasticsearch.yml
配置运行参数
配置方式:层次方式、属性方式:
path: data: /var/lib/elasticsearch logs:/var/log/elasticsearch
path.data: /var/lib/elasticsearch path.logs:/var/log/elasticsearchjvm.options
配置Elasticsearch JVM
设置最小、最大的JVM堆内存:
-Xms 和 -Xmx
两个值设置为相等,Xmx 设置为不超过物理内存的一半log4j2.properties
配置日志
启动ES
cd bin > elasticsearch.bat
插件安装
head 插件是一个可视化管理插件,监视ES状态,并通过head客户端和ES服务进行交互
下载head并运行
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start