一、Flume 架构
一个 Flume 事件被定义为一个数据流单元。Flume agent 其实是一个 JVM 进程,该进程中包含完成任务所需要的各个组件,其中最核心的三个组件是 Source、Channel 以及 Sink。
·Source
消费外部源(例如 Web 服务器或者其他 Source)传递给它的事件,并将其保存到 Channel(一个或多个)中。
·Channel
Channel 位于 Source 和 Sink 之间,用于缓存进来的 events,当 Sink 成功的将 events 发送到下一跳的 Channel 或最终目的,events 从 Channel 移除。
·Sink
Sink 负责将 events 传输到下一跳或最终目的,成功完成后将 events 从 Channel 移除。
二、使用准备
·已创建一个 EMR 集群。创建 EMR 集群 时需要在软件配置界面选择 flume 组件。
·flume 安装在 EMR 云服务器(core 节点和 task 节点)的 /usr/local/service/flume 路径下;master 节点的安装路径是 /usr/local/service/apps/。
三、配置 Flume
进入 /usr/local/service/flume 文件夹,并创建 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 # 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
四、启动 Flume
bin/flume-ng agent –conf conf –conf-file example.conf –name a1 -Dflume.root.logger=INFO,console
五、配置测试用例
配置后将会看到之前启动的 Flume Agent 向终端打印。
telnet localhost 44444Trying 127.0.0.1…Connected to localhost.localdomain (127.0.0.1).Escape character is '^]'.Hello world! <ENTER>OK