1 配置spool-hdfs.conf文件
a1.sources = r1
a1.sinks = k1
a1.channels = c1
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /root/logs2
a1.sources.r1.fileHeader = true
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/
a1.sinks.k1.hdfs.filePrefix = allen-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute
a1.sinks.k1.hdfs.rollInterval = 3
a1.sinks.k1.hdfs.rollSize = 20
a1.sinks.k1.hdfs.rollCount = 5
a1.sinks.k1.hdfs.batchSize = 1
a1.sinks.k1.hdfs.useLocalTimeStamp = true
a1.sinks.k1.hdfs.fileType = DataStream
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2 启动flume
bin/flume-ng agent -c ./conf -f ./conf/spool-hdfs.conf -n a1 -Dflume.root.logger= INFO,console
3 创建监控目录/root/logs2
mkdir -p /root/logs2
4 向监控目录移动文件
cp world.txt /root/logs2/
5 测试
2020-06-23 04:24:23,250 ( pool-5-thread-1) [ INFO - org.apache.flume.client.avro.ReliableSpoolingFileEventReader.readEvents( ReliableSpoolingFileEventReader.java:324) ] Last read took us just up to a file boundary. Rolling to the next file, if there is one.
2020-06-23 04:24:23,251 ( pool-5-thread-1) [ INFO - org.apache.flume.client.avro.ReliableSpoolingFileEventReader.rollCurrentFile( ReliableSpoolingFileEventReader.java:433) ] Preparing to move file /root/logs2/world.txt to /root/logs2/world.txt.COMPLETED
2020-06-23 04:24:23,397 ( SinkRunner-PollingRunner-DefaultSinkProcessor) [ INFO - org.apache.flume.sink.hdfs.HDFSDataStream.configure( HDFSDataStream.java:57) ] Serializer = TEXT, UseRawLocalFileSystem = false
2020-06-23 04:24:23,589 ( SinkRunner-PollingRunner-DefaultSinkProcessor) [ INFO - org.apache.flume.sink.hdfs.BucketWriter.open( BucketWriter.java:251) ] Creating /flume/events/20-06-23/0420//wangjie-.1592857463398.tmp
2020-06-23 04:24:25,194 ( SinkRunner-PollingRunner-DefaultSinkProcessor) [ INFO - org.apache.flume.sink.hdfs.BucketWriter.close( BucketWriter.java:393) ] Closing /flume/events/20-06-23/0420//wangjie-.1592857463398.tmp
2020-06-23 04:24:25,248 ( hdfs-k1-call-runner-6) [ INFO - org.apache.flume.sink.hdfs.BucketWriter$8 .call( BucketWriter.java:655) ] Renaming /flume/events/20-06-23/0420/wangjie-.1592857463398.tmp to /flume/events/20-06-23/0420/wangjie-.1592857463398
2020-06-23 04:24:25,280 ( SinkRunner-PollingRunner-DefaultSinkProcessor) [ INFO - org.apache.flume.sink.hdfs.BucketWriter.open( BucketWriter.java:251) ] Creating /flume/events/20-06-23/0420//wangjie-.1592857463399.tmp
2020-06-23 04:24:25,347 ( SinkRunner-PollingRunner-DefaultSinkProcessor) [ INFO - org.apache.flume.sink.hdfs.BucketWriter.close( BucketWriter.java:393) ] Closing /flume/events/20-06-23/0420//wangjie-.1592857463399.tmp
2020-06-23 04:24:25,355 ( hdfs-k1-call-runner-1) [ INFO - org.apache.flume.sink.hdfs.BucketWriter$8 .call( BucketWriter.java:655) ] Renaming /flume/events/20-06-23/0420/wangjie-.1592857463399.tmp to /flume/events/20-06-23/0420/wangjie-.1592857463399
2020-06-23 04:24:25,377 ( SinkRunner-PollingRunner-DefaultSinkProcessor) [ INFO - org.apache.flume.sink.hdfs.BucketWriter.open( BucketWriter.java:251) ] Creating /flume/events/20-06-23/0420//wangjie-.1592857463400.tmp
2020-06-23 04:24:28,399 ( hdfs-k1-roll-timer-0) [ INFO - org.apache.flume.sink.hdfs.BucketWriter.close( BucketWriter.java:393) ] Closing /flume/events/20-06-23/0420//wangjie-.1592857463400.tmp
2020-06-23 04:24:28,410 ( hdfs-k1-call-runner-6) [ INFO - org.apache.flume.sink.hdfs.BucketWriter$8 .call( BucketWriter.java:655) ] Renaming /flume/events/20-06-23/0420/wangjie-.1592857463400.tmp to /flume/events/20-06-23/0420/wangjie-.1592857463400
2020-06-23 04:24:28,412 ( hdfs-k1-roll-timer-0) [ INFO - org.apache.flume.sink.hdfs.HDFSEventSink$1 .run( HDFSEventSink.java:382) ] Writer callback called.
6 扩展启动命令解释
bin/flume-ng agent --conf conf --conf-file conf/netcat-logger.conf --name a1 -Dflume.root.logger= INFO,console
bin/flume-ng agent -c ./conf -f ./conf/spool-hdfs.conf -n a1 -Dflume.root.logger= INFO,console
--conf( -c) 指定flume默认的配置文件路径。要求改路径下必须有两个文件:
flume-env.sh
log4j.properties
--conf-file( -f) 指定采集方案的路径
--name( -n) 指定本agent进程名 要和采集方案中对应上
-Dflume.root.logger= INFO,console 开启日志 打印在控制台