Qwen3 惊喜上线阿里云百炼,8款模型全开源!点击免费领取 800万 tokens! 了解详情
写点什么

海量日志架构中的后端数据处理技术对比

  • 2018-05-03
  • 本文字数:8189 字

    阅读完需:约 27 分钟

随着 ELK 技术的普及,Elasticsearch 所提供的强大搜索、分析功能给大家处理各种类型的海量数据提供了可能。随之而来的是如何将各种类型的海量数据以一种通用、便捷、高效的方式进入到 ES 供其使用。传统的 logstash 具备这方面的能力,但由于其固有的缺陷无法避免,导致其处理性能较低,难于开发调试。

我们迫切需要一种通用的数据处理方式,实现从数据源到 ES 的全流程处理,最终需要达到:

  1. 通用性:接口丰富、有流程控制、数据类型转换、数据加工
  2. 易开发:便于快速开发调试
  3. 易管理:容易发现数据问题,性能瓶颈,清晰的流程
  4. 高性能:对数据处理有较高的吞吐量,较低的资源消耗

当然我们可以开发特定的 Spark Streaming 应用来实现数据到 ES 的流转,但从通用性、易用性方面来看,由于条件所限,这种方法代价较高,周期长,且性能、稳定性较难保证。

因此我们选用几种数据通用处理方法进行测试,对比各自的优缺点,发现他们所适应的场景:

  1. filebeat+ingest node

  2. logstash

  3. Apache Nifi

  4. Streamsets Data Collector(SDC)

  5. 测试简单 Apache 日志,普适于一般日志数据解析

a) 使用同一份 Apache access log 数据作为测试样本

b) 进行简单数据模式匹配,使用统一的 COMBINEDAPACHELOG grok pattern 对数据进行解析,将结果输入 ES

  1. 测试复杂 json 结构的 Twitter 数据,对其字段进行转换、计算、筛选等处理,应对复杂、大结构的数据处理

a) 使用同一份 Twitter 的 json 数据作为测试样本

b) 由于原始的 Twitter 数据为非标准 json 数据,因此在对 nifi 进行处理之前先将其处理为标准的 json array 数据,生成数据文件 tweet.nifi.json

  1. 每个测试重复三次,记录完成时间及相关运行指标
  2. 对于 ES 的性能数据收集采用 kibana 中自带的 monitoring 模块监控对应的 index
  3. 对于操作系统的性能数据收集采用 metricbeat,然后采用其自带的 template 在 kibana 中展现

3.1. 软硬件环境

  1. 虚拟机 VMware® Workstation 10.0.1 build-1379776
  2. Ubuntu 16.04.1 LTS Linux version 4.4.0-59-generic
  3. 2 CPU/10G MEM
  4. ELK 6.2.2 + xpack + 2 nodes
  5. Apache Nifi 1.5.0
  6. SDC 3.1.0.0

3.2. 数据准备

1、测试所用 Apache 日志数据来源于 http://www.secrepo.com

也可以使用日志生成器来生成数据:

https://github.com/kiritbasu/Fake-Apache-Log-Generator

2、测试所用 Twitter 数据来源于 Twitter 官网,通过 Python 脚本下载

详见:

https://github.com/zhan-yl/ELK-inputprocess-test/tree/master/log_tools

使用方式:

python2.7 tweet.py @realDonaldTrump

python2.7 tweet.py @BBCWorld

python2.7 tweet.py @BBCBreaking

python2.7 tweet.py @TIME

python2.7 tweet.py @PDChina

python2.7 tweet.py @CNN

python2.7 tweet.py @CBSNews

python2.7 tweet.py @ elastic

python2.7 tweet.py @golang

python2.7 tweet.py @Docker

python2.7 tweet.py @streamsets

生成的日志文件为:

-rw-rw-r-- 1 zhanyl zhanyl 277508582 4 月 2 10:11 tweet.json

-rw-rw-r-- 1 zhanyl zhanyl 277561344 4 月 2 15:56 tweet.nifi.json

3.3. 环境配置

3.3.1. Apache 日志测试

