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