一、如何使用flume將檔案存到hdfs
簡單例子:
啟動這個flume**,可以將監控路徑下的檔案通過channel傳輸到hdfs.path屬性的路徑中。#set name
agent1.sources = source1
agent1.channels = channel1
agent1.sinks = sink1
#link sources and sinks
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1
#set sources
agent1.sources.source1.type = spooldir
agent1.sources.source1.spooldir = 監控路徑
#set sinks 、necessary set in this example
agent1.sinks.sink1.type = hdfs
agent1.sinks.sink1.hdfs.path = 儲存到hdfs的路徑
#not necessary set in this example
agent1.sinks.sink1.hdfs.fileprefix = events
agent1.sinks.sink1.hdfs.filesuffix = .log
#下面這個屬性預設為空
agent1.sinks.sink1.inuseprefix = _
agent1.sinks.sink1.hdfs.filetype = datastream
#set channels
agent1.channels.channel1.type = file
上面這個例子使用了一些預設配置。包括在超過了給定的開啟時間(預設30s)之後,會將開啟的檔案通過channel傳輸到sink。這裡會存在乙個問題-》可能生成的內容太少了,每次都往hdfs中傳輸大量的小檔案,降低了mapreduce效率。
解決方式:
第乙個:
hdfs.rollinterval屬性設定開啟時間,使時間足夠長,獲取足夠多的內容。
第二個:
hdfs.rollsize屬性設定檔案大小,當檔案達到一定的大小的時候才傳輸(預設1024個位元組)
第三個:
hdfs.rollcount屬性設定接受的事件數目,當檔案寫滿了給定數量的事件之後才傳輸。
Flume 基本使用
配置agent init a1.sources s1 a1.channels c1 a1.sinks k1 sources 1 動態監控單個日誌檔案 a1.sources.s1.type exec a1.sources.s1.command tail f opt cdh5.7.6 hive 1.1....
Flume 將資料匯入Hive
flume 將資料匯入hive 1 建立.conf檔案 cd usr tmp mkdir flumesrc vim netcat to hive user.conf a1.sources r1 a1.sinks s1 a1.channels c1 a1.sources.r1.type netcat ...
Flume(03) Flume採集案例
需求分析 採集需求 某伺服器的某特定目錄 export servers dirfile下,會不斷產生新的檔案,每當有新檔案出現,就需要把檔案採集到hdfs中去。需求分析 通過flume採集資料,最重要的就是配置三大元件。這裡可以通過source來監控檔案目錄。通過channel,來將source採集...