1.安装
Java 安装
Flume配置文件解析
Flume Agent启动
(1)Flume 配置文件(Agent的配置)主要包括以下四部分配置:
--》Agent 连接的Source 、Sink、Channel名称配置;
--》Agent Source 的相关配置;
--》Agent Sink 的相关配置;
--》Agent Channel 的相关配置
其中,在Source 和 Sink 中可以配置序列化器(Serializer)来订制序列化方式,可以配置拦截器(Interceptor )来过滤指定的数据
(2)启动步骤:
--》解压apache-flume-1.6.0-bin.tar.gz到指定目录 ;
--》配置flume-conf.properties 文件;
--》使用如下命令启动Flume Agent:
bin/flume-ng agent --conf ./conf/ -f conf/flume-conf.properties -Dflume.root.logger=INFO,console -n a1 &
(3)下载flume1.6.0
http://shinyfeather.com/flume/1.6.0/apache-flume-1.6.0-bin.tar.gz
2.flume 配置文件
# example.conf: A single-node Flume configuration
# Name the components on this agent
#a1是agent的名字,r1,k1,c1也是名字
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
# Describe the sink
#输出源的类型
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
#channel选择存储在内存队列里面
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
启动
./bin/flume-ng agent --conf ./conf/ -f conf/flume-conf.properties -Dflume.root.logger=INFO,console -n a1 &
发送数据
$ telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Hello world! <ENTER>
OK
展示
12/06/19 15:32:19 INFO source.NetcatSource: Source starting
12/06/19 15:32:19 INFO source.NetcatSource: Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/127.0.0.1:44444]
12/06/19 15:32:34 INFO sink.LoggerSink: Event: { headers:{} body: 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 0D Hello world!. }