3.3.1.1. Filebeat+ingest node

  1. 建立 ingest 的 pipeline

  2. Filebeat 配置文件

3.3.1.2. Logstash

1、 建立配置文件

3.3.1.3. Apache nifi

1、 导入 template

详见:

https://github.com/zhan-yl/ELK-inputprocess-test/tree/master/nifi_config

2、 说明

为了避免 OutOfMemoryError 和同时打开大量的文件,在流程里面采用了多个 split text 串联的方式予以解决。

同时在流程中未加入对于 geo 的地址解析。

在 NIFI中对于 Java heap和文件句柄的使用是一个需要谨慎处理的问题。

3.3.1.4. SDC

1、 导入 pipeline

详见:

https://github.com/zhan-yl/ELK-inputprocess-test/tree/master/sdc_config

3.3.2. Twitter 日志测试

3.3.2.1. Filebaet+ingest node

由于对数据的加工处理较为复杂,不对该类型进行测试

3.3.2.2. Logstash

虽然可以通过 filter plugin 进行相关类似的操作,但由于操作复杂、调试困难,不对该类型进行测试

3.3.2.3. Apache nifi

1. 导入 template

详见:

https://github.com/zhan-yl/ELK-inputprocess-test/tree/master/nifi_config

2. 说明

由于下载的 Twitter 数据非标准 json 格式,因此在测试之前使用 sed 首先将其转换为标准 json array 数据,便于数据分割。

同时在流程中未加入对于 geo 的地址解析。

3.3.2.3. SDC

1. 导入 pipeline

详见:

https://github.com/zhan-yl/ELK-inputprocess-test/tree/master/sdc_config

4.1. Apache 日志测试

4.1.1. Filebeat+ingest node

4.1.1.1. 执行命令

初始化文件信息,便于重复执行

rm /var/lib/filebeat/registry

启动:

/usr/share/filebeat/bin/filebeat -c /etc/filebeat/filebeat_secrepo.yml -path.home /usr/share/filebeat -path.config /etc/filebeat -path.data /var/lib/filebeat -path.logs /var/log/filebeat

4.1.1.2. 数据监控

1、 数据总量

897123

2、 完成时间

开始时间

结束时间

耗时(单位:分钟)

1

10:20

10:40

20

2

10:45

11:03

18

3

11:05

11:24

19

3、 性能图表

a) ES 性能

b) 操作系统性能

c) ES 数据样本

复制代码
{
"_index": "ingest-pipeline",
"_type": "doc",
"_id": "5AZoLmIBmeYOsZrYcv72",
"_version": 1,
"_score": null,
"_source": {
"request": "/twitter-icon.png",
"geoip": {
"continent_name": "Asia",
"city_name": "Attock",
"country_iso_code": "PK",
"region_name": "Punjab",
"location": {
"lon": 72.3873,
"lat": 33.5937
}
},
"offset": 8706062,
"auth": "-",
"ident": "-",
"verb": "GET",
"source": "/home/zhanyl/examples-master/Graph/apache_logs_security_analysis/data/access.log",
"message": "103.255.6.250 - - [09/Mar/2018:02:24:56 -0800] \"GET /twitter-icon.png HTTP/1.1\" 200 27787 \"http://www.secrepo.com/\" \"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0\" ",
"referrer": "\"http://www.secrepo.com/\"",
"@timestamp": "2018-03-09T10:24:56.000Z",
"response": "200",
"bytes": "27787",
"clientip": "103.255.6.250",
"beat": {
"hostname": "zylxpack",
"name": "zylxpack",
"version": "6.2.2"
},
"httpversion": "1.1",
"user_agent": {
"major": "58",
"minor": "0",
"os": "Ubuntu",
"name": "Firefox",
"os_name": "Ubuntu",
"device": "Other"
}
},
"fields": {
"@timestamp": [
"2018-03-09T10:24:56.000Z"
]
},
"sort": [
1520591096000
]
}

4.1.2. Logstash

4.1.2.1. 执行命令

初始化文件信息,便于重复执行:

rm /data/logstash/.sincedb

启动:

