通過Apache Flume向HDFS儲存資料

2021-09-14 05:01:16 字數 1896 閱讀 9400

本筆記基於hadoop2.7.3,apache flume 1.8.0。其中flume source為netcat,flume channel為memory,flume sink為hdfs。

1,配置flume**檔案

配置乙個flume agent**,在此名稱為shaman。配置檔案(netcat-memory-hdfs.conf)如下:

# identify the components on agent shaman:

shaman.sources = netcat_s1

shaman.sinks = hdfs_w1

shaman.channels = in-mem_c1

# configure the source:

shaman.sources.netcat_s1.type = netcat

shaman.sources.netcat_s1.bind = localhost

shaman.sources.netcat_s1.port = 44444

# describe the sink:

shaman.sinks.hdfs_w1.type = hdfs

shaman.sinks.hdfs_w1.hdfs.path = hdfs://localhost:8020/user/root/test

shaman.sinks.hdfs_w1.hdfs.writeformat = text

shaman.sinks.hdfs_w1.hdfs.filetype = datastream

# configure a channel that buffers events in memory:

shaman.channels.in-mem_c1.type = memory

shaman.channels.in-mem_c1.capacity = 20000

shaman.channels.in-mem_c1.transactioncapacity = 100

# bind the source and sink to the channel:

shaman.sources.netcat_s1.channels = in-mem_c1

shaman.sinks.hdfs_w1.channel = in-mem_c1

備註:

hdfs://localhost:8020/user/root/test,其中hdfs://localhost:8020為hadoop配置檔案core-site.xml中

fs.defaultfs屬性的值,root為hadoop的登陸使用者。

2,啟動flume**

bin/flume-ng agent -f agent/netcat-memory-hdfs.conf -n shaman  -dflume.root.logger=debug,console -dorg.apache.flume.log.printconfig=true -dorg.apache.flume.log.rawdata=true
3,開啟telnet客戶端,輸入字母測試

telnet localhost 44444
然後輸入文字

4,檢視hdfs test目錄

hdfs dfs -ls /user/root/test
會發現有新的檔案出現,檔案裡面的內容即是通過telent輸入的字母。

學習資料:

1,《hadoop for dummies》

2,flume 1.8.0 user guide

通過HTMLExtractor向HTML要資料

西安市國土資源資訊中心 李博 如何不斷擴充資料中心的資料規模,提公升資料探勘的價值,這是我們思考的問題,資料一方面來自於內部生產,一部分資料可以來自於網際網路,網際網路上的資料體量龐大,形態多樣,之前blog裡很多fmeer已經提出了方案,比如json,xml,正規表示式等等,但對於比較鬆散的htm...

通過管道向 hadoop put 檔案

使用 hadoop file shell 可以方便地向 hdfs put 檔案,但是,該 shell 不支援從管道讀取資料並放到 hdfs 檔案中。它僅支援這樣的 put 命令 cd hadoop home bin hadoop fs put localfile hdfsfile bin hadoo...

通過jquery的ajax向struts2傳遞引數

通過jquery的 getjson 方法向struts2後台action傳遞引數,目前,我所知道的且經過實踐證明正確可行的方法,有兩種 第一種 如下 var dataid hello,my friends getjson action function data 注意,紅色背景部分的表示式就是要傳遞...