设置Flume监听文件内容

本文介绍如何配置Flume实现实时监控并采集Linux文件中的新增内容,直接写入HDFS。通过具体配置示例,展示如何利用Flume的tail命令实现对文件更新的实时跟踪。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

应用场景

按照Hadoop完全分布式安装Flume博文,测试使用了Flume监听文件夹,当文件夹中添加了文件,Flume设置会立马进行收集文件夹中的添加的文件,那么这是一种应用场景,但是如果我们想收集文件中的内容,该如何办呢?比如,linux目录下有一个文件,我会往这个文件里不断的新增内容,那么怎么才能实时写入到HDFS呢?

操作方案

Hadoop完全分布式安装Flume博文,中监控文件夹,如果linux目录的文件夹下,有文件添加,那么会自动采集到HDFS目录,如果需要监控具体的文件内容,如果该文件中有数据更新,那么需要修改flume-conf.properties文件为如下,其他不变!

 # cd /opt/flume1.7.0/conf
 # vim flume-conf.properties

# a.conf: A single-node Flume configuration
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = exec 
a1.sources.r1.command = tail -F /opt/log/exec.text
a1.sources.r1.fileHeader = true
a1.sources.r1.deserializer.outputCharset=UTF-8
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://hadoop0:9000/log
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.writeFormat=Text
a1.sinks.k1.hdfs.maxOpenFiles = 1
a1.sinks.k1.hdfs.rollCount = 0
a1.sinks.k1.hdfs.rollInterval = 0
a1.sinks.k1.hdfs.rollSize = 1000000
a1.sinks.k1.hdfs.batchSize = 100000
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000000
a1.channels.c1.transactionCapacity = 100000
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
 # cd /opt/flume1.7.0/
 # bin/flume-ng agent --conf conf --conf-file conf/flume-conf.properties --name a1 -Dflume.root.logger=INFO,console
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值