Elasticsearch、Logstash、Kibana

学会ELK Stack的日志框架

文档更新于: 2022-8-4 16:06

第 1 章 概述

1.1 Elasticsearch 的安装和简单配置

1.1.1 安装

Elasticsearch 的安装非常简单,只需要到官网下载压缩包解压即可。

前提是先下载 JDK ,并配置响应的环境变量,同时系统可用内存大于2GB。

在7.8 版本中的 Elasticsearch 自带了 JDK,也可以使用自带的 JDK。

Elasticsearch 下载网站

可以到 Github 上面下载 RTF 版本(Ready To Fly:集成了很多中文插件,但是版本有点老)。

目录结构如下

img

  • bin——含有运行 Elasticsearch 实例和管理插件的一些脚本。
  • config——主要是一些设置文件,如: elasticsearch.yml 和 logging.yml 等。
  • lib——包含一些相关的包文件等。
  • plugins——包含相关的插件文件等。
  • logs——日志文件。
  • data——Elasticsearch 中存放数据的地方。
  • works——临时文件。

Tips:

如果 Elasticsearch 运行在专用服务器上,一般经验是分配一定的内存给 Elasticsearch ,可以通过修改 ES_HEAP_SIZE 环境变量来改变这个设定,它控制堆大小。在启动 Elasticsearch 之前应该把这个变量改到预期值。关于这个数据的设置可参见相关手册。一般来说,如果在日志文件中发现带有 OutOfMemoryError 错误的输出记录,则应考虑将环境变量 ES_HEAP_SIZE 取值调大﹐建议该值不应超过总可用物理内存的50%(剩余内存可用作高速缓存,提高检索性能),这样可以极大地提高搜索性能。

1.1.2分词器

可选择 Elasticsearch 使用的中文分词器 IK。

到 Github 下载压缩包,解压到 plugins 文件夹,重命名 ik 即可

img

分词器测试

1
2
3
4
5
6
7
8
### 1.没有安装分词
POST http://localhost:9200/index3/_analyze
Content-Type: application/json

{
"text": "中国上海市",
"analyzer": "standard"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
"tokens": [
{
"token": "中",
"start_offset": 0,
"end_offset": 1,
"type": "<IDEOGRAPHIC>",
"position": 0
},
{
"token": "国",
"start_offset": 1,
"end_offset": 2,
"type": "<IDEOGRAPHIC>",
"position": 1
},
{
"token": "上",
"start_offset": 2,
"end_offset": 3,
"type": "<IDEOGRAPHIC>",
"position": 2
},
{
"token": "海",
"start_offset": 3,
"end_offset": 4,
"type": "<IDEOGRAPHIC>",
"position": 3
},
{
"token": "市",
"start_offset": 4,
"end_offset": 5,
"type": "<IDEOGRAPHIC>",
"position": 4
}
]
}
1
2
3
4
5
6
7
8
### 2.使用IK分词器的ik_smart,分词力度粗
POST http://localhost:9200/index3/_analyze
Content-Type: application/json

{
"text": "中国上海市",
"analyzer": "ik_smart"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"tokens": [
{
"token": "中国",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "上海市",
"start_offset": 2,
"end_offset": 5,
"type": "CN_WORD",
"position": 1
}
]
}
1
2
3
4
5
6
7
8
### 使用IK分词器的ik_max_word,分词力度细(推荐)
POST http://localhost:9200/index3/_analyze
Content-Type: application/json

{
"text": "中国上海市",
"analyzer": "ik_max_word"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
"tokens": [
{
"token": "中国",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 0
},
{
"token": "上海市",
"start_offset": 2,
"end_offset": 5,
"type": "CN_WORD",
"position": 1
},
{
"token": "上海",
"start_offset": 2,
"end_offset": 4,
"type": "CN_WORD",
"position": 2
},
{
"token": "海市",
"start_offset": 3,
"end_offset": 5,
"type": "CN_WORD",
"position": 3
}
]
}

1.1.3 shutdown

想要关闭 elasticsearch 客户端(默认 9200 端口),可在shell环境中输入命令

1
curl -xPOST http://localhost:9200/_cluster/nodes/_shutdown

1.2 走近 Elasticsearch

1.2.1 Elasticsearch 是什么

1.2.2 Elasticsearch 中涉及到的相关概念

1.2.3 Elasticsearch API 的简单使用方式

1.2.4 Elasticsearch RTF 版本中的部分插件简介

1.2.5 Elasticsearch 基本架构

1.3 Elasticsearch 索引及其构建

1.3.1 概述

1.3.2 借助 Head 工具构建索引

1.3.3 Mapping 简述

1.4 信息检索及其构建

1.5 实例

1.6 扩展知识与阅读

1.7 本章小结


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!