一、案例1之 Spool
Spool 监测配置的目录下新增的文件,并将文件中的数据读取出来。需要注意两点:
-
拷贝到 spool 目录下的文件不可以再打开编辑。
-
spool 目录下不可包含相应的子目录。
配置文件 jobs/spool.conf
a1.sources = r1 a1.channels = c1 a1.sinks = k1 a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 a1.sources.r1.type = spooldir a1.sources.r1.spoolDir = /opt/apache-flume-1.6.0-bin/logs a1.sources.r1.fileHeader = true a1.sources.r1.channels = c1 a1.sinks.k1.type = logger a1.sinks.k1.channel = c1
启动命令
bin/flume-ng agent -c conf -f jobs/spool.conf -n a1 -Dflume.root.logger=INFO,console
测试
$ echo "hello world" > logs/spool.log $ more logs/spool.log.COMPLETED hello world
二、案例2之 Exec
EXEC 执行一个给定的命令获得输出的源
配置文件 jobs/exec.conf
a1.sources = r1 a1.sinks = k1 a1.channels = c1 a1.channels.c1.type = memory a1.channels.c1.capacity = 10000 a1.channels.c1.transactionCapacity = 100 a1.sources.r1.type = exec a1.sources.r1.command = tail -F /opt/apache-flume-1.6.0-bin/logs/log_exec_tail a1.sources.r1.channels = c1 a1.sinks.k1.type = logger a1.sinks.k1.channel = c1
测试
for i in {1..1000} do echo "exec tail$i" >> /opt/apache-flume-1.6.0-bin/logs/log_exec_tail done
三、案例3之 JSONHanlder
从远程客户端接收数据
配置文件
a1.sources = r1 a1.sinks = k1 a1.channels = c1 a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 a1.sources.r1.type = org.apache.flume.source.http.HTTPSource a1.sources.r1.port = 8888 a1.sources.r1.channels = c1 a1.sinks.k1.type = logger a1.sinks.k1.channel = c1
测试
curl -X POST -d ‘[{ "headers" :{"a" : "a1","b" : "b1"}, "body" : "shiyanlou.org_body" }]‘ http://localhost:8888
233