/usr/share/logstash/bin/logstash -f /home/zhanyl/examples-master/Graph/apache_logs_security_analysis/logstash/secrepo_logstash.conf --path.settings=/etc/logstash --path.data /data/logstash

4.1.2.2. 数据监控

1、 数据总量

897123

2、 完成时间

开始时间

结束时间

耗时(单位:分钟)

1

13:43

13:54

11

2

14:00

14:11

11

3

14:13

14:24

11

3、 性能图表

a) ES 性能

b) 操作系统性能

c) ES 数据样本

复制代码
{
"_index": "secrepo-logstash",
"_type": "doc",
"_id": "vVswKGIBmeYOsZrYlb8C",
"_version": 1,
"_score": null,
"_source": {
"geoip": {
"city_name": "Islamabad",
"continent_code": "AS",
"timezone": "Asia/Karachi",
"longitude": 73.0113,
"latitude": 33.6957,
"country_name": "Pakistan",
"region_code": "IS",
"ip": "103.255.6.250",
"postal_code": "44000",
"country_code2": "PK",
"region_name": "Islamabad Capital Territory",
"country_code3": "PK",
"location": {
"lon": 73.0113,
"lat": 33.6957
}
},
"os_name": "Ubuntu",
"device": "Other",
"message": "103.255.6.250 - - [09/Mar/2018:02:24:56 -0800] \"GET /twitter-icon.png HTTP/1.1\" 200 27787 \"http://www.secrepo.com/\" \"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0\" ",
"path": "/home/zhanyl/examples-master/Graph/apache_logs_security_analysis/data/access.log",
"major": "58",
"@timestamp": "2018-03-09T10:24:56.000Z",
"referrer": "\"http://www.secrepo.com/\"",
"clientip": "103.255.6.250",
"verb": "GET",
"minor": "0",
"os": "Ubuntu",
"request": "/twitter-icon.png",
"@version": "1",
"host": "zylxpack",
"build": "",
"ident": "-",
"auth": "-",
"response": "200",
"httpversion": "1.1",
"bytes": "27787",
"name": "Firefox"
},
"fields": {
"@timestamp": [
"2018-03-09T10:24:56.000Z"
]
},
"sort": [
1520591096000
]
}

4.1.3. Apache nifi

4.1.3.1. 执行命令

初始化文件信息,便于重复执行:

启动:

选中相关的process,然后点击run

4.1.3.2. 数据监控

1、 数据总量

897123

2、 完成时间

开始时间

结束时间

耗时(单位:分钟)

1

14:08

14:34

26

2

14:38

15:07

29

3

15:08

15:37

29

3、 性能图表

a) ES 性能

b) 操作系统性能

c) ES 数据样本

复制代码
{
"_index": "nifi",
"_type": "nifi",
"_id": "C5XrLGIBmeYOsZrYiU7w",
"_version": 1,
"_score": null,
"_source": {
"clientip": "103.255.6.250",
"ident": "-",
"auth": "-",
"verb": "GET",
"request": "/twitter-icon.png",
"httpversion": "1.1",
"rawrequest": null,
"response": 200,
"bytes": 27787,
"referrer": "http://www.secrepo.com/",
"agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0",
"@timestamp": "2018-03-09T10:24:56.000Z"
},
"fields": {
"@timestamp": [
"2018-03-09T10:24:56.000Z"
]
},
"sort": [
1520591096000
]
}

4.1.4. SDC

4.1.4.1. 执行命令

建立 mapping。

注:如果 @timestamp 给出的是标准的 timestamp 字符串而不是 timestamp 类型则可以不建 mapping,可以动态生成

PUT /sdc

{
“mappings”: {
“sdc”: {
“properties”: {
“@timestamp”: {
“type”: “date”
},
“geo”: {
“type”: “geo_point”
},
“city”: {
“type”: “text”,
“index”: false
}
}
}
}
}

初始化文件信息,便于重复执行:

启动:

4.1.4.2. 数据监控

1、 数据总量

897070

缺少的 53 条记录是由于无法解析其地理位置而导致失败,如:

clientip :193.200.150.82

clientip :193.200.150.152

Address ‘91.197.234.102’

