Flume监听文件目录sink至hdfs配置

本文介绍Flume日志采集系统的配置与使用方法,包括配置文件解析、启动命令及常见问题解决。Flume能够从不同源收集数据,并将数据传输至指定目标,适用于日志文件的实时采集。

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

一:flume介绍

        Flume是一个分布式、可靠、和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方(可定制)的能力。,Flume架构分为三个部分 源-Source,接收器-Sink,通道-Channel

 

二:配置文件

    此配置文件source为一个目录,注意,该目录下的文件应为只读,不可写,且文件名不能相同,采用的channels为file,sink为hdfs,此处往hdfs写的策略是当时间达到3600s或者文件大小达到128M。

agent1.sources = spooldirSource
agent1.channels = fileChannel
agent1.sinks = hdfsSink

agent1.sources.spooldirSource.type=spooldir
agent1.sources.spooldirSource.spoolDir=/home/duanxz/flume/scan_logs
agent1.sources.spooldirSource.channels=fileChannel

agent1.sinks.hdfsSink.type=hdfs
agent1.sinks.hdfsSink.hdfs.path=hdfs://192.168.1.105:9000/import/flume/%y-%m-%d
agent1.sinks.hdfsSink.hdfs.filePrefix=flume
agent1.sinks.sink1.hdfs.round = true
# Number of seconds to wait before rolling current file (0 = never roll based on time interval)
agent1.sinks.hdfsSink.hdfs.rollInterval = 3600
# File size to trigger roll, in bytes (0: never roll based on file size)
agent1.sinks.hdfsSink.hdfs.rollSize = 128000000
agent1.sinks.hdfsSink.hdfs.rollCount = 0
agent1.sinks.hdfsSink.hdfs.batchSize = 1000

#Rounded down to the highest multiple of this (in the unit configured using hdfs.roundUnit), less than current time.
agent1.sinks.hdfsSink.hdfs.roundValue = 1
agent1.sinks.hdfsSink.hdfs.roundUnit = minute
agent1.sinks.hdfsSink.hdfs.useLocalTimeStamp = true
agent1.sinks.hdfsSink.channel=fileChannel
agent1.sinks.hdfsSink.hdfs.fileType = DataStream


agent1.channels.fileChannel.type = file
agent1.channels.fileChannel.checkpointDir=/home/duanxz/flume/apache-flume-1.5.0-bin/checkpoint
agent1.channels.fileChannel.dataDirs=/home/duanxz/flume/apache-flume-1.5.0-bin/dataDir

 

三:启动命令

duanxz@three:~/flume/apache-flume-1.8.0-bin/bin$ ./flume-ng agent --conf ../conf/ -f ../conf/flume_hdfs.conf -Dflume.root.logger=DEBUG,console -n agent1

四、查看结果:

或者通过hadoop的shell命令行查看文件如下:

 

 

Q:启动flume后,控制台上输出warning信息:No configuration found for this host:flume-hdfs

原因:flume启动时,如果没有通过参数(--name 或者 - n)指定代理,那么默认使用flume-hdfs作为代理名称,启动成功后,不会报错,但是可能会提示如题警告。

 

Q:flume启动后,好像没有正常工作,查看日志,看到flume启动报错:org.apache.commons.cli.MissingOptionException: Missing required option: n

解决方案:agent启动时需要用-n参数指定agent的名字(用于跟flume配置中的agent名字对应上)

 

如果Flume监听文件完成之后,HDFS并未接收到数据,可能有以下几个原因: 1. **配置文件不正确**[^1]: 检查`flume-file-hdfs.conf`中的source(源)、sink(目的地)设置是否正确,比如Source应配置为读取指定文件,Sink配置为将数据发送至HDFS。 ```yaml .sources = source1 sinks = sink1 channels = channel1 sources.source1.type = file sources.source1.file.filename = <your_file_path> sources.source1.file.channels = channel1 sinks.sink1.type = hdfs sinks.sink1.hdfs.path = <hdfs_directory> sinks.sink1.hdfs.rollCount = 1 ``` 2. **权限问题**: 确认Flume进程是否有足够的权限访问源文件和写入HDFS。可能是文件权限不够,或者是HDFS客户端配置错误。 3. **数据流异常**[^2]: 如果`flume-hdfs.conf`配置的是追加模式(`-Dflume.root.logger=INFO,console`),可能是因为程序运行时并没有开启agent,或者agent在写入数据之前就已经关闭了。 4. **网络问题**: 检查网络连接是否稳定,以及Hadoop集群是否正常运行。如果Flume AgentHDFS服务器之间的通信有问题,数据可能会丢失或无法到达。 5. **Agent启动方式**: 确认Flume Agent是否按照正确的命令行参数启动,如 `-conf-file job/flume-file-hdfs.conf` 和 `-name a1` 是否匹配配置文件名称。 要解决这个问题,你可以按照以下步骤排查: 1. 查看Flume日志以寻找错误信息。 2. 确认配置文件中的文件路径和HDFS路径是否正确。 3. 检查网络状态和代理之间的通信是否畅通。 4. 启动Agent时确保使用的配置文件与实际配置一致。 5. 如果是在追加模式下,确认数据已经写入到本地文件并且Flume Agent已启动并正在监视该文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值