自行整理, 學(xué)習(xí)用途, 侵知?jiǎng)h歉
Flume的設(shè)計(jì)目標(biāo): 可靠性, 可量測(cè)性, 可擴(kuò)展性

Agent將數(shù)據(jù)寫成多種HDFS文件格式(text, SeqFile, JSON, Avro).
Source: 告訴節(jié)點(diǎn)從哪里接受數(shù)據(jù)
Sink: 告訴節(jié)點(diǎn)把數(shù)據(jù)發(fā)送到哪里去
Channel: Source和Sink之間的序列, 可以放在內(nèi)存或者可持續(xù)化, 持續(xù)化的掉電后不失去數(shù)據(jù)[可放入硬盤]
- 向下agent傳送失敗會(huì)回滾, 然后重試; 多臺(tái)agent向上傳輸數(shù)據(jù)如果其中一臺(tái)失敗會(huì)切換
- Flume的性能隨著機(jī)器的增加會(huì)線性的增加
擴(kuò)展性:
Source: 包括文件數(shù)據(jù), 系統(tǒng)log, 標(biāo)準(zhǔn)linux process輸出
Sink: 包括本地文件系統(tǒng)的文件, 或者HDFS
開(kāi)發(fā)者還能自己設(shè)計(jì)Source Sink
典型結(jié)構(gòu)

Flume采用了分層架構(gòu):分別為agent,collector和storage。
agent
agent的作用是將數(shù)據(jù)源的數(shù)據(jù)發(fā)送給collector。
Flume自帶了很多直接可用的數(shù)據(jù)源
source:
text(“filename”):將文件filename作為數(shù)據(jù)源,按行發(fā)送
tail(“filename”):探測(cè)filename新產(chǎn)生的數(shù)據(jù),按行發(fā)送出去
fsyslogTcp(5140):監(jiān)聽(tīng)TCP的5140端口,并且接收到的數(shù)據(jù)發(fā)送出去
tailDir("dirname"[, fileregex=".*"[, startFromEnd=false[, recurseDepth=0]]]):監(jiān)聽(tīng)目錄中的文件末尾,使用正則去選定需要監(jiān)聽(tīng)的文件(不包含目錄),recurseDepth為遞歸監(jiān)聽(tīng)其下子目錄的深度
更多整理:http://www.cnblogs.com/zhangmiao-chp/archive/2011/05/18/2050465.html
sink:
console[("format")] :直接將將數(shù)據(jù)顯示在consolr上
text(“txtfile”):將數(shù)據(jù)寫到文件txtfile中
dfs(“dfsfile”):將數(shù)據(jù)寫到HDFS上的dfsfile文件中
syslogTcp(“host”,port):將數(shù)據(jù)通過(guò)TCP傳遞給host節(jié)點(diǎn)
agentSink[("machine"[,port])]:等價(jià)于agentE2ESink,如果省略,machine參數(shù),默認(rèn)使用flume.collector.event.host與flume.collector.event.port作為默認(rèn)collecotr
agentDFOSink[("machine" [,port])]:本地?zé)醾鋋gent,agent發(fā)現(xiàn)collector節(jié)點(diǎn)故障后,不斷檢查collector的存活狀態(tài)以便重新發(fā)送event,在此間產(chǎn)生的數(shù)據(jù)將緩存到本地磁盤中
agentBESink[("machine"[,port])]:不負(fù)責(zé)的agent,如果collector故障,將不做任何處理,它發(fā)送的數(shù)據(jù)也將被直接丟棄
agentE2EChain:指定多個(gè)collector提高可用性。 當(dāng)向主collector發(fā)送event失效后,轉(zhuǎn)向第二個(gè)collector發(fā)送,當(dāng)所有的collector失敗后,它會(huì)非常執(zhí)著的再來(lái)一遍
更多整理:http://www.cnblogs.com/zhangmiao-chp/archive/2011/05/18/2050472.html
collector
collector的作用是將多個(gè)agent的數(shù)據(jù)匯總后,加載到storage中。
它的source和sink與agent類似
安裝, 配置, 啟動(dòng)Flume
安裝:
-sudo yum install flume-ng
-sudo yum install flume-ng-agent
配置產(chǎn)生數(shù)據(jù)的Agent節(jié)點(diǎn):
/etc/flume-ng/conf/flume-conf.properties文件決定了source,sinks,channels以及agent內(nèi)的flow
啟動(dòng):
#啟動(dòng)一個(gè)host上的單個(gè)Flume agent
sudo service flume-ng-agent start
#啟動(dòng)一個(gè)host上的多個(gè)Flume agent
flume-ng --name <agent_name>
運(yùn)行實(shí)例
1.安裝
$ sudo yum install --assumeyes flume-ng
2. 創(chuàng)建配置文件excample.conf
# example.conf: A single-node Flume configuration
# 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
3. 終端(A)啟動(dòng)Agent
$ flume-ng agent \
-c conf \
-f /opt/wanghaixin/01.flume/example.conf \
-n a1 \
-Dflume.root.logger=INFO,console
4. 開(kāi)啟另一個(gè)終端(B)通過(guò)telnet對(duì)端口44444注入內(nèi)容, 充當(dāng)source
$ telnet localhost 44444
#接著可以鍵盤輸入, 如輸入 :hhhhh
5. 在終端(A)可觀察到打印
$ hadoop fs -ls flume/collector1

更多資料:
http://flume.apache.org/FlumeUserGuide.html
http://www.cnblogs.com/oubo/archive/2012/05/25/2517751.html