Flume采集到HDFS

一、需求:

采集指定文件的内容到HDFS

技术选型:exec - memory - hdfs

a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /home/hadoop/data/data.log
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://192.168.0.129:9000/user/hadoop/flume
a1.sinks.k1.hdfs.batchSize = 10            #10行产生新文件
a1.sinks.k1.hdfs.fileType = DataStream     #压缩格式
a1.sinks.k1.hdfs.writeFormat = Text        #格式类型
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

启动:

./flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file /home/hadoop/script/flume/exec-memory-hdfs.conf \
-Dflume.root.logger=INFO,console \
-Dflume.monitoring.type=http \
-Dflume.monitoring.port=34343

添加测试数据:

[hadoop@hadoop001 data]$ touch data.log
[hadoop@hadoop001 data]$ echo test >> data.log
[hadoop@hadoop001 data]$ echo test >> data.log
[hadoop@hadoop001 data]$ echo test >> data.log
[hadoop@hadoop001 data]$ echo test >> data.log
[hadoop@hadoop001 data]$ echo test >> data.log

检查HDFS:

[hadoop@hadoop001 flume]$ hdfs dfs -text hdfs://192.168.0.129:9000/user/hadoop/flume/*
18/08/09 20:59:02 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
test
test
test
test
test


二、需求:

采集指定文件夹的内容到(HDFS或者控制台)

==》文件夹下文件不能修改切不能重名

==》处理完当前文件添加 .COMPLETED标识

a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /home/hadoop/data/
a1.sources.r1.fileHeader = true
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1


三、需求:(生产使用,记录偏移量)

采集指定文件夹和文件内容到( 控制台 或者 HDFS )


a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = TAILDIR
a1.sources.r1.channels = c1
#记录偏移量,重启续传
a1.sources.r1.positionFile = /home/hadoop/script/flume/taildir_position.json
a1.sources.r1.filegroups = f1 f2
#监控指定log文件
a1.sources.r1.filegroups.f1 =/home/hadoop/data/example.log
a1.sources.r1.headers.f1.headerKey1 = value1
#监控文加下的所有log*文件夹和内容
a1.sources.r1.filegroups.f2 = /home/hadoop/data/test/.*log.*
a1.sources.r1.headers.f2.headerKey1 = value2
a1.sources.r1.headers.f2.headerKey2 = value2-2
# 控制台输出
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
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1


启动:

./flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file /home/hadoop/script/flume/taildir-memory-logger.conf \
-Dflume.root.logger=INFO,console


记录偏移量:

[hadoop@hadoop001 flume]$ cat taildir_position.json


[{"inode":679982," pos":14 ,"file":"/home/hadoop/data/example.log"}


{"inode":679984,"pos":0,"file":"/home/hadoop/data/test/log1.log"}]






来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31441024/viewspace-2199595/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31441024/viewspace-2199595/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flume 是一种用于数据采集、聚合和移动的工具,它可以将多种来源的数据收集到 HDFS(Hadoop分布式文件系统)中。通过 Flume,用户可以轻松地配置和管理数据流,确保数据的可靠性和一致性。 首先,用户需要在 Flume 的配置文件中定义数据源,例如日志文件、网络源或其他存储位置。接着,用户需要定义数据的处理流程,包括数据的过滤、转换和路由策略。然后,用户需要指定目的地为 HDFS,并设置 HDFS 的相关参数,包括数据的写入路径、文件格式和压缩方式等。 当 Flume 启动后,它会按照用户定义的规则和流程,从数据源收集数据,并将其经过处理后写入到 HDFS 中。Flume 可以确保数据的高效传输和存储,同时具有容错和重试机制,以保证数据的可靠性和完整性。 在数据采集HDFS 后,用户可以通过 Hadoop 生态系统中的其他工具和框架,如 MapReduce、Spark 等进行数据处理和分析。同时,用户也可以通过 HDFS 提供的 API 和命令行工具,对数据进行管理和检索,以满足各种业务需求和分析任务。 总之,通过 Flume 将数据采集HDFS 中,用户可以实现大规模数据的收集、存储和分析,为企业决策和业务运营提供基础支持。同时,Flume 也为数据工程师和分析师提供了一个灵活、高效的数据采集和处理工具,助力他们更好地利用数据来推动业务发展。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值