2016-07-12 82 views
-1

在java中使用文件生成器时,我将在本地文件系统中拥有需要在HDFS中移动的目录和文件流。我在互联网搜索,我看到我可以使用Flume,但我没有找到任何资源,向我解释如何做到这一点。你有什么想法如何实现这一点?使用Flume将本地文件系统中的文件复制到HDFS

谢谢

+0

需要更多的细节才能够给你点击。首先,你有几台机器,或者你正在做同一个节点上的所有东西(例如测试)。这些文件的性质是什么:是一次性读取的那些静态文件,还是那些不时创建的日志文件? – Serhiy

+0

现在,我使用相同的节点进行测试。它将是由用户创建的日志文件,并且每次创建之间的时间间隔可能会从几分钟到几小时不等。但现在我正在生成随机文件,以查看HDFS如何响应小文件的流式传输。 – Yassine

回答

0

我从来没有做过它在同一台机器上(如你提到你对此有何评论,对环境),所以你可能需要做一些测试和调整以下配置工作。

就你而言,由于文件将在一个(或多个目录)中动态创建,因此我建议配置Spooling Directory Source(每个目录)和HDFS Sink。在水槽的安装文件夹conf目录下创建一个文件test.conf并把类似的配置:

# Name the components on this agent 
agent.sources = file-source 
agent.sinks = hdfs-sink 
agent.channels = mem-channel 

# Associate channel with source and sink 
agent.sources.file-source.channels = mem-channel 
agent.sinks.hdfs-sink.channel = mem-channel 

# Configure the source 
agent.sources.file-source.type = spooldir 
agent.sources.file-source.spoolDir = /tmp/spool/ 
agent.sources.file-source.fileHeader = true 

# Configure the sink 
agent.sinks.hdfs-sink.type = hdfs 
agent.sinks.hdfs-sink.hdfs.path = /tmp/log.log 
agent.sinks.hdfs-sink.hdfs.fileType = DataStream 
agent.sinks.hdfs-sink.hdfs.path = /flume/test/ 

# Use a channel which buffers events in memory 
agent.channels.mem-channel.type = memory 
agent.channels.mem-channel.capacity = 1000 
agent.channels.mem-channel.transactionCapacity = 100 

运行的代理,在水槽的安装目录下执行以下命令:

bin/flume-ng agent -n agent -c conf -f conf/test.conf 

开始把文件放到/tmp/spool/并检查它们是否出现在HDFS中。

当您要分配系统时,我建议在客户端上使用Avro Sink,在服务器上使用Avro Source,当您将在该服务器上时,您会得到它。

相关问题