1. 程式人生 > >Apache Flume簡介及安裝部署

Apache Flume簡介及安裝部署

display 根據 buffers type hello headers agent tran 結構圖

概述

Flume 是 Cloudera 提供的一個高可用的,高可靠的,分布式的海量日誌采集、聚合和傳輸的軟件

Flume 的核心是把數據從數據源(source)收集過來,再將收集到的數據送到指定的目的地(sink)。為了保證輸送的過程一定成功,在送到目的地(sink)之前,會先緩存數據(channel),待數據真正到達目的地(sink)後,flume 在刪除自己緩存的數據。

Flume 支持定制各類數據發送方,用於收集各類型數據;同時,Flume 支持定制各種數據接受方,用於最終存儲數據。一般的采集需求,通過對 flume 的簡單配置即可實現。針對特殊場景也具備良好的自定義擴展能力。因此,flume 可以適用於大部分的日常數據采集場景

運行機制

  Flume 系統中核心的角色是 agent,agent 本身是一個 Java 進程,一般運行在日誌收集節點。

  •   每一個 agent 相當於一個數據傳遞員,內部有三個組件:

    Source:采集源,用於跟數據源對接,以獲取數據;

    Sink:下沈地,采集數據的傳送目的,用於往下一級 agent 傳遞數據或者往最終存儲系統傳遞數據;

    Channel:agent 內部的數據傳輸通道,用於從 source 將數據傳遞到 sink;

  •   在整個數據的傳輸的過程中,流動的是 event,它是 Flume 內部數據傳輸的最基本單元。event 將傳輸的數據進行封裝。如果是文本文件,通常是一行記錄,event 也是事務的基本單位。event 從 source,流向 channel,再到 sink,本身為一個字節數組,並可攜帶 headers(頭信息)信息。event 代表著一個數據的最小完整單元,從外部數據源來,向外部的目的地去。
  •   一個完整的 event 包括:event headers、event body、event 信息,其event 信息就是 flume 收集到的日記記錄。

Flume采集系統結構圖

  簡單結構:

      單個 agent 采集數據

技術分享圖片

  復雜結構

      多級 agent 之間串聯

技術分享圖片

Flume安裝部署

  • 上傳安裝包到數據源所在節點上
  • 解壓
tar -zxvf apache-flume-1.6.0-bin.tar.gz
  • 根據數據采集需求 配置采集方案,描述在配置文件中(文件名可任意自定義)

    在 flume 的 的 conf 目錄下新建一個文件

vi netcat-logger.conf
#從網絡端口接收數據,下沈到logger
#采集配置文件,netcat-logger.conf

# 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 agent
bin/flume-ng agent --conf conf --conf-file conf/netcat-logger.conf --name a1 -Dflume.root.logger=INFO,console

#--conf 指定flume自帶配置文件位置(簡寫-c)

#--conf-file指定采集方案是哪一個(-f)

#--name 給本次flume agent起個名字

  • 測試
#安裝telnet
yum install -y telnet

傳入數據:
$ telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]‘.
Hello world! <ENTER>
OK

Apache Flume簡介及安裝部署