You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Flume Agent无法将Netcat数据写入HDFS求助

Flume Agent数据写入HDFS失败排查及修复

以下是配置中的核心问题及修复方案:

1. HDFS Sink参数错误

配置中使用了不存在的参数hdfs.fileStream,正确参数名为hdfs.fileType,这个错误会导致HDFS Sink无法初始化文件写入逻辑,是数据无法落地的关键原因。

修复后的sink配置:

a1.sinks.k1.type=hdfs
a1.sinks.k1.hdfs.path=hdfs://localhost:8020/manager
a1.sinks.k1.hdfs.writeFormat=Text
a1.sinks.k1.hdfs.fileType=DataStream

a1.sinks.k2.type=hdfs
a1.sinks.k2.hdfs.path=hdfs://localhost:8020/developer
a1.sinks.k2.hdfs.writeFormat=Text
a1.sinks.k2.hdfs.fileType=DataStream

2. 多路选择器缺少默认通道

当前仅映射了行首为1和2的情况,但需求是行首非1都存入developer目录,需添加默认通道处理所有未匹配规则的事件(如行首为3、4等数字或非数字开头的行),否则这些事件会被直接丢弃。

添加配置:

a1.sources.r1.selector.default=c2

若仅需区分行首是否为1,原配置中a1.sources.r1.selector.mapping.2=c2可删除,默认通道已覆盖所有非1的场景。

3. 正则表达式适配(可选)

若输入行首存在空白字符,需调整正则为^\\s*(\\d)以忽略前置空白;若行首为纯数字,当前^(\\d)的正则匹配逻辑正常。

4. 优化写入延迟(可选)

若HDFS写入存在延迟,可添加文件滚动参数,避免因未达到滚动条件导致数据暂存内存:

a1.sinks.k1.hdfs.rollInterval=10
a1.sinks.k2.hdfs.rollInterval=10

修复后的完整配置示例:

a1.sources=r1
a1.channels=c1 c2
a1.sinks = k1 k2

a1.sources.r1.type=netcat
a1.sources.r1.bind=localhost
a1.sources.r1.port=44444

a1.channels.c1.type=memory
a1.channels.c1.capacity=1000
a1.channels.c1.transactionCapacity=100

a1.channels.c2.type=memory
a1.channels.c2.capacity=1000
a1.channels.c2.transactionCapacity=100

a1.sources.r1.interceptors.i1.type=regex_extractor
a1.sources.r1.interceptors.i1.regex=^(\\d)
a1.sources.r1.interceptors.i1.serializers=s1
a1.sources.r1.interceptors.i1.serializers.s1.name=Rola

a1.sources.r1.selector.type=multiplexing
a1.sources.r1.selector.header=Rola
a1.sources.r1.selector.mapping.1=c1
a1.sources.r1.selector.default=c2

a1.sinks.k1.type=hdfs
a1.sinks.k1.hdfs.path=hdfs://localhost:8020/manager
a1.sinks.k1.hdfs.writeFormat=Text
a1.sinks.k1.hdfs.fileType=DataStream
a1.sinks.k1.hdfs.rollInterval=10

a1.sinks.k2.type=hdfs
a1.sinks.k2.hdfs.path=hdfs://localhost:8020/developer
a1.sinks.k2.hdfs.writeFormat=Text
a1.sinks.k2.hdfs.fileType=DataStream
a1.sinks.k2.hdfs.rollInterval=10

a1.sources.r1.channels = c1 c2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c2

内容的提问来源于stack exchange,提问作者xiras2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 06:30:35