1、前言
-
step1:开发一个文件,properties类型的文件
-
step2:在文件中要定义一个agent,这个agent中要定义source、channel、sink
- source:从哪采集数据
- channel:采集到的数据临时存放在哪
- sink:将采集的数据发送到哪去
-
step3:使用Flume的命令运行这个文件中的agent即可
-
官网: http://archive.cloudera.com/cdh5/cdh/5/flume-ng-1.6.0-cdh5.14.0/FlumeUserGuide.html
-
Flume提供了非常全面的组件的支持
-
Source
-
Channel
-
Sink
2、测试
- 需求:动态的采集某个文件的数据,将采集的内容存储在日志中【命令行】
- source:exec source,执行一条Linux命令实现数据的采集
- 一般exec source都与tail命令放在一起用
- tail命令能实现动态的采集一个文件
- tail -f xxxx:动态查看这个文件
- http://archive.cloudera.com/cdh5/cdh/5/flume-ng-1.6.0-cdh5.14.0/FlumeUserGuide.html#exec-source
- channel:使用memchannel,将采集到的数据临时缓存在内存中
- sink:使用logger sink,将采集到的数据写入日志,将日志打印在控制台
- 切换到Flume的目录下
cd /export/servers/flume-1.6.0-cdh5.14.0-bin/
- 创建案例测试目录以及测试的数据文件
mkdir userCase
cd /export/datas
touch hive.log
- 复制官方的示例程序
cd userCase/
cp ../conf/flume-conf.properties.template ./
mv flume-conf.properties.template log-console.properties
- 编辑这个文件
# define sourceName/channelName/sinkName for the agent
a1.sources = s1
a1.channels = c1
a1.sinks = k1
# define the s1
a1.sources.s1.type = exec
a1.sources.s1.command = tail -f /export/datas/hive.log
# define the c1
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# def the k1
a1.sinks.k1.type = logger
#source、channel、sink bond
a1.sources.s1.channels = c1
a1.sinks.k1.channel = c1
- 运行这个程序
- 查看命令的用法
Usage: bin/flume-ng <command> [options]...
- 具体的命令
bin/flume-ng agent -c conf/ -f userCase/log-console.properties -n a1 -Dflume.root.logger=INFO,console
--conf,-c <conf> :指定Flume的配置文件目录
--name,-n <name>:指定运行的agent的名字
--conf-file,-f <file>:指定运行哪个文件
-Dflume.root.logger=INFO,console:将Flume的日志调整为INFO级别,并显示在控制台
- 提交运行
bin/flume-ng agent -c conf/ -f userCase/log-console.properties -n a1 -Dflume.root.logger=INFO,console
- 注意:Flume是前端运行程序,如果要关闭,必须手动Ctrl+c
- 观察结果
- 刚启动
- 刚启动