小工具知识网

当前位置: 首页 > 行业知识 > Flume集成Kafka

行业知识

Flume集成Kafka

2026-11-29 12:29:17 来源:互联网转载

之前���到Flume可以直接采集数据存储到HDFS中,那为什么还要引入Kafka这个中间件呢,这个是因为在实际应用场景中,我们既需要实时计算也需要离线计算。

Kfka to HDFS配置

# Name the components on this agenta1.sources = r1a1.sinks = k1a1.channels = c1# sourcea1.sources.r1.type = org.apache.flume.source.kafka.KafkaSourcea1.sources.r1.channels = channel1a1.sources.r1.batchSize = 10a1.sources.r1.batchDurationMillis = 2000a1.sources.r1.kafka.bootstrap.servers = hadoop01:9092,hadoop02:9092,hadoop03:9092a1.sources.r1.kafka.topics = test_r2p5a1.sources.r1.kafka.consumer.group.id = flume-group1# Bind the source and sink to the channela1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 1000# Describe the sinka1.sinks.k1.type = hdfsa1.sinks.k1.channel = c1a1.sinks.k1.hdfs.path = hdfs://192.168.52.100:9000/kafkaout/%Y-%m-%da1.sinks.k1.hdfs.filePrefix = accessa1.sinks.k1.hdfs.writeFormat = Texta1.sinks.k1.hdfs.useLocalTimeStamp = truea1.sinks.k1.hdfs.fileType = DataStreama1.sinks.k1.hdfs.rollCount = 0a1.sinks.k1.hdfs.rollInterval = 3600a1.sinks.k1.hdfs.rollSize = 134217728# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1

File to Kafka配置

# Name the components on this agenta1.sources = r1a1.sinks = k1a1.channels = c1# sourcea1.sources.r1.type = execa1.sources.r1.command = tail -F /home/log/test.log# Bind the source and sink to the channela1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 1000# Describe the sinka1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSinka1.sinks.k1.kafka.topic = test_r2p5a1.sinks.k1.kafka.bootstrap.servers = hadoop01:9092,hadoop02:9092,hadoop03:9092a1.sinks.k1.kafka.flumeBatchSize = 10a1.sinks.k1.kafka.producer.acks = 1a1.sinks.k1.kafka.producer.linger.ms = 1a1.sinks.k1.kafka.producer.compression.type = snappy# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1

创建Topic

[root@hadoop01 kafka_2.12-2.4.0]# bin/kafka-topics.sh --create --zookeeper hadoop01:2181 --partitions 5 --replication-factor 2 --topic test_r2p5

启动flume

[root@hadoop04 conf-kafka-hdfs]# bin/flume-ng agent --name a1 --conf conf-kafka-hdfs --conf-file conf-kafka-hdfs/kafka-to-hdfs.conf -Dflume.root.logger=INFO,console[root@hadoop04 apache-flume-1.11.0-bin]# bin/flume-ng agent --name a1 --conf conf-file-kafka --conf-file conf-file-kafka/file-to-kafka.conf -Dflume.root.logger=INFO,console

创建test.log文件

[root@hadoop04 log]# echo hello world >> /home/log/test.log

验证

[root@hadoop01 kafka_2.12-2.4.0]# hdfs dfs -cat /kafkaout/2024-03-13/access.1710307375351.tmphello world

p01 kafka_2.12-2.4.0]# hdfs dfs -cat /kafkaout/2024-03-13/access.1710307375351.tmp

hello world



上一篇:云服务器免费平台

下一篇:怎么确定服务器安全问题?