1.需求
监控一个文件实时采集新增的数据输出到控制台
2.创建配置文件
在conf下创建一个名为exec-memory-logger.conf的文件,在文件中加入以下配置:
# 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 /root/data/data.log
a1.sources.r1.shell = /bin/sh -c
# Describe the sink
a1.sinks.k1.type = logger
#Use a channel which buffers events in memory
a1.channels.c1.type = memory
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
3.启动
flume-ng agent --name a1 --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/exec-memory-logger.conf -Dflume.root.logger=INFO,console
启动成功的界面:
4.向data.log中添加数据
echo hello >> data.log
echo ligh >> data.log
echo welcome >> data.log
5.控制台结果显示
拓展:
打印在控制台上面的数据也可以存储到HDFS中,只不过是离线的数据,后面会讲通过kafka实时的存储数据,详细的配置见
官网链接