- Apache Flume 教程
- Apache Flume - 首頁
- Apache Flume - 簡介
- Hadoop 中的資料傳輸
- Apache Flume - 架構
- Apache Flume - 資料流
- Apache Flume - 環境
- Apache Flume - 配置
- Apache Flume - 獲取 Twitter 資料
- 序列生成器源
- Apache Flume - NetCat 源
- Apache Flume 資源
- Apache Flume - 快速指南
- Apache Flume - 有用資源
- Apache Flume - 討論
Apache Flume - 配置
安裝 Flume 後,我們需要使用配置檔案對其進行配置,該配置檔案是一個 Java 屬性檔案,包含**鍵值對**。我們需要將值傳遞給檔案中的鍵。
在 Flume 配置檔案中,我們需要 -
- 命名當前代理的元件。
- 描述/配置源。
- 描述/配置接收器。
- 描述/配置通道。
- 將源和接收器繫結到通道。
通常,我們可以在 Flume 中有多個代理。我們可以使用唯一的名稱來區分每個代理。並使用此名稱,我們需要配置每個代理。
命名元件
首先,您需要命名/列出代理的元件,例如源、接收器和通道,如下所示。
agent_name.sources = source_name agent_name.sinks = sink_name agent_name.channels = channel_name
Flume 支援各種源、接收器和通道。它們列在下面給出的表中。
| 源 | 通道 | 接收器 |
|---|---|---|
|
|
|
您可以使用其中任何一個。例如,如果您正在使用 Twitter 源透過記憶體通道將 Twitter 資料傳輸到 HDFS 接收器,並且代理名稱為**TwitterAgent**,則
TwitterAgent.sources = Twitter TwitterAgent.channels = MemChannel TwitterAgent.sinks = HDFS
列出代理的元件後,您必須透過為其屬性提供值來描述源、接收器和通道。
描述源
每個源都將具有單獨的屬性列表。名為“type”的屬性對每個源都是通用的,它用於指定我們正在使用的源的型別。
除了屬性“type”之外,還需要提供特定源的所有**必需**屬性的值來對其進行配置,如下所示。
agent_name.sources. source_name.type = value agent_name.sources. source_name.property2 = value agent_name.sources. source_name.property3 = value
例如,如果我們考慮**twitter 源**,以下是我們必須提供值以對其進行配置的屬性。
TwitterAgent.sources.Twitter.type = Twitter (type name) TwitterAgent.sources.Twitter.consumerKey = TwitterAgent.sources.Twitter.consumerSecret = TwitterAgent.sources.Twitter.accessToken = TwitterAgent.sources.Twitter.accessTokenSecret =
描述接收器
就像源一樣,每個接收器都將具有單獨的屬性列表。名為“type”的屬性對每個接收器都是通用的,它用於指定我們正在使用的接收器的型別。除了屬性“type”之外,還需要提供特定接收器所有**必需**屬性的值來對其進行配置,如下所示。
agent_name.sinks. sink_name.type = value agent_name.sinks. sink_name.property2 = value agent_name.sinks. sink_name.property3 = value
例如,如果我們考慮**HDFS 接收器**,以下是我們必須提供值以對其進行配置的屬性。
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
例如,如果我們考慮**記憶體通道**,以下是我們必須提供值以對其進行配置的屬性。
TwitterAgent.channels.MemChannel.type = memory (type name)
將源和接收器繫結到通道
由於通道連線源和接收器,因此需要將兩者都繫結到通道,如下所示。
agent_name.sources.source_name.channels = channel_name agent_name.sinks.sink_name.channels = channel_name
以下示例顯示瞭如何將源和接收器繫結到通道。在這裡,我們考慮**twitter 源、記憶體通道**和**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
其中 -
**agent** - 啟動 Flume 代理的命令
**--conf ,-c<conf>** - 使用 conf 目錄中的配置檔案
**-f<file>** - 指定配置檔案路徑(如果缺少)
**--name, -n <name>** - twitter 代理的名稱
**-D property =value** - 設定 Java 系統屬性值。