Flume 採集目錄到HDFS

2021-10-02 10:16:50 字數 2450 閱讀 9394

需求某服務器的某特定目錄下,會不斷產生新的檔案,每當有新檔案出現,就需要把檔案採集到hdfs中去

思路根據需求,首先定義以下3大要素

1. 資料來源元件,即source ——監控檔案目錄 : spooldir

1. 監視乙個目錄,只要目錄**現新檔案,就會採集檔案中的內容

2. 採集完成的檔案,會被agent自動新增乙個字尾:completed

3. 所監視的目錄中不允許重複出現相同檔名的檔案

2. 下沉元件,即sink——hdfs檔案系統 : hdfs sink

3. 通道元件,即channel——可用file channel 也可以用記憶體channel

cd  /usr/flume/conf

mkdir /usr/dirfile

vim spooldir.conf

#name the components on this agent 

a1.sources = r1

a1.sinks = k1

a1.channels = c1

# describe/configure the source

##注意:不能往監控目中重複丟同名檔案

a1.sources.r1.type = spooldir #conf

a1.sources.r1.spooldir = /usr/dirfile #所監控的資料夾

a1.sources.r1.fileheader = true

# describe the sink flume目錄資料採集

a1.sinks.k1.type = hdfs

a1.sinks.k1.channel = c1

a1.sinks.k1.hdfs.path = hdfs://node01:8020/spooldir/files/%y-%m-%d/%h%m/ a1.sinks.k1.hdfs.fileprefix = events- #檔案字首

a1.sinks.k1.hdfs.round = true # 是否使用檔案滾動

a1.sinks.k1.hdfs.roundvalue = 10 #hdfs檔案滾動週期

a1.sinks.k1.hdfs.roundunit = minute

a1.sinks.k1.hdfs.rollinterval = 3 #每三秒產生新檔案

a1.sinks.k1.hdfs.rollsize = 20 #臨時檔案大小達到20個位元組

a1.sinks.k1.hdfs.rollcount = 5 #臨時檔案大小達到5個event時

a1.sinks.k1.hdfs.batchsize = 1 #channel中event轉入transactioncapacity的數量

a1.sinks.k1.hdfs.uselocaltimestamp = true

#生成的檔案型別,預設是sequencefile,可用datastream,則為普通文字

a1.sinks.k1.hdfs.filetype = datastream

# use a channel which buffers events in memory

a1.channels.c1.type = memory

a1.channels.c1.capacity = 1000 #channels容量

a1.channels.c1.transactioncapacity = 100 #channels一次向sinks傳遞的檔案數

# bind the source and sink to the channel

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

step 2: 啟動 flume

flume-ng agent -c conf -f conf/spooldir.conf -n a1 -dflume.root.logger=info,console

flume-ng flume版本

-c conf 指定flume自身的配置檔案所在目錄

-f conf/spooldir.con 指定我們所描述的採集方案

-n a1 指定我們這個agent的名字

step 3: 上傳檔案到指定目錄

將不同的檔案上傳到下面目錄里面去,注意檔案不能重名,盡量純英文

flume 採集 目錄到 到 HDFS

案例 採集 目錄到 到 hdfs 採集需求 某伺服器的某特定目錄下,會不斷產生新的檔案,每當有新檔案出現,就需要把檔案採集到 hdfs 中去。根據需求,首先定義以下 3 大要素 資料來源元件,即 source 監控檔案目錄 spooldir spooldir 特性 1 監視乙個目錄,只要目錄中出現新...

Flume採集目錄及檔案到HDFS案例

使用flume採集目錄需要啟動hdfs集群 vi spool hdfs.conf name the components on this agent a1.sources r1 a1.sinks k1 a1.channels c1 describe configure the source 注意 不...

Flume採集檔案到HDFS

在flume和hadoop安裝好的情況下 1.遇到的坑 在安裝hadoop時,配置 core site.xml 檔案一定要注意。fs.defaultfs name hdfs master 9000 value property 上述的value值使用的是主機名稱 master 或者ip位址,不能使用...