案例说明:
1、以日志的形式输出
2、输出到hdfs中
操作步骤:
一、以日志的形式输出
1、创建file-flume-logger.conf
内容如下:
a2.sources=r1
a2.channels=c1
a2.sinks=k1
a2.sources.r1.type=exec
a2.sources.r1.command=tail -f /opt/soft/flume160/conf/KB15conf/flumefile.log
a2.channels.c1.type=memory
a2.channels.c1.capacity=1000
a2.channels.c1.transactionCapacity=100
a2.sinks.k1.type=logger
a2.sources.r1.channels=c1
a2.sinks.k1.channel=c1
sources以exec追加跟踪某一文件,channels以memory的形式将event数据存储在内存中,sinks以logger的形式将内容写入到日志中。
2、执行命令
进入到flume目录下,执行命令./bin/flume-ng agent --name a2 --conf conf/ --conf-file conf/KB15conf/file-flume-logger.conf -Dflume.root.logger=INFO,console
3、查看输出内容
4、追加内容
命令echo hello 123 >> flumefile.log
输出:
二、以文件的形式输出到hdfs中
1、创建file-flume-hdfs.conf
内容如下:
a2.sources=r1
a2.channels=c1
a2.sinks=k1
a2.sources.r1.type=exec
a2.sources.r1.command=tail -f /opt/soft/flume160/conf/KB15conf/flumefile.log
a2.channels.c1.type=memory
a2.channels.c1.capacity=1000
a2.channels.c1.transactionCapacity=100
a2.sinks.k1.type=hdfs
a2.sinks.k1.hdfs.fileType=DataStream
a2.sinks.k1.hdfs.filePrefix=flumetohdfs
a2.sinks.k1.hdfs.fileSuffix=.txt
a2.sinks.k1.hdfs.path=hdfs://192.168.91.135:9000/kb15file/
a2.sources.r1.channels=c1
a2.sinks.k1.channel=c1
sources以exec追加跟踪某一文件,channels以memory的形式将event数据存储在内存中,sinks以hdfs的形式将内容写入到hdfs中,文件前缀是flumetohdfs,后缀是.txt
2、执行命令
进入到flume目录下,执行命令./bin/flume-ng agent --name a2 --conf conf/ --conf-file conf/KB15conf/file-flume-hdfs.conf -Dflume.root.logger=INFO,console
3、查看输出内容
下载文件查看,内容是和flumefile.log里的内容是一致的