flume监控一个linux指定的一个文件夹的文件信息

1.编辑一个配置文件 flume-app.conf  拷贝至fulme的安装目录的conf下

 1 # The configuration file needs to define the sources, 
 2 # the channels and the sinks.
 3 
 4 ### define agent
 5 a3.sources = r3
 6 a3.channels = c3
 7 a3.sinks = k3
 8 
 9 
10 ### define sources
11 a3.sources.r3.type = spooldir
12 ### 要扫描的文件夹
13 a3.sources.r3.spoolDir = /opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/spoollogs
14 ### 以.log结尾的文件不扫描
15 a3.sources.r3.ignorePattern = ^(.)*\.log$
16 ### 扫描完成的文件加一个后缀
17 a3.sources.r3.fileSuffix = .delete
18 
19 ### define channels
20 a3.channels.c3.type = file
21 a3.channels.c3.checkpointDir = /opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/filechannel/checkpoint
22 a3.channels.c3.dataDirs = /opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/filechannel/data
23 
24 ### define sink
25 a3.sinks.k3.type = hdfs
26 ### 已当天日期在hdfs上创建一个文件夹
27 a3.sinks.k3.hdfs.path = hdfs://hadoop:8020/user/xuyou/flume/splogs/%Y%m%d
28 a3.sinks.k3.hdfs.fileType = DataStream 
29 a3.sinks.k3.hdfs.writeFormat = Text
30 a3.sinks.k3.hdfs.batchSize = 10
31 a3.sinks.k3.hdfs.useLocalTimeStamp = true
32 
33 
34 ### bind the soures and  sink to the channel
35 a3.sources.r3.channels = c3
36 a3.sinks.k3.channel = c3

创建 spoollogs 文件夹  准备一些数据   测试 .log结尾的文件是否被扫描到

执行命令

1 bin/flume-ng agent 
2 -c conf 
3 -n a3 
4 -f conf/flume-app.conf 
5 -Dflume.root.logger=DEBUG,console

查看文件   .log结尾的文件果然没有被读取到  已经读取的文件也被加上后缀了

在hdfs上自动以当天时间命名生成了一个文件夹

然后测试 是否一直监控这个文件夹

创建一个文件  然后在查询发现被标记 后缀了  (ps:如果此文件夹是空的 不会在hdfs生成对应的文件)

 

原文地址:https://www.cnblogs.com/xuyou551/p/8038415.html