flume 入门 实时监控目录下的多个追加文件,并上传至 HDFS(四)

需求

在这里插入图片描述
在这里插入图片描述

配置conf

vim dir-hdfs-tail.conf
# Name the components on this agent
a4.sources = r4
a4.sinks = k4
a4.channels = c4

# Describe/configure the source
a4.sources.r4.type = TAILDIR
a4.sources.r4.positionFile = /flume-tail/tail_dir.json
a4.sources.r4.filegroups = f1 f2
a4.sources.r4.filegroups.f1 = /flume-tail/files/.*file.*
a4.sources.r4.filegroups.f2 = /flume-tail/files2/.*log.*

# Describe the sink
a4.sinks.k4.type = hdfs
a4.sinks.k4.hdfs.path = hdfs://hadoop100:9000/flume/dir-tail/%Y%m%d/%H
#上传文件的前缀
a4.sinks.k4.hdfs.filePrefix = dir-tail-
#是否按照时间滚动文件夹
a4.sinks.k4.hdfs.round = true
#多少时间单位创建一个新的文件夹
a4.sinks.k4.hdfs.roundValue = 1
#重新定义时间单位
a4.sinks.k4.hdfs.roundUnit = hour
#是否使用本地时间戳
a4.sinks.k4.hdfs.useLocalTimeStamp = true
#积攒多少个 Event 才 flush 到 HDFS 一次
a4.sinks.k4.hdfs.batchSize = 100
#设置文件类型,可支持压缩
a4.sinks.k4.hdfs.fileType = DataStream
#多久生成一个新的文件
a4.sinks.k4.hdfs.rollInterval = 20
#设置每个文件的滚动大小
a4.sinks.k4.hdfs.rollSize = 134217700
#文件的滚动与 Event 数量无关
a4.sinks.k4.hdfs.rollCount = 0

# Use a channel which buffers events in memory
a4.channels.c4.type = memory
a4.channels.c4.capacity = 1000
a4.channels.c4.transactionCapacity = 100

# Bind the source and sink to the channel
a4.sources.r4.channels = c4
a4.sinks.k4.channel = c4

在这里插入图片描述

启动

 bin/flume-ng agent --name a4 --conf-file job/dir-hdfs-tail.conf -Dflume.foot.logger=INFO,console

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

Taildir 说明:

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
利用FLUME实时读取目录文件HDFS的步骤如下: 1. 首先需要在Flume的conf目录下创建一个新的配置文件,例如my_flume.conf。 2. 在my_flume.conf文件中,需要定义Flume的agent名称以及其它设置,比如数据源、数据目的地、数据处理管道等。例如: ``` # Define an agent named Agent1 agent1.sources = source1 agent1.sinks = sink1 agent1.channels = channel1 # Define a memory channel called channel1 agent1.channels.channel1.type = memory # Define a source that reads files from a directory agent1.sources.source1.type = spooldir agent1.sources.source1.spoolDir = /path/to/spool/directory # Define a sink that writes to HDFS agent1.sinks.sink1.type = hdfs agent1.sinks.sink1.hdfs.path = hdfs://localhost:9000/flume/events agent1.sinks.sink1.hdfs.filePrefix = events- agent1.sinks.sink1.hdfs.fileSuffix = .log agent1.sinks.sink1.hdfs.rollInterval = 3600 agent1.sinks.sink1.hdfs.rollSize = 0 agent1.sinks.sink1.hdfs.rollCount = 10000 # Bind the source and sink to the channel agent1.sources.source1.channels = channel1 agent1.sinks.sink1.channel = channel1 ``` 在这个配置文件中,我们定义了一个名为Agent1的Flume agent,它包含一个source、一个sink和一个channel。source定义了要读取的文件目录,sink定义了数据写入的HDFS路径和文件名的前缀、后缀等信息,而channel则定义了source和sink之间的数据传输通道。 3. 启动Flume agent。在命令行中输入以下命令: ``` bin/flume-ng agent --conf conf --conf-file my_flume.conf --name agent1 -Dflume.root.logger=INFO,console ``` 启动后,Flume将开始读取指定目录下的文件,并将其实时写入HDFS。 注意:在实际使用中,还需要根据具体情况对Flume的配置文件进行调整和优化,以满足实际需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值