Address ‘103.234.188.37’

2、 完成时间

开始时间

结束时间

耗时(单位:分钟)

1

16:13

16:29

16

2

16:32

16:43

11

3

16:45

16:59

14

在第三次测试中出现 exception,但并未中断处理

3、 性能图表

a) ES 性能

b) 操作系统性能

c) ES 数据样本

复制代码
{
"_index": "sdc",
"_type": "sdc",
"_id": "Wur8LWIBmeYOsZrYnL-S",
"_version": 1,
"_score": null,
"_source": {
"request": "/twitter-icon.png",
"agent": "\"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0\"",
"auth": "-",
"ident": "-",
"verb": "GET",
"referrer": "\"http://www.secrepo.com/\"",
"response": 200,
"bytes": 27787,
"clientip": "103.255.6.250",
"httpversion": "1.1",
"rawrequest": null,
"geo": {
"lat": 33.6957,
"lon": 73.0113
},
"@timestamp": 1520591096000,
"city": "Islamabad"
},
"fields": {
"@timestamp": [
"2018-03-09T10:24:56.000Z"
]
},
"sort": [
1520591096000
]
}

4.2. Twitter 日志测试

4.2.1. Apache nifi

4.2.1.1. 执行命令

初始化文件信息,便于重复执行:

启动

选中相关的process,然后点击run

4.2.1.2. 数据监控

1、 数据总量

52759

2、 完成时间

开始时间

结束时间

耗时(单位:分钟)

1

20:12

20:17

5

2

20:18

20:22

4

3

20:23

20:27

4

3、 性能图表

a) ES 性能

b) 操作系统性能

c) ES 数据样本

复制代码
{
"_index": "twitter-nifi",
"_type": "doc",
"_id": "u7NThmIBROKaR930KYYi",
"_version": 1,
"_score": null,
"_source": {
"geo": null,
"id": 980626639842357200,
"id_str": "980626639842357249",
"lang": "en",
"user_mentions": [],
"favorite_count": 23,
"favorited": false,
"retweet_count": 25,
"text": "Cops: Man arrested with weapons cache, bump stock claimed secret government mission https://t.co/XaHdZOmV8z https://t.co/N3ca4nAUSv",
"user": {
"contributors_enabled": false,
"created_at": "Thu Jun 05 00:54:31 +0000 2008",
"default_profile": false,
"default_profile_image": false,
"description": "Your source for original reporting and trusted news.",
"entities": {
"description": {
"urls": []
},
"url": {
"urls": [
{
"display_url": "CBSNews.com",
"expanded_url": "http://CBSNews.com",
"indices": [
0,
23
],
"url": "https://t.co/VGut7r2Vg5"
}
]
}
},
"favourites_count": 270,
"follow_request_sent": false,
"followers_count": 6490476,
"following": false,
"friends_count": 431,
"geo_enabled": false,
"has_extended_profile": false,
"id": 15012486,
"id_str": "15012486",
"is_translation_enabled": true,
"is_translator": false,
"lang": "en",
"listed_count": 47812,
"location": "New York, NY",
"name": "CBS News",
"notifications": false,
"profile_background_color": "D9DADA",
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/736106551/37bf1f784305fe4a9c7e9105772c6e1a.jpeg",
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/736106551/37bf1f784305fe4a9c7e9105772c6e1a.jpeg",
"profile_background_tile": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/15012486/1519827973",
"profile_image_url": "http://pbs.twimg.com/profile_images/645966750941626368/d0Q4voGK_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/645966750941626368/d0Q4voGK_normal.jpg",
"profile_link_color": "B12124",
"profile_sidebar_border_color": "FFFFFF",
"profile_sidebar_fill_color": "EAEDF0",
"profile_text_color": "000000",
"profile_use_background_image": true,
"protected": false,
"screen_name": "CBSNews",
"statuses_count": 168688,
"time_zone": "Eastern Time (US & Canada)",
"translator_type": "none",
"url": "https://t.co/VGut7r2Vg5",
"utc_offset": -14400,
"verified": true
},
"created_at": "Mon Apr 02 02:03:04 +0000 2018",
"place": null,
"total_count": 48,
"@timestamp": "2018-04-02T02:03:04.000Z"
},
"fields": {
"@timestamp": [
"2018-04-02T02:03:04.000Z"
]
},
"sort": [
1522634584000
]
}

