Flume集成Kafka

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

image-20240313120335406

Kfka to HDFS配置

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# source
a1.sources.r1.type = org.apache.flume.source.kafka.KafkaSource
a1.sources.r1.channels = channel1
a1.sources.r1.batchSize = 10
a1.sources.r1.batchDurationMillis = 2000
a1.sources.r1.kafka.bootstrap.servers = hadoop01:9092,hadoop02:9092,hadoop03:9092
a1.sources.r1.kafka.topics = test_r2p5
a1.sources.r1.kafka.consumer.group.id = flume-group1

# Bind the source and sink to the channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 1000


# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
a1.sinks.k1.hdfs.path = hdfs://192.168.52.100:9000/kafkaout/%Y-%m-%d
a1.sinks.k1.hdfs.filePrefix = access
a1.sinks.k1.hdfs.writeFormat = Text
a1.sinks.k1.hdfs.useLocalTimeStamp = true
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.rollCount = 0
a1.sinks.k1.hdfs.rollInterval = 3600
a1.sinks.k1.hdfs.rollSize = 134217728

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

File to Kafka配置

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /home/log/test.log

# Bind the source and sink to the channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 1000

# Describe the sink
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = test_r2p5
a1.sinks.k1.kafka.bootstrap.servers = hadoop01:9092,hadoop02:9092,hadoop03:9092
a1.sinks.k1.kafka.flumeBatchSize = 10
a1.sinks.k1.kafka.producer.acks = 1
a1.sinks.k1.kafka.producer.linger.ms = 1
a1.sinks.k1.kafka.producer.compression.type = snappy

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.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.tmp
hello world

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




相关推荐

  1. FlumeKafka的区别

    2024-03-14 05:20:06       42 阅读
  2. <span style='color:red;'>Flume</span>

    Flume

    2024-03-14 05:20:06      58 阅读
  3. flume

    2024-03-14 05:20:06       39 阅读
  4. <span style='color:red;'>Flume</span>

    Flume

    2024-03-14 05:20:06      142 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-14 05:20:06       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-14 05:20:06       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-14 05:20:06       87 阅读
  4. Python语言-面向对象

    2024-03-14 05:20:06       96 阅读

热门阅读

  1. Python web框架fastapi中间件的使用

    2024-03-14 05:20:06       39 阅读
  2. python控制语句-2.1

    2024-03-14 05:20:06       41 阅读
  3. 企业数字化转型:挑战、机遇与整合

    2024-03-14 05:20:06       44 阅读
  4. 在docker中使用nginx转发端口失败

    2024-03-14 05:20:06       43 阅读
  5. Unity中计算两个三维坐标点的各种方法

    2024-03-14 05:20:06       43 阅读
  6. Oracle DBMS_LOCK

    2024-03-14 05:20:06       31 阅读
  7. zabbix-server-pgsql docker镜像备忘

    2024-03-14 05:20:06       34 阅读
  8. 不同数据库中sql如何添加数据

    2024-03-14 05:20:06       42 阅读
  9. MySQL学习记录

    2024-03-14 05:20:06       45 阅读
  10. Vim 编辑器|批量注释与批量取消注释

    2024-03-14 05:20:06       41 阅读
  11. 阿里云国际版源站IP暴露的解决办法

    2024-03-14 05:20:06       47 阅读
  12. Linux-轻量级数据库sqlite-015

    2024-03-14 05:20:06       40 阅读