如何在flume中使用taildir源代码只附加.txt文件的最新行?

brjng4g3  于 2021-06-04  发布在  Flume
关注(0)|答案(1)|浏览(324)

我最近问了一个问题apacheflume-只发送新的文件内容
我重新措辞的问题,以了解更多,并提供更多的利益给未来的用户的Flume。
设置:两台服务器,其中一台带有一个.txt文件,该文件定期附加行。
目标:使用flume taildir source将最近写入的行附加到另一台服务器上的文件中。
问题:每当源文件添加了新行数据时,当前配置都会将服务器1上的文件中的所有内容附加到服务器2上的文件中。这将导致文件2中出现重复的行,并且无法从服务器1正确地重新创建文件。
服务器1上的配置:


# configure the agent

    agent.sources=r1
    agent.channels=k1
    agent.sinks=c1

    #using memort channel to hold upto 1000 events
    agent.channels.k1.type=memory
    agent.channels.k1.capacity=1000
    agent.channels.k1.transactionCapacity=100

    #connect source, channel,sink
    agent.sources.r1.channels=k1
    agent.sinks.c1.channel=k1

    #define source
    agent.sources.r1.type=TAILDIR
    agent.sources.r1.channels=k1
    agent.sources.r1.filegroups=f1

    agent.sources.r1.filegroups.f1=/home/tail_test_dir/test.txt
    agent.sources.r1.maxBackoffSleep=1000

    #connect to another box using avro and send the data
    agent.sinks.c1.type=avro
    agent.sinks.c1.hostname=10.10.10.4
    agent.sinks.c1.port=4545

服务器2上的配置:


# configure the agent

    agent.sources=r1
    agent.channels=k1
    agent.sinks=c1

    #using memory channel to hold up to 1000 events
    agent.channels.k1.type=memory
    agent.channels.k1.capacity=1000
    agent.channels.k1.transactionCapacity=100

    #connect source, channel, sink
    agent.sources.r1.channels=k1
    agent.sinks.c1.channel=k1

    #here source is listening at the specified port using AVRO for data
    agent.sources.r1.type=avro
    agent.sources.r1.bind=0.0.0.0
    agent.sources.r1.port=4545

    #use file_roll and write file at specified directory
    agent.sinks.c1.type=file_roll
    agent.sinks.c1.sink.directory=/home/Flume_dump
ylamdve6

ylamdve61#

必须设置json文件的位置。然后源代码检查位置并只向sink写入新添加的行。例如)agent.sources.s1.positionfile=/var/log/flume/tail\u position.json

相关问题