日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Flume实操(二)【实时读取本地文件到HDFS案例】

發布時間:2024/2/28 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flume实操(二)【实时读取本地文件到HDFS案例】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1)案例需求:實時監控本地一文件,并上傳到HDFS中

2)需求分析:【圖示為Hive啟動日志,這里做一個更為普通的本地文件】

3)實現步驟:

1.Flume要想將數據輸出到HDFS,必須持有Hadoop相關jar包

Cd /opt/hadoop-2.6.5 find ./ -name "commons-configuration-1.6.jar" cp./share/hadoop/common/lib/commons-configuration-1.6.jar ../flume/lib/ find ./ -name "hadoop-auth-2.6.5.jar" cp./share/hadoop/tools/lib/hadoop-auth-2.6.5.jar find ./ -name "hadoop-common-2.6.5.jar" cp./share/hadoop/common/hadoop-common-2.6.5.jar ../flume/lib/ find ./ -name "hadoop-hdfs-2.6.5.jar" cp./share/hadoop/hdfs/hadoop-hdfs-2.6.5.jar ../flume/lib/ find ./ -name "commons-io-2.4.jar" cp ./share/hadoop/common/lib/commons-io-2.4.jar find ./ -name "htrace-core-*.jar" cp./share/hadoop/common/lib/htrace-core-3.0.4.jar ../flume/lib/

2.創建flume-file-hdfs.conf文件

還是在/opt/flume/job/下

touch flume-file-hdfs.conf

注:要想讀取Linux系統中的文件,就得按照Linux命令的規則執行命令。由于Hive日志在Linux系統中所以讀取文件的類型選擇:exec即execute執行的意思。表示執行Linux命令來讀取文件。

vim flume-file-hdfs.conf # Name the components on this agent a2.sources = r2 a2.sinks = k2 a2.channels = c2# Describe/configure the source a2.sources.r2.type = exec a2.sources.r2.command = tail -F /opt/logs/xx.log a2.sources.r2.shell = /bin/bash -c# Describe the sink a2.sinks.k2.type = hdfs a2.sinks.k2.hdfs.path = hdfs://mycluster/flume/%Y%m%d/%H #上傳文件的前綴 a2.sinks.k2.hdfs.filePrefix = logs- #是否按照時間滾動文件夾 a2.sinks.k2.hdfs.round = true #多少時間單位創建一個新的文件夾 a2.sinks.k2.hdfs.roundValue = 1 #重新定義時間單位 a2.sinks.k2.hdfs.roundUnit = hour #是否使用本地時間戳 a2.sinks.k2.hdfs.useLocalTimeStamp = true #積攢多少個Event才flush到HDFS一次 a2.sinks.k2.hdfs.batchSize = 1000 #設置文件類型,可支持壓縮 a2.sinks.k2.hdfs.fileType = DataStream #多久生成一個新的文件 a2.sinks.k2.hdfs.rollInterval = 600 #設置每個文件的滾動大小 a2.sinks.k2.hdfs.rollSize = 134217700 #文件的滾動與Event數量無關 a2.sinks.k2.hdfs.rollCount = 0 #最小冗余數 a2.sinks.k2.hdfs.minBlockReplicas = 1# Use a channel which buffers events in memory a2.channels.c2.type = memory a2.channels.c2.capacity = 1000 a2.channels.c2.transactionCapacity = 100# Bind the source and sink to the channel a2.sources.r2.channels = c2 a2.sinks.k2.channel = c2

各參數解釋:

3. 執行監控配置

flume-ng agent --conf conf/ --name a2 --conf-file job/flume-file-hdfs.conf

4.往xx.log中輸入信息

5.查看hdfs文件信息

【友情補充】

此情形可以應用于hive上,在hive的外部表中我們的表數據在hdfs上,所以,點到為止。溜了溜了!!!

總結

以上是生活随笔為你收集整理的Flume实操(二)【实时读取本地文件到HDFS案例】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。