flume分散式日誌收集系統操作

xiaohei.info發表於2015-03-27
版權宣告:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/qq1010885678/article/details/44681127

1.flume是分散式的日誌收集系統,把收集來的資料傳送到目的地去。
2.flume裡面有個核心概念,叫做agent。agent是一個java程式,執行在日誌收集節點。
3.agent裡面包含3個核心元件:source、channel、sink。
3.1 source元件是專用於收集日誌的,可以處理各種型別各種格式的日誌資料,包括avro、thrift、exec

、jms、spooling directory、netcat、sequence generator、syslog、http、legacy、自定義。
    source元件把資料收集來以後,臨時存放在channel中。
3.2 channel元件是在agent中專用於臨時儲存資料的,可以存放在memory、jdbc、file、自定義。
    channel中的資料只有在sink傳送成功之後才會被刪除。
3.3 sink元件是用於把資料傳送到目的地的元件,目的地包括hdfs、logger、avro、thrift、ipc、file

、null、hbase、solr、自定義。
4.在整個資料傳輸過程中,流動的是event。事務保證是在event級別。
5.flume可以支援多級flume的agent,支援扇入(fan-in)、扇出(fan-out)。

6.書寫配置檔案example

#定義agent名, source、channel、sink的名稱
a4.sources = r1
a4.channels = c1
a4.sinks = k1

#具體定義source
a4.sources.r1.type = spooldir
a4.sources.r1.spoolDir = /home/hadoop/logs

#具體定義channel
a4.channels.c1.type = memory
a4.channels.c1.capacity = 10000
a4.channels.c1.transactionCapacity = 100

#定義攔截器,為訊息新增時間戳
a4.sources.r1.interceptors = i1
a4.sources.r1.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor

$Builder

#具體定義sink
a4.sinks.k1.type = hdfs
a4.sinks.k1.hdfs.path = hdfs://ns1/flume/%Y%m%d
a4.sinks.k1.hdfs.filePrefix = events-
a4.sinks.k1.hdfs.fileType = DataStream
#不按照條數生成檔案
a4.sinks.k1.hdfs.rollCount = 0
#HDFS上的檔案達到128M時生成一個檔案
a4.sinks.k1.hdfs.rollSize = 134217728
#HDFS上的檔案達到60秒生成一個檔案
a4.sinks.k1.hdfs.rollInterval = 60

#組裝source、channel、sink
a4.sources.r1.channels = c1
a4.sinks.k1.channel = c1

7.執行命令~/flume/bin/flume-ng agent -n agent1 -c conf -f conf/example –

Dflume.root.logger=DEBUG,console

執行的時候可能缺少jar包  要匯入
還要將hadoop的core-site.xml和hdfs-site.xml拷貝到flume的conf目錄下
還要將flume機器的hosts檔案修改配置


相關文章