4.2.2. SDC

4.2.2.1. 执行命令

初始化文件信息,便于重复执行:

启动:

4.2.2.2. 数据监控

1、 数据总量

52759

2、 完成时间

开始时间

结束时间

耗时(单位:分钟)

1

21:00

21:05

5

2

21:06

21:12

6

3

21:13

21:18

5

3、 性能图表

d) ES 性能

e) 操作系统性能

f) ES 数据样本

复制代码
{
"_index": "twitter-sdc",
"_type": "doc",
"_id": "VbVuhmIBROKaR930GV0_",
"_version": 1,
"_score": null,
"_source": {
"created_at": "Mon Apr 02 02:03:04 +0000 2018",
"entities": {
"user_mentions": []
},
"favorite_count": 23,
"favorited": false,
"geo": null,
"id": 980626639842357200,
"id_str": "980626639842357249",
"lang": "en",
"place": null,
"retweet_count": 25,
"text": "Cops: Man arrested with weapons cache, bump stock claimed secret government mission https://t.co/XaHdZOmV8z https://t.co/N3ca4nAUSv",
"user": {
"description": "Your source for original reporting and trusted news.",
"favourites_count": 270,
"followers_count": 6490476,
"friends_count": 431,
"id": 15012486,
"location": "New York, NY",
"name": "CBS News"
},
"@timestamp": "2018-04-02T10:03:04.000+08",
"lat": null,
"lon": null,
"total_count": 48
},
"fields": {
"@timestamp": [
"2018-04-02T02:03:04.000Z"
]
},
"sort": [
1522634584000
]
}

5.1. 数据结果

在最终数据进入 ES 以后,虽然记录数相等,但是数据的大小存在差异,所记录的内容也存在差异,这也是导致执行时间存在差异的原因

5.2. 对比

5.2.1. Filebeat+ingest node

1、 优点

a) 比较轻量级,对系统资源消耗较少

b) Ingest node 内置于 ES 集群内部,无需额外部署

c) 通过简单的 json 语句即可实现 pipeline 处理

2、 缺点

a) 所支持的功能有限,仅能对简单数据进行处理。能够处理的功能集,现阶段仅为 logstash 的子集

b) Ingest node 本身不具备自主 pull 数据的功能,需要其他工具将数据写入。如果部署在 kafka 后端,则必须部署能够配合其数据写入的工具

c) 不支持可视化

5.2.2. Logstash

1、 优点

a) 有丰富的 plugin 进行各种数据加工、处理

b) 有大量的接口支持,技术较为成熟

2、 缺点

a) 开发、调试、跟踪困难,无法可视化呈现

b) 对于较为复杂的数据结构处理较难实现,会依赖于嵌套 ruby 来处理

c) 无法进行可视化监控发现性能瓶颈,新的 kibana pipeline 在一定程度上缓解该问题

5.2.3. Apache nifi

1、 优点

a) 可图形化编辑、监控整个处理流程

b) 可进行单步调试,在上一个处理环节得出正确结果以后再进入下一个处理环节。可以通过 Data Provenance 追踪数据的完整处理过程。

c) 对数据有 back pressure 机制

d) 在运行过程中可随时修改流程中的各个处理环节,调整资源使用量而不必中断整个流程

e) 有丰富的接口及数据处理机制(expression language),数据类型转换机制

f) 拥有 rest 接口,通过该接口可进行进一步应用开发

g) 由于使用文件作为载体,对所处理数据的大小基本无限制

h) 对于大数据结构、批量数据处理具有一定优势

2、 缺点

a) 由于使用文件,文件需要落地并频繁地打开、关闭,性能较低,需要依靠较高性能的磁盘设备

b) 同时对于内存的消耗较大,由其是生成大量 attribute 的情况下。极易造成 OOM。

c) 对于能够同时打开文件的个数要求也较严格,需要设置较高的 fileno

