flume监视文件夹案例

发布时间 2023-08-30 14:49:16作者: whiteY

监视文件夹

1.在flume的conf的目录下创建文件名称为:vim spool-logger.conf的文件
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
#监听目录,spoolDir指定目录, fileHeader要不要给文件夹前坠名
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /data/flume_spooldir
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
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
2.:根据a1.sources.r1.spoolDir = /data/flume_spooldir配置的文件路径,创建相应的目录。必须先创建对应的目录,不然报错。java.lang.IllegalStateException: Directory does not exist: /data/flume_spooldir
[root@hadoop01 con]# mkdir /data/flume_spooldir
3.启动命令:
[root@hadoop01 apache-flume-1.9.0-bin]# bin/flume-ng agent --conf conf --conf-file conf/spool-logger.conf --name a1 -Dflume.root.logger=INFO,console
4.测试

往/data/flume_spooldir放文件,但是不要在里面生成文件。

采集结果