• test with netcat
# netcat-flume-logger.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

# 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

use following command

bin/flume-ng agent --conf conf/ --conf-file example-conf/netcat-flume-logger.conf --name a1 -Dflume.root.logger=INFO,console
  • test with single file
# file-flume-logger.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /tmp/logs/tailF.log

# 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

use following command

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

then, open a new termial, and execute

touch /tmp/logs/tailF.log
echo aaa >> /tmp/logs/tailF.log
echo bbb >> /tmp/logs/tailF.log
echo cccc >> /tmp/logs/tailF.log
echo dddd >> /tmp/logs/tailF.log

仅在测试环境使用,不支持单点续传,当机器重启时会有数据丢失问题。

  • test with sinking int hdfs
# file-flume-hdfs.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /tmp/logs/tailF.log
#a1.sources.r1.shell = /bin/bash -C   # this will cause exit with 127

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://172.70.0.182:9000/flume/log/%Y%m%d/%H
a1.sinks.k1.hdfs.filePrefix = logs-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 1
a1.sinks.k1.hdfs.roundUnit = hour
a1.sinks.k1.hdfs.useLocalTimeStamp = true
a1.sinks.k1.hdfs.rollInterval = 30


# 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

use following command

bin/flume-ng agent --conf conf/ --conf-file example-conf/file-flume-hdfs.conf --name a1 

then, open a new termial, and execute

touch /tmp/logs/tailF.log
echo aaa >> /tmp/logs/tailF.log
echo bbb >> /tmp/logs/tailF.log
echo cccc >> /tmp/logs/tailF.log
echo dddd >> /tmp/logs/tailF.log
  • test with taildir
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = f1
a1.sources.r1.filegroups.f1 = /tmp/files/a*.txt
a1.sources.r1.positionFile = /tmp/files/position_file.json
作者:张三  创建时间:2026-03-12 12:07
最后编辑:张三  更新时间:2026-03-12 12:07