配置环境
1、win7;
2、jdk8;
3、flume1.9;
注:最新版flume1.9需要jdk1.8支持。
安装
jdk的安装不多赘述,flume1.9的安装如下:
1、进入官网下载页面:http://flume.apache.org/download.html
2、然后找到1.9版本下载解压到指定路径(安装路径名称不能有空格)即可。
3、编辑 apache-flume-1.9.0-bin\conf 下的flume-env.sh(如果没有,复制flume-env.sh.template重命名为flume-env.sh) 在最后行输入:export JAVA_HOME = 安装的jdk路径
检验是否安装成功
cd到apache-flume-1.9.0-bin\bin目录下,输入flume-ng version得到如下结果即安装成功。
运行实例
1、在apache-flume-1.9.0-bin\conf目录下配置好一个agent,保存为 .conf 文件 ,比如example.conf,然后把官文档中的案例内容复制到example.conf文件中,如下内容:
# example.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
a1.sources.r1.ack-every-event=false
# 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
2、cd到apache-flume-1.9.0-bin\bin目录下输入以下命令:
flume-ng.cmd agent -conf ../conf -conf-file ../conf/example.conf -name a1 -property flume.root.logger=INFO,console
或者:
flume-ng agent -conf ../conf -conf-file ../conf/example.conf -name a1 -property "flume.root.logger=INFO,console"
如果是linux系统则是:
flume-ng agent --conf ../conf --conf-file ../conf/example.conf --name a1 -Dflume.root.logger=INFO,console
其中 flume.root.logger=INFO,console 仅为 测试开发环境 使用 。
-c/--conf 后跟配置目录,-f/--conf-file 后跟具体的配置文件,-n/--name 指定agent的名称。
出现下图信息则成功运行Flume:
3、打开另一个cmd命令行窗口,输入:telnet localhost 44444 进入telnet客户端,即可输入信息,按回车结束。
如上图输入状态的telnet客户端输入信息后,flume即监听到并打印日志如下图: