05案例 實時讀取目錄檔案

2021-09-26 15:11:30 字數 2156 閱讀 3835

實時讀取目錄檔案到hdfs案例

案例需求:使用flume監聽整個目錄的檔案

1.建立配置檔案"flume-dir-hdfsconf"
touch flume-dir-hdfs.conf

vim flume-dir-hdfs.conf

a3.sources = r3

a3.sinks = k3

a3.channels = c3

# describe/configure the source

a3.sources.r3.type = spooldir

a3.sources.r3.spooldir = /opt/module/flume/upload

a3.sources.r3.filesuffix = .completed

a3.sources.r3.fileheader = true

#忽略所有以.tmp結尾的檔案,不上傳

a3.sources.r3.ignorepattern = ([^ ]*\.tmp)

# describe the sink

a3.sinks.k3.type = hdfs

a3.sinks.k3.hdfs.path = hdfs://hadoop102:9000/flume/upload/%y%m%d/%h

#上傳檔案的字首

a3.sinks.k3.hdfs.fileprefix = upload-

#是否按照時間滾動資料夾

a3.sinks.k3.hdfs.round = true

#多少時間單位建立乙個新的資料夾

a3.sinks.k3.hdfs.roundvalue = 1

#重新定義時間單位

a3.sinks.k3.hdfs.roundunit = hour

#是否使用本地時間戳

a3.sinks.k3.hdfs.uselocaltimestamp = true

#積攢多少個event才flush到hdfs一次

a3.sinks.k3.hdfs.batchsize = 100

#設定檔案型別,可支援壓縮

a3.sinks.k3.hdfs.filetype = datastream

#多久生成乙個新的檔案

a3.sinks.k3.hdfs.rollinterval = 600

#設定每個檔案的滾動大小大概是128m

a3.sinks.k3.hdfs.rollsize = 134217700

#檔案的滾動與event數量無關

a3.sinks.k3.hdfs.rollcount = 0

#最小冗餘數

a3.sinks.k3.hdfs.minblockreplicas = 1

# use a channel which buffers events in memory

a3.channels.c3.type = memory

a3.channels.c3.capacity = 1000

a3.channels.c3.transactioncapacity = 100

# bind the source and sink to the channel

a3.sources.r3.channels = c3

a3.sinks.k3.channel = c3

2.啟動監控資料夾命令
bin/flume-ng agent --conf conf/ 

--name a3 --conf-file job/flume-dir-hdfs.conf

在使用spooling directory source時,注意:

(1)不要在監控目錄中建立並持續修改檔案

(2)上傳完成的檔案會以.completed結尾

(3)被監控資料夾每500毫秒掃瞄一次檔案變動

3.向upload資料夾中新增檔案

mkdir upload

touch hao.txt

touch hao.tmp

touch hao.log

4.檢視hdfs上的資料

"node01:50070"
5.等待1s,再次查詢upload資料夾

ll 出現那三個檔案

04案例 實時讀取本地檔案

實時讀取本地檔案到hdfs案例 案例需求 實時監控hive日誌,並上傳到hdfs中 1.flume想要將資料輸出到hdfs,必須持有hadoop相關jar包將commons configuration 1.6.jar hadoop auth 2.7.2.jar hadoop common 2.7.2...

6 案例 人臉案例

1 得到影象的特徵後,訓練乙個決策樹構建的adaboost級聯決策器來識別是否為人臉 2 opencv中自帶已訓練好的檢測器,包括面部,眼睛,貓臉等,都儲存在xml檔案中,我們可以通過以下程式找到他們 主程式如下 import cv2 as cv import matplotlib.pyplot a...

10案例分析

銀行 信用風險,即客戶違約風險,是銀行風險管控的主要內容。不同行業,不同企業,財務指標的風險程度不同。假資料,假資訊,假報表的現象,財務資訊的質量問題有三個方面是非常重要的 1.建立識別假報表的管理體系 2.研究建立財務資訊的勾稽關係,即通過相互之間的購機關係的檢驗來判別資料的質量 3.建立資料的錄...