Flume配置案例@Source:Kafka,Channel:File,Sink:HDFS

创建flume配置文件

[atguigu@hadoop104 flume]$ vim job/kafka_to_hdfs_log.conf

配置内容如下:

---------------------

#定义组件

a1.sources=r1

a1.channels=c1

a1.sinks=k1

#配置source1

a1.sources.r1.type = org.apache.flume.source.kafka.KafkaSource

a1.sources.r1.batchSize = 5000

a1.sources.r1.batchDurationMillis = 2000

a1.sources.r1.kafka.bootstrap.servers= = hadoop102:9092,hadoop103:9092,hadoop104:9092

# 消费的kafka的主题是topic_log

a1.sources.r1.kafka.topics=topic_log

a1.sources.r1.interceptors = i1

# 下面写的这个拦截器是要解决零点飘移问题

a1.sources.r1.interceptors.i1.type = com.atguigu.flume.interceptor.TimestampInterceptor$Builder

com.atguigu.flume.interceptor. 这是包名 ;$Builder 这是里面的内部类

#配置channel

a1.channels.c1.type = file

a1.channels.c1.checkpointDir = /opt/module/flume/checkpoint/behavior1

a1.channels.c1.dataDirs = /opt/module/flume/data/behavior1

a1.channels.c1.maxFileSize = 2146435071

a1.channels.c1.capacity = 1000000

a1.channels.c1.keep-alive = 6

#配置sink

a1.sinks.k1.type = hdfs

a1.sinks.k1.hdfs.path = /origin_data/gmall/log/topic_log/%Y-%m-%d

/origin_data/gmall/log/topic_log/%Y-%m-%d 这个是要存的HDFS的路径,可以提前不存在

a1.sinks.k1.hdfs.filePrefix = log

a1.sinks.k1.hdfs.round = false

a1.sinks.k1.hdfs.rollInterval = 10

a1.sinks.k1.hdfs.rollSize = 134217728

a1.sinks.k1.hdfs.rollCount = 0

#控制输出文件类型

a1.sinks.k1.hdfs.fileType = CompressedStream

a1.sinks.k1.hdfs.codeC = gzip

#组装 

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以回答这个问题。您可以按照以下步骤来使用Flume采集Kafka数据到HDFS和Hive中: 1. 首先,确保您已经安装了FlumeKafkaHDFS和Hive等必要的软件。 2. 然后,在Flume配置文件中添加Kafka作为Source和HDFS/Hive作为Sink。例如,以下是一个简单的配置文件示例: ``` agent.sources = kafka-source agent.channels = hdfs-channel agent.sinks = hdfs-sink hive-sink agent.sources.kafka-source.type = org.apache.flume.source.kafka.KafkaSource agent.sources.kafka-source.batchSize = 1000 agent.sources.kafka-source.kafka.bootstrap.servers = localhost:9092 agent.sources.kafka-source.kafka.topics = my-topic agent.sources.kafka-source.kafka.consumer.group.id = my-group agent.channels.hdfs-channel.type = memory agent.channels.hdfs-channel.capacity = 10000 agent.channels.hdfs-channel.transactionCapacity = 100 agent.sinks.hdfs-sink.type = hdfs agent.sinks.hdfs-sink.hdfs.path = hdfs://localhost:9000/flume/kafka agent.sinks.hdfs-sink.hdfs.fileType = DataStream agent.sinks.hdfs-sink.hdfs.writeFormat = Text agent.sinks.hdfs-sink.channel = hdfs-channel agent.sinks.hive-sink.type = hive agent.sinks.hive-sink.hive.metastore = thrift://localhost:9083 agent.sinks.hive-sink.hive.database = my-db agent.sinks.hive-sink.hive.table = my-table agent.sinks.hive-sink.hive.partition = dt=%Y-%m-%d agent.sinks.hive-sink.channel = hdfs-channel ``` 在上面的配置文件中,我们使用Kafka作为Source,将数据写入到HDFS和Hive中。我们使用Memory Channel将数据缓存在内存中,然后将其写入到HDFS和Hive中。在Hive Sink中,我们还定义了一个分区,以便按日期对数据进行分区。 3. 最后,运行Flume代理以开始从Kafka读取数据并将其写入到HDFS和Hive中。您可以使用以下命令来启动Flume代理: ``` $ bin/flume-ng agent -n agent -c conf -f conf/flume-kafka-hdfs-hive.conf ``` 这样,Flume代理就会开始从Kafka读取数据,并将其写入到HDFS和Hive中。 希望这些信息能够帮助您采集Kafka数据到HDFS和Hive中。如果您有任何其他问题,请随时问我。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值