新建配置文件 flume-config01.conf

    使用 TAILDIR source 可以监控一个或多个日志目录。
    positionFile 是一个记录偏移量的文件,可以

    1. # example.conf: A single-node Flume configuration
    2. # Name the components on this agent
    3. a1.sources = r1
    4. a1.sinks = k1
    5. a1.channels = c1
    6. # Describe/configure the source
    7. a1.sources.r1.type = TAILDIR
    8. a1.sources.r1.positionFile = /Users/taoshilei/dev/flume_data/taildir_position.json
    9. a1.sources.r1.filegroups = f1
    10. a1.sources.r1.filegroups.f1 = /Users/taoshilei/dev/flume_data/file1.txt
    11. a1.sources.ri.maxBatchCount = 1000
    12. # Describe the sink
    13. a1.sinks.k1.type = logger
    14. # Use a channel which buffers events in memory
    15. a1.channels.c1.type = memory
    16. a1.channels.c1.capacity = 1000
    17. a1.channels.c1.transactionCapacity = 100
    18. # Bind the source and sink to the channel
    19. a1.sources.r1.channels = c1
    20. a1.sinks.k1.channels = c1

    启动命令

    1. flume-ng agent --conf conf --conf-file conf/flume-config02.conf -name a1 -Dflume.root.logger=INFO,console

    打开另一个窗口,进入到 cd /Users/taoshilei/dev/flume_data

    1. echo 'hello world' >> file1.txt
    2. echo 'hello world2' >> file1.txt

    如图
    截屏2021-08-12 下午2.51.30.png
    文件读取的偏移量记录在哪里了呢?taildir_position.json

    1. [{"inode":18397130,"pos":25,"file":"/Users/taoshilei/dev/flume_data/file1.txt"}]%

    这里面记录了文件的 inode,这个是系统给文件的一个唯一标识。pos 是数据的偏移位置。而且这个文件,正在被flume进程所占用,禁止私自修改。

    可以在关于 fluem进程之后,再修改这个文件,比如,我们有时候想从头开始重新读取文件,就可以把pos改成 0

    下面一下修改文件名会怎么样????

    如果在 Flume 挂掉的时候,数据还在写入,然后重命名文件了。再创建一个新的文件,重新启动 flume 进程,程序就会漏掉一部分数据。

    所以 tardir 指定某一个文件的方式不是很安全,容易造成数据丢失。

    接下来,试一下正则匹配。

    改成下面这样的:file1*.txt

    1. a1.sources.r1.filegroups.f1 = /Users/taoshilei/dev/flume_data/file1*.txt

    https://www.freesion.com/article/7343479314/

    https://blog.csdn.net/test103/article/details/55096786