Kafka集成flume

1.flume作为生产者集成Kafka

kafka作为flume的sink,扮演消费者角色

1.1 flume配置文件

vim $kafka/jobs/flume-kafka.conf

bash 复制代码
# agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1 c2

# Describe/configure the source
a1.sources.r1.type = TAILDIR
#记录最后监控文件的断点的文件,此文件位置可不改
a1.sources.r1.positionFile =  /export/server/flume/job/data/tail_dir.json
a1.sources.r1.filegroups = f1 f2
a1.sources.r1.filegroups.f1 = /export/server/flume/job/data/.*file.*
a1.sources.r1.filegroups.f2 =/export/server/flume/job/data/.*log.*

# Describe the sink
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = customers
a1.sinks.k1.kafka.bootstrap.servers =node1:9092,node2:9092
a1.sinks.k1.kafka.flumeBatchSize = 20
a1.sinks.k1.kafka.producer.acks = 1
a1.sinks.k1.kafka.producer.linger.ms = 1
a1.sinks.k1.kafka.producer.compression.type = snappy


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

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

1.2开启flume监控

flume-ng agent -n a1 -c conf/ -f /export/server/kafka/jobs/kafka-flume.conf

1.3开启Kafka消费者

kafka-console-consumer.sh --bootstrap-server node1:9092,node2:9092 --topic consumers --from-beginning

1.4生产数据

往被监控文件输入数据

ljr@node1 data\]$echo hello \>\>file2.txt \[ljr@node1 data\]$ echo ============== \>\>file2.txt 查看Kafka消费者 ![](https://img-blog.csdnimg.cn/direct/754950995683442593335d088d65a239.png) 可见Kafka集成flume生产者成功。 ### 2.flume作为消费者集成Kafka kafka作为flume的source,扮演生产者角色 #### 2.1flume配置文件 vim $kafka/jobs/flume-kafka.conf ```bash # agent a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = org.apache.flume.source.kafka.KafkaSource #注意不要大于channel transactionCapacity的值100 a1.sources.r1.batchSize = 50 a1.sources.r1.batchDurationMillis = 200 a1.sources.r1.kafka.bootstrap.servers =node1:9092, node1:9092 a1.sources.r1.kafka.topics = consumers a1.sources.r1.kafka.consumer.group.id = custom.g.id # 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 #注意transactionCapacity的值不要小于sources batchSize的值50 a1.channels.c1.transactionCapacity = 100 # Bind the source and sink to the channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 ``` #### 2.2开启flume监控 flume-ng agent -n a1 -c conf/ -f /export/server/kafka/jobs/kafka-flume1.conf #### 2.3开启Kafka生产者并生产数据 kafka-console-producer.sh --bootstrap-server node1:9092,node2:9092 --topic consumers ![](https://img-blog.csdnimg.cn/direct/f4b9a37f761b411882d53fe141864136.png) 查看flume监控台 ![](https://img-blog.csdnimg.cn/direct/16b931bcd36445eb885dde1a8068d1f0.png) 可见Kafka集成flume消费者成功。

相关推荐
ifeng09182 小时前
HarmonyOS分布式媒体播放器——跨设备音视频无缝流转
分布式·音视频·harmonyos
代码哈士奇2 小时前
简单使用Nest+Nacos+Kafka实现微服务
后端·微服务·nacos·kafka·nestjs
蒋星熠2 小时前
分布式计算深度解析:从理论到实践的技术探索
分布式·机器学习·spark·自动化·云计算·边缘计算·mapreduce
Gss7774 小时前
Kafka 相关内容总结
分布式·kafka
摇滚侠8 小时前
Spring Boot3零基础教程,KafkaTemplate 发送消息,笔记77
java·spring boot·笔记·后端·kafka
小小的木头人10 小时前
Windows Docker desktop 部署
运维·kafka
一晌小贪欢15 小时前
Python爬虫第10课:分布式爬虫架构与Scrapy-Redis
分布式·爬虫·python·网络爬虫·python爬虫·python3
摇滚侠19 小时前
Spring Boot3零基础教程,监听 Kafka 消息,笔记78
spring boot·笔记·kafka
摇滚侠1 天前
Spring Boot3零基础教程,Kafka 小结,笔记79
spring boot·笔记·kafka
沐浴露z1 天前
一篇文章详解Kafka Broker
java·分布式·kafka