Apache Flume 配置
安装 Flume 后,我们需要使用配置文件进行配置,该配置文件是一个 Java 属性文件,具有 键值对 .我们需要将值传递给文件中的键。
在 Flume 配置文件中,我们需要:
- 命名当前代理的组件。
- 描述/配置源。
- 描述/配置接收器。
- 描述/配置频道。
- 将源和接收器绑定到通道。
通常我们在 Flume 中可以有多个代理。我们可以通过使用唯一的名称来区分每个代理。并且使用这个名称,我们必须配置每个代理。
命名组件
首先,你需要命名/列出代理的源、接收器和通道等组件,如下所示。
agent_name.sources = source_name agent_name.sinks = sink_name agent_name.channels = channel_name
Flume 支持各种来源、接收器和通道。它们列在下表中。
Sources | Channels | Sinks |
---|---|---|
|
|
|
你可以使用它们中的任何一个。例如,如果你使用 Twitter 源通过内存通道将 Twitter 数据传输到 HDFS 接收器,并且代理名称 id 推特代理 , then
TwitterAgent.sources = Twitter TwitterAgent.channels = MemChannel TwitterAgent.sinks = HDFS
列出代理的组件后,你必须通过为其属性提供值来描述源、接收器和通道。
描述来源
每个源都有一个单独的属性列表。名为“type”的属性对每个源都是通用的,它用于指定我们正在使用的源的类型。
除了属性“type”之外,还需要提供所有 required 特定源的属性来配置它,如下所示。
agent_name.sources. source_name.type = value agent_name.sources. source_name.property2 = value agent_name.sources. source_name.property3 = value
例如,如果我们考虑 推特来源 , 以下是我们要得到的属性 must 提供值来配置它。
TwitterAgent.sources.Twitter.type = Twitter (type name) TwitterAgent.sources.Twitter.consumerKey = TwitterAgent.sources.Twitter.consumerSecret = TwitterAgent.sources.Twitter.accessToken = TwitterAgent.sources.Twitter.accessTokenSecret =
描述水槽
就像源一样,每个接收器都有一个单独的属性列表。名为“type”的属性对每个 sink 都是通用的,它用于指定我们正在使用的 sink 的类型。除了属性“类型”之外,还需要为所有 required 特定接收器的属性来配置它,如下所示。
agent_name.sinks. sink_name.type = value agent_name.sinks. sink_name.property2 = value agent_name.sinks. sink_name.property3 = value
例如,如果我们考虑 HDFS 接收器 , 以下是我们要得到的属性 must 提供值来配置它。
TwitterAgent.sinks.HDFS.type = hdfs (type name) TwitterAgent.sinks.HDFS.hdfs.path = HDFS directory’s Path to store the data
描述频道
Flume 提供了各种渠道来在源和接收器之间传输数据。因此,除了源和通道之外,还需要描述代理中使用的通道。
要描述每个通道,你需要设置所需的属性,如下所示。
agent_name.channels.channel_name.type = value agent_name.channels.channel_name. property2 = value agent_name.channels.channel_name. property3 = value
例如,如果我们考虑 记忆通道 , 以下是我们要得到的属性 must 提供值来配置它。
TwitterAgent.channels.MemChannel.type = memory (type name)
将 Source 和 Sink 绑定到 Channel
由于channels连接了sources和sinks,因此需要将它们都绑定到channel,如下所示。
agent_name.sources.source_name.channels = channel_name agent_name.sinks.sink_name.channels = channel_name
以下示例显示如何将源和接收器绑定到通道。在这里,我们考虑 推特来源,记忆频道, and HDFS 接收器 .
TwitterAgent.sources.Twitter.channels = MemChannel TwitterAgent.sinks.HDFS.channels = MemChannel
启动 Flume 代理
配置完成后,我们要启动 Flume 代理。完成如下:
$ bin/flume-ng agent --conf ./conf/ -f conf/twitter.conf Dflume.root.logger=DEBUG,console -n TwitterAgent
where:
-
agent : 启动 Flume 代理的命令
-
--conf ,-c
-
-f<文件> :指定一个配置文件路径,如果缺少
-
--name, -n <名称> : 推特代理名称
-
-D 属性=值 :设置一个Java系统属性值。