這兩天看了一下Flume的開發文檔,而且體驗了下Flume的使用。html
本文就從以下的幾個方面講述下個人使用心得:java
Flume的配置是真繁瑣,source,channel,sink的關係在配置文件裏面交織在一塊兒,沒有Logstash那麼簡單明瞭。node
Flume與Logstash相比,我我的的體會以下:redis
Logstash中:shell
在Logstash比較看重input,filter,output之間的協同工做,所以多個輸入會把數據彙總到input和filter之間的buffer中。filter則會從buffer中讀取數據,進行過濾解析,而後存儲在filter於output之間的Buffer中。當buffer知足必定的條件時,會觸發output的刷新。apache
在Flume中:windows
Flume比較看重數據的傳輸,所以幾乎沒有數據的解析預處理。僅僅是數據的產生,封裝成event而後傳輸。傳輸的時候flume比logstash多考慮了一些可靠性。由於數據會持久化在channel中(通常有兩種能夠選擇,memoryChannel就是存在內存中,另外一個就是FileChannel存儲在文件種),數據只有存儲在下一個存儲位置(多是最終的存儲位置,如HDFS;也多是下一個Flume節點的channel),數據纔會從當前的channel中刪除。這個過程是經過事務來控制的,這樣就保證了數據的可靠性。app
不過flume的持久化也是有容量限制的,好比內存若是超過必定的量,也同樣會爆掉。elasticsearch
在官網下載最新版本http://flume.apache.org/download.html,目前最新的版本是1.6.0ide
默認flume是不支持windows的,沒有bat的啓動命令。不過有一個flume-ng.cmd,其實它也不是啓動文件,只是啓動了一個powershell而已,若是你本地有這個軟件,就能夠在windows下運行了。
powershell.exe -NoProfile -InputFormat none -ExecutionPolicy unrestricted -File %~dp0flume-ng.ps1 %*
存放了啓動腳本
啓動所需的全部組件jar包
提供了幾個測試配置文件
文檔
跟日誌輸出有關的一個jar包(不知道有什麼不一樣)
# 關於license的一大堆 blabla # 配置sources,channels,sinks的名稱 agent.sources = seqGenSrc agent.channels = memoryChannel agent.sinks = loggerSink # 配置sources是哪種類型,注意能夠由多個source哦! # seq 是專門給測試用的,會自動產生一大堆數據。 # (其實我以爲stdin最好,不過flume沒這個source) agent.sources.seqGenSrc.type = seq # 配置source輸出的channel爲memoryChannel(名稱,你也能夠叫c1) agent.sources.seqGenSrc.channels = memoryChannel # 配置sink是哪種類型,本例子爲logger,即log4j輸出。 # (log4j會參考conf下的log4j.properties文件,通常開啓consoleAppender作測試就行) agent.sinks.loggerSink.type = logger # 配置sink取數據的channel爲memoryChannel,注意跟上面的名字保持一致哦! agent.sinks.loggerSink.channel = memoryChannel # 配置channel的類型 agent.channels.memoryChannel.type = memory # 配置channel的容量 agent.channels.memoryChannel.capacity = 100
而後在flume目錄下,輸入下面的命令:
bin/flume-ng agent --conf-file conf/flume-conf.properties.template --name agent -Dflume.root.logger=INFO,console -C .
而後就能夠看到滿屏滾動的信息了!
注意:上面啓動命令沒一個字母是廢話!
你能夠輸入flume-ng help
得到幫助提示:
[root@10 /xinghl/flume]$ bin/flume-ng hekp Usage: bin/flume-ng <command> [options]... commands: help display this help text agent run a Flume agent avro-client run an avro Flume client version show Flume version info global options: --conf,-c <conf> use configs in <conf> directory --classpath,-C <cp> append to the classpath --dryrun,-d do not actually start Flume, just print the command --plugins-path <dirs> colon-separated list of plugins.d directories. See the plugins.d section in the user guide for more details. Default: $FLUME_HOME/plugins.d -Dproperty=value sets a Java system property value -Xproperty=value sets a Java -X option agent options: --name,-n <name> the name of this agent (required) --conf-file,-f <file> specify a config file (required if -z missing) --zkConnString,-z <str> specify the ZooKeeper connection to use (required if -f missing) --zkBasePath,-p <path> specify the base path in ZooKeeper for agent configs --no-reload-conf do not reload config file if changed --help,-h display help text avro-client options: --rpcProps,-P <file> RPC client properties file with server connection params --host,-H <host> hostname to which events will be sent --port,-p <port> port of the avro source --dirname <dir> directory to stream to avro source --filename,-F <file> text file to stream to avro source (default: std input) --headerFile,-R <file> File containing event headers as key/value pairs on each new line --help,-h display help text Either --rpcProps or both --host and --port must be specified.
這裏就挑重要的參數將了:
這個是很重要的參數,由於flume可使用不一樣的角色啓動,好比agent以及client等等。暫時搞不清楚avro-client有什麼特殊的,先了解一下吧!平時啓動就使用agent就能夠了。
--conf 或者 -c ,指定去conf目錄下加載配置文件
--classpath 或者 -C,指定類加載的路徑(不知道爲何我下載flume版本啓動的時候找不到log4j配置,只能加上 -C .
才能啓動!)
-Dproperty=value 這個參數比較重要,好比logger就須要它來指定傳輸的級別等信息。若是沒有這個參數,logger就很差使了。
其中最終要的就是 --name 或者 -n ,它指定了啓動agent的名稱,注意是啓動agent的名稱。
這個名稱必須與配置文件中的同樣
這個名稱必須與配置文件中的同樣
這個名稱必須與配置文件中的同樣
重要的事情重複三遍!
若是寫錯了!一段小異常就跑來了~(好比我配置文件中爲agent,啓動命令中寫agent123)
2016-06-30 17:04:19,529 (conf-file-poller-0) [WARN - org.apache.flume.node.AbstractConfigurationProvider.getConfiguration(AbstractConfigurationProvider.java:133)] No configuration found for this host:agent123
另外,就是經過--conf-file 或者 -f 指定配置文件。若是配置文件放在conf,也等同於--conf。
參數就介紹到這裏了。