天天看點

flume分布式日志收集系統操作

版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 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檔案修改配置