1.基本結構介紹java
flume是三層架構,agent,collector,storage。每一層均可水平擴展。node
其中,agent就是數據採集方;collector是數據整合方;storage是各類數據落地方,如hdfs。linux
前二者都是由source和sink組成,source是數據讀取組件,sink是數據分發組件。web
前二者做爲不一樣類型node統一歸master管理。可在master shell活web中動態配置。shell
2.自帶的sourceapache
text 文件,按行發送windows
tail 探測新產生數據,安航發送服務器
fsyslog Tcp(5140) 監聽這個端口架構
tailDir("dirname"[, fileregex=".*"[, startFromEnd=false[, recurseDepth=0]]]):監聽目錄中的文件末尾,使用正則去選定須要監聽的文件(不包含目錄),recurseDepth爲遞歸監聽其下子目錄的深度工具
3.想採集windows服務器上的日誌文件,因而,研究了flume怎麼在windows下部署。
a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = exec a1.sources.r1.channels = c1 a1.sources.r1.command = tail -f D:\hadoopResouce\flume\logs\log_exec_tail.txt # 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
其實裏面須要修改的就是須要採集的文件全路徑
set FLUME_HOME=D:\hadoopResouce\flume set JAVA_HOME=D:\jdk1.8 set JAVA="%JAVA_HOME%\bin\java.exe" set JAVA_OPTS=-Xmx1024m set CONF=%FLUME_HOME%\conf\flume-conf.properties set AGENT=agent %JAVA% %JAVA_OPTS% -Dflume.monitoring.type=http -Dflume.monitoring.port=34545 -Dlog4j.configuration=file:\\\%FLUME_HOME%\conf\log4j.properties -cp "%FLUME_HOME%\lib\*" org.apache.flume.node.Application -f %FLUME_HOME%\conf\flume-conf.properties -n %AGENT%
須要注意的是幾處路徑的配置
{ SOURCE.seqGenSrc: { EventReceivedCount: "0", Type: "SOURCE", AppendBatchAcceptedCount: "0", EventAcceptedCount: "2532", AppendReceivedCount: "0", StartTime: "1468487063825", AppendAcceptedCount: "0", OpenConnectionCount: "0", AppendBatchReceivedCount: "0", StopTime: "0" }, CHANNEL.memoryChannel: { ChannelCapacity: "100", ChannelFillPercentage: "99.0", Type: "CHANNEL", EventTakeSuccessCount: "2423", ChannelSize: "99", StartTime: "1468487063801", EventTakeAttemptCount: "2424", EventPutAttemptCount: "2524", EventPutSuccessCount: "2523", StopTime: "0" } }
4.讀取目錄新增長文件內容的配置
a1.sources.r1.type = spooldir a1.sources.r1.channels = c1 a1.sources.r1.spoolDir = /home/master/yang/flume/logs a1.sources.r1.fileHeader = true
5.寫入kafka的配置
這裏踩的坑較多,一種多是老版本配置,還有一種就是有的人沒通過試驗的東西就貼出來了。引覺得戒,本身測試經過再貼,保持嚴謹,省得誤人。
//看好類全路徑是否都對,網上有不靠譜的寫法,org.apache.flume.plugins.SinglePartition 使人鄙視 a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink //不知道爲何不少人這裏項寫爲:a1.sinks.k1.metadata.broker.list,多是以前版本有這個吧 a1.sinks.k1.brokerList =master:9092,slave1:9092,slave2:9092 a1.sinks.k1.serializer.class=kafka.serializer.StringEncoder //還有這玩意,這寫法太坑人了a1.sinks.k1.custom.topic.name a1.sinks.k1.topic=kafka-storm-cluster a1.sinks.k1.channel=c1
6.讀取telnet監控內容配置sink
a1.sources.r1.type= netcat a1.sources.r1.bind= localhost a1.sources.r1.port= 44444
7.經常使用命令:
啓動: bin/flume-ng agent -c ./conf/ -f conf/spool.conf -Dflume.root.logger=DEBUG,console -n a1