自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Apache Flume之正則過濾器

大數(shù)據(jù)
在當今的大數(shù)據(jù)世界中,應用程序產(chǎn)生大量的電子數(shù)據(jù) – 這些巨大的電子數(shù)據(jù)存儲庫包含了有價值的、寶貴的信息。 對于人類分析師或領(lǐng)域?qū)<?,很難做出有趣的發(fā)現(xiàn)或?qū)ふ铱梢詭椭鷽Q策過程的模式。 我們需要自動化的流程來有效地利用龐大的,信息豐富的數(shù)據(jù)進行規(guī)劃和投資決策。 在處理數(shù)據(jù)之前,收集數(shù)據(jù),聚合和轉(zhuǎn)換數(shù)據(jù)是絕對必要的,并最終將數(shù)據(jù)移動到那些使用不同分析和數(shù)據(jù)挖掘工具的存儲庫中。

Apache Flume之正則過濾器

在當今的大數(shù)據(jù)世界中,應用程序產(chǎn)生大量的電子數(shù)據(jù) – 這些巨大的電子數(shù)據(jù)存儲庫包含了有價值的、寶貴的信息。 對于人類分析師或領(lǐng)域?qū)<遥茈y做出有趣的發(fā)現(xiàn)或?qū)ふ铱梢詭椭鷽Q策過程的模式。 我們需要自動化的流程來有效地利用龐大的,信息豐富的數(shù)據(jù)進行規(guī)劃和投資決策。 在處理數(shù)據(jù)之前,收集數(shù)據(jù),聚合和轉(zhuǎn)換數(shù)據(jù)是絕對必要的,并最終將數(shù)據(jù)移動到那些使用不同分析和數(shù)據(jù)挖掘工具的存儲庫中。

執(zhí)行所有這些步驟的流行工具之一是Apache Flume。 這些數(shù)據(jù)通常是以事件或日志的形式存儲。 Apache Flume有三個主要組件:

  • Source:數(shù)據(jù)源可以是企業(yè)服務器,文件系統(tǒng),云端,數(shù)據(jù)存儲庫等。
  • Sink:Sink是可以存儲數(shù)據(jù)的目標存儲庫。 它可以是一個集中的地方,如HDFS,像Apache Spark這樣的處理引擎,或像ElasticSearch這樣的數(shù)據(jù)存儲庫/搜索引擎。
  • Channel:在事件被sink消耗前由Channel 存儲。 Channel 是被動存儲。 Channel 支持故障恢復和高可靠性; Channel 示例是由本地文件系統(tǒng)和基于內(nèi)存的Channel 支持的文件通道。

Flume是高度可配置的,并且支持許多源,channel,serializer和sink。它還支持數(shù)據(jù)流。 Flume的強大功能是攔截器,支持在運行中修改/刪除事件的功能。支持的攔截器之一是regex_filter。

regex_filter將事件體解釋為文本,并將其與提供的正則表達式進行對比,并基于匹配的模式和表達式,包括或排除事件。我們將詳細看看regex_filter。

要求

從數(shù)據(jù)源中,我們以街道號,名稱,城市和角色的形式獲取數(shù)據(jù)?,F(xiàn)在,數(shù)據(jù)源可能是實時流數(shù)據(jù),也可能是任何其他來源。在本示例中,我已經(jīng)使用Netcat服務作為偵聽給定端口的源,并將每行文本轉(zhuǎn)換為事件。要求以文本格式將數(shù)據(jù)保存到HDFS中。在將數(shù)據(jù)保存到HDFS之前,必須根據(jù)角色對數(shù)據(jù)進行過濾。只有經(jīng)理的記錄需要存儲在HDFS中;其他角色的數(shù)據(jù)必須被忽略。例如,允許以下數(shù)據(jù):

  1. 1,alok,mumbai,manager 
  2.  
  3. 2,jatin,chennai,manager  

下列的數(shù)據(jù)是不被允許的:

  1. 3,yogesh,kolkata,developer 
  2.  
  3. 5,jyotsana,pune,developer  

如何達到這個要求

可以通過使用 regex_filter 攔截器來實現(xiàn)。這個攔截器將根據(jù)規(guī)則基礎(chǔ)來進行事件過濾,只有感興趣的事件才會發(fā)送到對應的槽中,同時忽略其他的事件。

  1. ## Describe regex_filter interceptor and configure exclude events attribute 
  2.  
  3. a1.sources.r1.interceptors = i1 
  4.  
  5. a1.sources.r1.interceptors.i1.type = regex_filter 
  6.  
  7. a1.sources.r1.interceptors.i1.regex = developer 
  8.  
  9. a1.sources.r1.interceptors.i1.excludeEvents = true  

HDFS 槽允許數(shù)據(jù)存儲在 HDFS 中,使用文本/序列格式。也可以使用壓縮格式存儲。

  1. a1.channels = c1 
  2.  
  3. a1.sinks = k1 
  4.  
  5. a1.sinks.k1.type = hdfs 
  6.  
  7. a1.sinks.k1.channel = c1 
  8.  
  9. ## assumption is that Hadoop is CDH 
  10.  
  11. a1.sinks.k1.hdfs.path = hdfs://quickstart.cloudera:8020/user/hive/warehouse/managers 
  12.  
  13. a1.sinks.k1.hdfs.fileType= DataStream 
  14.  
  15. a1.sinks.k1.hdfs.writeFormat = Text  

