如下案例,监控linux
目录上的csv
文件,并读取到 hdfs
上
#命名这个组件
agent1.channels = c1
agent1.sources = r1
agent1.sinks = k1
agent1.sources.r1.channels = c1
# source属性
agent1.sources.r1.type = TAILDIR
#元数据保存位置,记录读取的位置啥的,位于linux上
agent1.sources.r1.positionFile = /home/data/flume_log/taildir_position.json
agent1.sources.r1.filegroups = f1
#监控的文件夹的位置
agent1.sources.r1.filegroups.f1 = /home/data/flume-CSV/.*csv
agent1.sources.r1.fileHeader = true
# 设置channel类型为memory,速度比较快
agent1.channels.c1.type = memory
# channel可以容纳的event数目
agent1.channels.c1.capacity = 1000
# 事务数量
agent1.channels.c1.transactionCapacity = 100
# 设置sink的类型为hdfs
agent1.sinks.k1.type=hdfs
# hdfs上的路径
agent1.sinks.k1.hdfs.path= hdfs://node01:8020/data203/nshop/ods/release/bdp_day=%Y%m%d
agent1.sinks.k1.hdfs.fileType=DataStream
#文件在hdfs上的保存格式
agent1.sinks.k1.hdfs.writeFormat=TEXT
agent1.sinks.k1.hdfs.rollCount=0
agent1.sinks.k1.hdfs.rollSize=0
agent1.sinks.k1.channel=c1
#文件名的前缀
agent1.sinks.k1.hdfs.filePrefix=%Y-%m-%d
agent1.sinks.k1.hdfs.fileSuffix=.log
agent1.sinks.k1.hdfs.useLocalTimeStamp = true
启动脚本
flume-ng agent -c /usr/local/flume/conf -f /usr/local/flume/flumeconf/taildir-mem-hdfs1.conf -n agent1 -Dflume.root.logger=INFO,console
之后就可以在hdfs上看到相应的文件.
数据导入成功后,可以进一步将hdfs上的文件映射成hive表,就相当于导入hive中了
alter table ods_nshop_2003.ods_nshop_01_releasedatas add partition (bdp_day='20201223');
当然,前提是hiev已经有创建这个表,且该表的位置为
'/data203/nshop/ods/release/';
也就是hive建表时外部表的位置要和采集方案中hdfs输出的位置是一样的!
注意事项
报错
Failed loading positionFile
1.删掉该文件,重新启动flume