flume-使用KafkaChannel读取不到数据

使用TAILDIR监听日志写入KafkaChannel。

配置如下:

a1.sources = r1
a1.channels = c1

#描述source
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = f1
a1.sources.r1.filegroups.f1 = /opt/module/applog/log22/app.*
a1.sources.r1.positionFile = /opt/module/flume/taildir_position.json
#a1.sources.r1.interceptors =  i1
#a1.sources.r1.interceptors.i1.type = com.flume.interceptor.ETLInterceptor$Builder

#描述channel
a1.channels.c1.type = org.apache.flume.channel.kafka.KafkaChannel
a1.channels.c1.kafka.bootstrap.servers = 192.168.88.161:9092
a1.channels.c1.kafka.topic = topic_log
a1.channels.c1.parseAsFlumeEvent = false

#绑定source和channel以及sink和channel的关系
a1.sources.r1.channels = c1

启动命令:

/export/soft/apache-flume-1.9.0-bin/bin/flume-ng agent --name=$agent_name -Dflume.monitoring.type=http -Dflume.monitoring.port=1234 -c /export/soft/apache-flume-1.9.0-bin/conf -f /export/soft/apache-flume-1.9.0-bin/conf/user/applog_flie-kafka2.conf -Dflume.root.logger=INFO,LOGFILE >/opt/module/flume/server/log/log.txt 2>&1

发现kafka对应的topic没有接收到消息。

排查:

1,修改启动命令,将日志输出到控制台,查看相应的组件是否启动,正常情况日志应该有如下的日志:xxx started:

在这里插入图片描述

但我的日志中发现一个组件都没有启动。

在这里插入图片描述
2,推测是不是flume监听日志文件除了问题,于是想把监听文件内容输出到控制台,另外写一个flume的配置文件,source(文件)->channel(内存)->sink(控制台):

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

#描述source
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = f1
a1.sources.r1.filegroups.f1 = /opt/module/applog/log22/app.*
a1.sources.r1.positionFile = /opt/module/flume/taildir_position.json
#a1.sources.r1.interceptors =  i1
#a1.sources.r1.interceptors.i1.type = com.flume.interceptor.ETLInterceptor$Builder

#描述channel
#a1.channels.c1.type = org.apache.flume.channel.kafka.KafkaChannel
#a1.channels.c1.kafka.bootstrap.servers = node1:9092,noide2:9092
#a1.channels.c1.kafka.topic = topic_log
#a1.channels.c1.parseAsFlumeEvent = false


# Describe the sink
a1.sinks.k1.type = logger
  
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100


#绑定source和channel以及sink和channel的关系
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

启动命令:

../../bin/flume-ng agent -n a1 -c ../../conf -f applog_flie-memory.conf -Dflume.root.logger=INFO,console

测试发现监听文件没有问题,文件内容会打印到控制台,说明flume监听文件是没问题的。

3,又一次启动flume任务,仔细研究日志,发现有这样一行:

在这里插入图片描述

错误找到了,整个管道的名称不是xa1,而是a1:
在这里插入图片描述
修改启动命令,指定正确的名称 :
在这里插入图片描述

启动后,日志打印正常,kafka也接收到消息。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
好的,以下是一个示例的file-flume-kafka.conf配置文件,您可以根据自己的需求进行修改: ```properties # Name the components on this agent kafka-flume-agent.sources = kafka-source kafka-flume-agent.channels = kafka-channel kafka-flume-agent.sinks = logger-sink # Describe/configure the source kafka-flume-agent.sources.kafka-source.type = org.apache.flume.source.kafka.KafkaSource kafka-flume-agent.sources.kafka-source.zookeeperConnect = hadoop102:2181,hadoop103:2181,hadoop104:2181 kafka-flume-agent.sources.kafka-source.topic = test-topic kafka-flume-agent.sources.kafka-source.batchSize = 1000 # Describe the sink kafka-flume-agent.sinks.logger-sink.type = logger # Use a channel which buffers events in memory kafka-flume-agent.channels.kafka-channel.type = memory kafka-flume-agent.channels.kafka-channel.capacity = 10000 kafka-flume-agent.channels.kafka-channel.transactionCapacity = 1000 # Bind the source and sink to the channel kafka-flume-agent.sources.kafka-source.channels = kafka-channel kafka-flume-agent.sinks.logger-sink.channel = kafka-channel ``` 这个示例配置文件定义了一个名为"kafka-flume-agent"的Flume代理程序,它从名为"test-topic"的Kafka主题中读取数据,并将其写入到一个内存通道中。 注意,这个示例配置文件中的"zookeeperConnect"参数指定了Kafka使用的Zookeeper地址,您需要根据自己的实际情况进行修改。 启动这个配置文件的方法已经在上一条回答中给出。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大数据男

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值