如何運行示例

首先,你需要 Hadoop 來讓示例作為 HDFS 的槽來運行。如果你沒有一個 Hadoop 集群,可以將槽改為日志,然后只需要啟動 Flume。 在某個目錄下存儲 regex_filter_flume_conf.conf 文件然后使用如下命令運行代理。

  1. flume-ng agent --conf conf --conf-file regex_filter_flume_conf.conf --name a1 -Dflume.root.logger=INFO,console 

注意代理名稱是 a1。我用了 Netcat 這個源。

  1. a1.sources.r1.type = netcat 
  2.  
  3. a1.sources.r1.bind = localhost 
  4.  
  5. a1.sources.r1.port = 44444  

一旦 Flume 代理啟動,運行下面命令用來發(fā)送事件給 Flume。

  1. telnet localhost 40000 

現(xiàn)在我們只需要提供如下輸入文本:

  1. 1,alok,mumbai,manager 
  2.  
  3. 2,jatin,chennai,manager 
  4.  
  5. 3,yogesh,kolkata,developer 
  6.  
  7. 4,ragini,delhi,manager 
  8.  
  9. 5,jyotsana,pune,developer 
  10.  
  11. 6,valmiki,banglore,manager  

訪問 HDFS 你會觀察到 HDFS 在 hdfs://quickstart.cloudera:8020/user/hive/warehouse/managers 下創(chuàng)建了一個文件,文件只包含經(jīng)理的數(shù)據(jù)。

完整的 flume 配置 — regex_filter_flume_conf.conf — 如下:

  1. Name the components on this agent 
  2.  
  3. a1.sources = r1 
  4.  
  5. a1.sinks = k1 
  6.  
  7. a1.channels = c1 
  8.  
  9. # Describe/configure the source - netcat 
  10.  
  11. a1.sources.r1.type = netcat 
  12.  
  13. a1.sources.r1.bind = localhost 
  14.  
  15. a1.sources.r1.port = 44444 
  16.  
  17. # Describe the HDFS sink 
  18.  
  19. a1.channels = c1 
  20.  
  21. a1.sinks = k1 
  22.  
  23. a1.sinks.k1.type = hdfs 
  24.  
  25. a1.sinks.k1.channel = c1 
  26.  
  27. a1.sinks.k1.hdfs.path = hdfs://quickstart.cloudera:8020/user/hive/warehouse/managers 
  28.  
  29. a1.sinks.k1.hdfs.fileType= DataStream 
  30.  
  31. a1.sinks.k1.hdfs.writeFormat = Text 
  32.  
  33. ## Describe regex_filter interceptor and configure exclude events attribute 
  34.  
  35. a1.sources.r1.interceptors = i1 
  36.  
  37. a1.sources.r1.interceptors.i1.type = regex_filter 
  38.  
  39. a1.sources.r1.interceptors.i1.regex = developer 
  40.  
  41. a1.sources.r1.interceptors.i1.excludeEvents = true 
  42.  
  43. # Use a channel which buffers events in memory 
  44.  
  45. a1.channels.c1.type = memory 
  46.  
  47. a1.channels.c1.capacity = 1000 
  48.  
  49. a1.channels.c1.transactionCapacity = 100 
  50.  
  51. # Bind the source and sink to the channel 
  52.  
  53. a1.sources.r1.channels = c1 
  54.  
  55. a1.sinks.k1.channel = c1  

完整的項目代碼請看 這里。 

責任編輯:龐桂玉 來源: 36大數(shù)據(jù)
相關(guān)推薦

2021-07-05 15:22:03

Servlet過濾器客戶端

2024-01-05 09:04:35

隆過濾器數(shù)據(jù)結(jié)構(gòu)哈希函數(shù)

2024-11-04 08:45:48

布隆過濾器元數(shù)據(jù)指紋值

2009-07-08 15:30:56

Servlet過濾器

2009-07-08 16:07:04

Servlet過濾器配

2009-09-29 13:55:23

Hibernate設(shè)置

2009-07-14 09:09:08

Swing模型過濾器

2011-06-29 16:14:59

Qt 事件 過濾器

2022-05-13 08:23:07

Zuul微服務Zuul過濾器

2011-03-07 09:33:18

FileZilla

2009-06-18 10:13:00

Hibernate過濾

2025-04-21 00:50:50

2009-07-08 17:33:37

Servlet過濾器

2009-09-25 15:19:44

Hibernate過濾

2021-02-20 08:41:51

Wireshark

2009-07-06 13:02:49

Servlet過濾器

2024-03-15 11:21:22

布隆過濾器數(shù)據(jù)庫數(shù)據(jù)

2023-01-26 01:41:27

核心全局過濾器

2016-12-07 09:56:13

JavaFilter過濾器

2010-03-01 14:45:07

Linux文件重定向
點贊
收藏

51CTO技術(shù)棧公眾號