使用Java中的文件生成器,我将在本地文件系统中拥有目录流和文件流,需要在HDFS中移动它们。我在互联网上搜索,发现可以使用Flume,但是没有找到任何资源向我说明如何做。你有什么想法要实现吗?
谢谢
最佳答案
我从来没有在同一台机器上做过(正如您在评论中提到的有关环境),因此您可能需要做一些测试和调整才能使以下配置生效。
在您的情况下,由于将在一个(或多个目录)中动态创建文件,因此建议您配置Spooling Directory Source(每个目录)和HDFS Sink。在Flume安装文件夹的test.conf
目录中创建一个文件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
要运行代理,请在Flume安装目录中执行以下命令:
bin/flume-ng agent -n agent -c conf -f conf/test.conf
开始将文件放入
/tmp/spool/
中,并检查它们是否出现在HDFS中。当您要分发系统时,我建议在客户端上使用Avro Sink并在服务器上使用Avro Source,当您在那里时就可以得到它。
关于hadoop - 使用Flume将文件从本地文件系统复制到HDFS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38333812/