三剑客:Elastic Stackhtml
在学习ELK前,先对 Lucene做基本了解。java
今天才知道关系型数据库的索引是 B-Tree,罪过...node
原始数据基础查询 + 原始数据聚合查询git
核心:反向倒排索引github
//关键词 document ---> term ---> posting list<docid> term dictionary ---> term index
联合索引查询正则表达式
关于二者的性能比较,参见:Frame of Reference and Roaring Bitmaps 算法
Nested Document数据库
按期行数据合并:子文档 ---> 父文档npm
DocValuesbootstrap
主存储按列组织,随机读操做很快
时间序列数据库秘密:https://segmentfault.com/a/1190000003502849?mType=Group
基于Lucene实现,接近实时(NRT,Near Realtime)的搜索平台,基于 JSON的分布式搜索和分析引擎
官网:https://www.520mwx.com/view/44635
从5.x支持拆分红text和keyword,在6.x废弃string 在7.x废弃TransportClient,建议High-level-rest-client 在7.x使用默认的_doc做为type,在8.x移除type 从7.x默认节点名称为主机名,分片数改成1 在7.x默认自带jdk 从7.x Kibana支持全局开启“黑暗”模式 从7.x时间戳从毫秒级支持至纳秒级
关于7.x版本参见:Elastic Stack 7.0.0, Breaking changes in 7.0
ES每日持续性能监控:https://benchmarks.elastic.co/index.html
基本概念
关系数据库 --> 数据库 --> 表 --> 行(Rows) --> 列(Columns) Elasticsearch --> 索引(Index) --> 类型(type) --> 文档(Docments) --> 字段(Fields)
其中,document 是能够被索引的基本信息单元,Index 名字务必小写 。
最佳场景:一、检索 二、统计监控 三、(日志)分析
docid --> block --> Segment --> Shards/Replicas --> Index
分片 shards:
复制 replicas:
默认状况下,Elasticsearch中的每一个索引配置5个主分片和每一个分片的1个复制。
节点数 <= 主分片数 *(副本数+1)
Mapping映射
动态映射 --> 定制映射
mapping一经建立没法修改,若要修改需从新创建索引和定义映射,具体方法:
step1.给现有索引定义别名,并把现有索引指向该别名,PUT /现有索引/_alias/别名A
step2.新建立一个索引,定义新的映射关系
step3.将别名指向新的索引,而且取消以前索引的执行
POST /_aliases { "actions":[ {"remove": { "index": "现有索引名", "alias":"别名A" }}, {"add" : { "index": "新建索引名", "alias":"别名A" }} ] }
性能:实现索引的平滑过渡,而且是零停机。
索引+检索
精髓:一切设计都是为了提升搜索的性能
强烈推荐:Elasticsearch 的性能优化,亿级 Elasticsearch 性能优化
Pipeline Aggregation
先了解下聚合
可优化网络传输量
Pipeline Aggregation 做为聚合的 plus版本
elasticsearch安装
推荐 ES 6.x版本,暂用 -v6.8.0 & -v6.2.0
鉴于 .net Framework生产最高 4.6,也采用 ES v6.2.0版本
同时考虑 Java技术栈中 NodeClient已过时,当前流行的 Transport Client在 7.x版本开始将再也不支持
运行:elasticsearch.bat
9300:java/.Net 程序访问的端口(tcp) 9200:浏览器、postman 访问端口(http)
默认 ES只容许本机访问,修改 config/elasticsearch.yml文件,修改 network.host
为 0.0.0.0或指定IP,再重启便可
建议在文件最后新增以下配置
http.cors.enabled: true //是否支持跨域
http.cors.allow-origin: "*" //支持全部域名 (以上2个配置解决:使用 Head 插件链接不上集群)
node.master: true
node.data: true
注意,根据规划 ES 6.x版每一个 Index只容许包含一个 Type,7.x版将会完全移除 Type:Removal of mapping types
若遇报错
ERROR: bootstrap checks failed system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
则在配置文件中新增
bootstrap.memory_lock: false bootstrap.system_call_filter: false
经常使用命令
http://localhost:9200/_cat/indices?v //当前结点的全部Index http://localhost:9200/_mapping?pretty=true //当前Index包含的全部Type http://ip:9200/_nodes #查看节点信息 http://ip:9200/_template #查看模板 GET /Index/Type/_search?pretty #返回索引记录,默认size=10 GET /index_name/_mapping/type_name #查询映射 GET /index_Name/_mapping #获取映射关系 GET /_all/_mapping/ #获取集群内的全部映射关系
安装教程:http://www.javashuo.com/article/p-dqhvkyhe-nn.html
elasticsearch-head插件
下载地址:https://github.com/mobz/elasticsearch-head
在 Gruntfile.js的 connect配置项中新增 hostname:'*',
注意,es5 以上版本安装 head须要安装 node和 grunt
重点了解下grunt
JavaScript 任务运行器,基于 Node.js的项目构建工具,能够进行打包压缩、测试、执行等工做
npm install -g grunt-cli #全局安装 grunt -version #查看版本号
head 插件经过 grunt 启动。
安装教程:http://www.javashuo.com/article/p-gmyswcin-mb.html
head/_site/app.js 下配置修改
#这里改为es的IP和端口 this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://99.6.150.141:9200";
暂时未用到,先 mark 备用。
安装:npm install 运行:grunt server 或 npm run start
安装时若出现 FetchError: request to https://registry.npmjs.com/grunt-karma failed,reason connect EACCES 104.16.27.35:443
解决:更新npm:npm install -g npm
若出现 notarget No matching version found for grunt-karma@2.0.0
解决:从新安装grunt
若出现 error phantomjs-prebuilt@2.1.16 install: 'node install.js'
解决:执行npm install -g phantomjs-prebuilt@2.1.16 --ignore-scrip
相关信息可参考:npm install error | stackoverflow
至于出现 Local Npm module "grunt-contrib-jasmine" not found. Is it installed?
解决:能够忽略,尚不影响使用,也能够安装 npm install grunt-contrib-jasmine解决
注意,出现 connect EACCES 或 connect ETIMEDOUT,优先启用重试大法命令。
安装教程:http://www.javashuo.com/article/p-wdbumflm-dy.html
ik分词器
ES 内置分词器(standard、simple)效果不理想,推荐插件安装:IK Analyzer v3.0
选择与 ES配套的版本便可,下载地址,或选择其余分词器 smartcn
重命名为 ik,放在 elasticsearch\plugins 目录下重启 es 便可
分词在线测试地址:grokdebug
注意,ES中一个字段不能同时支持全文和聚合搜索,除非采用以下方式
"url": { "type": "string", "analyzer": "simple", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } },
基本使用
几个重要的配置
# (master_eligible_nodes / 2) + 1 discovery.zen.minimum_master_nodes:集群主节点最小可见数量,为提升集群的可用性,避免集群脑裂 discovery.zen.ping.unicast.hosts:节点发现机制,unicast通讯方式 discovery.zen.ping_timeout:发现过程当中的等待时间,默认3秒
动态数据收集管道,日志解析引擎,拥有可扩展的插件生态系统。
官网:https://www.elastic.co/cn/products/logstash
下载版本与 es一致便可:下载地址
安装教程:
filter的ruby插件待学习...
基本使用
Shipper Logstash --> Redis --> Indexer Logstash --> Elasticsearch
分析和可视化平台。
官网:https://www.elastic.co/cn/products/kibana
安装
默认 Kibana只容许本机访问,修改 config/kibana.yml文件,修改 server.host 为 0.0.0.0或指定IP,再重启便可
http://ip:5601/app/kibana#/home/tutorial_directory/sampleData?_g=() #添加kibana样例数据
参考教程:
基本使用
REST访问模式:<REST Verb>/<Index>/<Type>/<ID>
http://localhost:5601/status #状态信息 GET /_cat/health?v #集群健康信息 GET /_cat/nodes?v #集群中结点列表 GET /_cat/indices?v #集群中索引列表
建议入库 ES 的对象包含 Date 字段,不然 Create Index Pattern 时无可用字段可选,报错
The indices which match this index pattern don't contain any time fields.
问题解决
按{"type":"string","index":"not_analyzed"}设置mapping时,报错: Elasticsearch:No handler for type [string] declared on field[XXX]
缘由:Elasticsearch从5.X引入
text"
和"
keyword"
用于分词和全词匹配,从6.X完全移除"string",且"index"值只能是boolean变量:string类型已死, 字符串数据永生。"
若容许该字段被索引查询,需{"type":"text","index":true},不然会报错:Cannot search on field [xxx] since it is not indexed.
关于ES中的数据类型,参见:Field datatypes
X-Pack
ElasticSearch 扩展包
cerebro
elasticsearch 开源监控软件,替代 kopf(http://99.6.150.141:9200/_plugin/kopf/#!/cluster)
下载地址:cerebro | github
es-rally
ES性能监控工具
[使用教程](https://blog.csdn.net/laoyang360/article/details/52155481)
其余工具使用
Grafana:适合监控类场景 ElasticHD:支持SQL转DSL elasticsearch-SQL:类SQL查询工具 测试工具:在原来执行的DSL的基础上新增profile参数 "profile": true