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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Flume实战监听文件夹内文件变化

發布時間:2025/3/11 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flume实战监听文件夹内文件变化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


Flume官網有多種場景的source,sink,channel的配置







1、flume安裝目錄下新建文件夾 example?

2、在example下新建文件?

spooldir-logger.conf

內容如下:

a1.sources = r1 a1.sinks = k1 a1.channels = c1# Describe/configure the source a1.sources.r1.type = spooldir a1.sources.r1.spoolDir = /home/hadoop/flume_test a1.sources.r1.fileHeader = true# Describe the sink a1.sinks.k1.type = logger# Use a channel which buffers events in memory a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1

3、創建文件夾??/home/hadoop/flume_test


4、啟動,

命令:flume-ng agent -c ../conf -f spooldir-logger.conf -n a1 -Dflume.root.logger=INFO,console


5、在flume_test文件夾下新建文件

echo "11111" ?>> ?hello.txt

flume_test文件夾下多了個文件:hello.txt.COMPLETED


但flume報錯了。

2017-03-22 21:55:50,005 (pool-3-thread-1) [ERROR - org.apache.flume.source.SpoolDirectorySource$SpoolDirectoryRunnable.run(SpoolDirectorySource.java:280)] FATAL: Spool Directory source r1: { spoolDir: /home/hadoop/flume_test }: Uncaught exception in SpoolDirectorySource thread. Restart or reconfigure Flume to continue processing. java.lang.IllegalStateException:File name has been re-used with different files. Spooling assumptions violated for /home/hadoop/flume_test/hello.txt.COMPLETED

跟蹤拋出異常的源碼,SpoolDirectorySource會啟動一個線程輪詢監控目錄下的目標文件,當讀取完該文件(readEvents)之后會對該文件進行重名(rollCurrentFile),當重命名失敗時會拋出IllegalStateException,被SpoolDirectoryRunnable catch重新拋出RuntimeException,導致當前線程退出,從源碼看SpoolDirectoryRunnable是單線程執行的,因此線程結束后,監控目錄下其他文件不再被處理。所以,再新建個 word.txt 文件,flume沒有監聽動作了。如下圖,word.txt沒有被重命名 word.txt.COMPLETED



正確的做法:


不要在flume_test文件夾下直接新建文件,寫內容。在其他文件下新建,寫好內容,mv 到flume_test文件夾下。
[hadoop@nbdo3 ~]$ cd testdata/ [hadoop@nbdo3 testdata]$ ll total 4 -rw-rw-r--. 1 hadoop hadoop 71 Mar 10 20:19 hello.txt [hadoop@nbdo3 testdata]$ cp hello.txt ../flume_test/ [hadoop@nbdo3 testdata]$ echo "123456778" >> world.txt [hadoop@nbdo3 testdata]$ cp world.txt ../flume_test/ [hadoop@nbdo3 testdata]$



-------------

更多的Java,Angular,Android,大數據,J2EE,Python,數據庫,Linux,Java架構師,:

http://www.cnblogs.com/zengmiaogen/p/7083694.html



創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Flume实战监听文件夹内文件变化的全部內容,希望文章能夠幫你解決所遇到的問題。

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