5.2.4. SDC

1、 优点

a) 可视化处理、对各环节都有监控指标展现

b) 可预览数据处理过程、检查数据处理结果

c) 拥有多种处理 process 和 package,可形成复杂的处理 pipeline,可使用 expression language、groovy、JavaScript、jyphon 等

d) 拥有 rest 接口,直接调用,也通过该接口可进行进一步应用开发

e) 自带异常告警机制

f) 由于在内存中按照批量进行处理,因此处理性能较高

g) 对于小数据结构、实时数据处理具有一定优势

2、 缺点

a) 由于在内存中进行数据处理,为避免 OOM,对处理的 event 大小有限制,其 buffer 大小限制为 1048576 字节,超出部分将会被截断

b) 不能进行单步调用调试,无法在 pipeline 运行过程中干预其处理

作者介绍

詹玉林,中国民生银行系统管理中心大数据工程师,曾作为研发工程师开发过银行核心系统,IBM 数据库支持工程师,现关注于大数据的实时解决方案。

2018-05-03 18:2212522

评论

发布
暂无评论
发现更多内容

如何更改 datax 以支持hive 的 DECIMAL 数据类型?

明哥的IT随笔

hadoop hive

【设计模式】-创建型模式-第2章第1讲-【单例模式】

跟着飞哥学编程

设计模式 单例模式 java 编程 11月月更

前台小姐姐是如何转行测试,从月薪3000到月薪15K,实现逆袭

千锋IT教育

基于BPMN2.0的业务流程引擎

GFE

前端 BPMN 流程引擎

量化合约系统开发逻辑篡改方案

I8O28578624

“鸿蒙生态专家面对面”技术交流会,专家齐聚,等你前来!

HarmonyOS开发者

HarmonyOS

测试小白到月薪30K+的测试大佬学习路线图

千锋IT教育

vue3实战-完全掌握ref、reactive

yyds2026

几个你必须知道的React错误实践

xiaofeng

React

Python 实现栈的几种方式及其优劣

宇宙之一粟

Python 数据结构 11月月更

pyside6 qml 自定义边框

Mr_No爱学习

公链defi质押挖矿分红dapp系统开发(合约定制)

开发微hkkf5566

Backdrop Filter

肥晨

css3 css特效 11月月更 css滤镜

【解决】前端开发中的5大痛点

GFE

前端

vue中的几个高级概念

yyds2026

Vue

用git上传项目到GitHub或者码云全过程

肥晨

代码上传 githun 11月月更 Git上传

11月必须要了解的一项福利

夏夜许游

AI 双十一 视觉智能

Ten Million-Level Capacity Storage Solution of Student Management System - Examination

David

架构实战营

从事分布式工作10余年,这本书颠覆了我的认知!

博文视点Broadview

币安DAPP系统开发技术概念及篡改逻辑

I8O28578624

CSS3渐变-快来感受CSS的伟大吧(差点闪瞎我的狗眼)

肥晨

11月月更 css3渐变 conic-gradient

即时通讯技术文集(第4期):不为人知的网络编程 [共14篇]

JackJiang

vue实战-完全掌握Vue自定义指令

yyds2026

Vue

Zepoch节点已售出500+,Zebec Chain市场反响激烈

鳄鱼视界

开源!非凸Rust高性能日志库ftlog

非凸科技

Wallys/Qualcomm IPQ5018 solution application wifi6 , support M.2 Card Slot for QCN9074 WIFI 6E Card

Cindy-wallys

802.11AX WIFI 6e ipq5018

计算机网络:电路、报文与分组交换

timerring

计算机网络 11月月更

升级到React-Router-v6

xiaofeng

React

你要的react+ts最佳实践指南

xiaofeng

React

一路同行,再聚乌镇 | 旺链科技与你相约世界互联网大会

旺链科技

产业区块链 世界互联网大会 乌镇 企业号十月PK榜

科普 | 关于NFT的概念、价值及应用

NFT Research

海量日志架构中的后端数据处理技术对比_DevOps & 平台工程_詹玉林_InfoQ精选文章