標籤:建立檔案 pool bbs 安裝 hba 執行命令 local ext memory
1.flume是分布式的日誌收集系統,把收集來的資料傳送到目的地去。
2.flume裡面有個核心概念,叫做agent。agent是一個java進程,運行在日誌收集節點。通過agent接收日誌,然後暫存起來,再發送到目的地。
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、安裝Flume:
1、先將flume的bin.jar和src.jar複製到/usr/local下,然後解壓,將src目錄下的檔案複製到bin目錄下:cp -ri apache-flume-1.4.0-src/* apache-flume-1.4.0-bin/
2、刪除/usr/lcoal下的解壓好的src檔案,再將bin重新命名:mv apache-flume-1.4.0-bin flume
3、flume/bin/ #flume-ng 可以看到命令的相關用法
4、核心是寫設定檔
7.書寫設定檔example
在flume/conf/下建立設定檔example:
vi example 或者直接在winSCP中建立
#agent1表示代理名稱agent1.sources=source1agent1.sinks=sink1agent1.channels=channel1#Spooling Directory是監控指定檔案夾中新檔案的變化,一旦新檔案出現,就解析該檔案內容,然後寫入到channle。寫入完成後,標記該檔案已完成或者刪除該檔案。#配置source1 interceptor可以在資料傳遞過程中改變其屬性資訊agent1.sources.source1.type=spooldiragent1.sources.source1.spoolDir=/root/hmbbsagent1.sources.source1.channels=channel1agent1.sources.source1.fileHeader = falseagent1.sources.source1.interceptors = i1 agent1.sources.source1.interceptors.i1.type = timestamp#配置sink1agent1.sinks.sink1.type=hdfsagent1.sinks.sink1.hdfs.path=hdfs://hadoop0:9000/hmbbsagent1.sinks.sink1.hdfs.fileType=DataStreamagent1.sinks.sink1.hdfs.writeFormat=TEXTagent1.sinks.sink1.hdfs.rollInterval=1agent1.sinks.sink1.channel=channel1agent1.sinks.sink1.hdfs.filePrefix=%Y-%m-%d#配置channel1agent1.channels.channel1.type=fileagent1.channels.channel1.checkpointDir=/root/hmbbs_tmp/123agent1.channels.channel1.dataDirs=/root/hmbbs_tmp/
在/root下建立檔案夾hmbbs:mkdir hmbbs
在HDFS中建立檔案夾:hadoop fs -mkdir /hmbbs
8.執行命令bin/flume-ng agent -n agent1 -c conf -f conf/example -Dflume.root.logger=DEBUG,console
執行完了,flume就會監控/root/hmbbs中資料的變化
在/root/hmbbs下:
vi hello
helloyou
hellome
cp hello hmbbs
現在資料就發生了變化!flume就會監控到變化,並把資料檔案上傳到hdfs中
可在hadoop0:50070中觀察到記錄檔
也可在hadoop0/root/hmbbs下,觀察到有個hello.COMPLETED,之前的hello變成了hello.COMPLETED(因為這裡使用的是Spooling Directory導致的。對hello從不刪除,上傳完成只會重新命名)
在/root/hmbbs_tmp目錄下,這個目錄是channel使用的目錄。在/root/hmbbs_tmp123目錄下,表示的是備份資料。
Flume分布式日誌收集系統