头歌flume拦截器答案

文章详细介绍了如何配置Flume进行数据拦截与处理,包括使用avro源和正则表达式拦截器筛选以y.开头的事件,将数据存储到HDFS,并设置文件滚动策略。此外,还展示了如何创建自定义拦截器`RegexExtractorExtInterceptor`,从文件头中提取信息并添加到事件头中,以及配置Flume从指定目录读取文件并按特定格式存储到HDFS。
摘要由CSDN通过智能技术生成

第一关Flume拦截器的使用


start-dfs.sh
hadoop dfs -mkdir /flume

 


# Define source, channel, sink
#agent名称为a1


# Define source
#source类型配置为avro,监听8888端口,后台会自动发送数据到该端口
#拦截后台发送过来的数据,将y.开头的保留下来


# Define channel
#channel配置为memery


# Define sink
#落地到 hdfs://localhost:9000/flume目录下
#根据时间落地,3s
#数据格式DataStream


a1.sources = source1
a1.sinks = sink1
a1.channels = channel1
 
# 配置source组件
a1.sources.source1.type = avro
a1.sources.source1.bind  = 127.0.0.1
    a1.sources.source1.port  =  8888
##定义文件上传完后的后缀,默认是.COMPLETED
a1.sources.source1.fileSuffix=.FINISHED
##默认是2048,如果文件行数据量超过2048字节(1k),会被截断,导致数据丢失
a1.sources.source1.deserializer.maxLineLength=5120
 #正则过滤拦截器

a1.sources.source1.interceptors = i1

a1.sources.source1.interceptors.i1.type = regex_filter

a1.sources.source1.interceptors.i1.regex = ^y.*

#如果excludeEvents设为false,表示过滤掉不是以A开头的events。

#如果excludeEvents设为true,则表示过滤掉以A开头的events。

a1.sources.source1.interceptors.i1.excludeEvents = false
# 配置sink组件
a1.sinks.sink1.type = hdfs
a1.sinks.sink1.hdfs.path =hdfs://localhost:9000/flume
#上传文件的前缀
a1.sinks.sink1.hdfs.filePrefix = FlumeData.
#上传文件的后缀
a1.sinks.sink1.hdfs.fileSuffix = .log
#积攒多少个Event才flush到HDFS一次
a1.sinks.sink1.hdfs.batchSize= 100
a1.sinks.sink1.hdfs.fileType = DataStream
a1.sinks.sink1.hdfs.writeFormat =Text
 
## roll:滚动切换:控制写文件的切换规则
## 按文件体积(字节)来切
a1.sinks.sink1.hdfs.rollSize = 512000
## 按event条数切   
a1.sinks.sink1.hdfs.rollCount = 1000000
## 按时间间隔切换文件,多久生成一个新的文件
a1.sinks.sink1.hdfs.rollInterval = 4
 
## 控制生成目录的规则
a1.sinks.sink1.hdfs.round = true
##多少时间单位创建一个新的文件夹
a1.sinks.sink1.hdfs.roundValue = 10
a1.sinks.sink1.hdfs.roundUnit = minute
 
#是否使用本地时间戳
a1.sinks.sink1.hdfs.useLocalTimeStamp = true
 
# channel组件配置
a1.channels.channel1.type = memory
## event条数
a1.channels.channel1.capacity = 500000
##flume事务控制所需要的缓存容量600条event
a1.channels.channel1.transactionCapacity = 600
 
# 绑定source、channel和sink之间的连接
a1.sources.source1.channels = channel1
a1.sinks.sink1.channel = channel1
 

第二关 Flume自定义拦截器

 Flume1/flume.conf配置文件

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required b

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值