使用Flume将文件从我的本地文件系统复制到HDFS

时间:2016-07-12 15:57:39

标签: hadoop hdfs flume flume-ng

在java中使用文件生成器,我将在本地文件系统中有一个目录和文件流,我需要在HDFS中移动。我在网上搜索,我看到我可以使用Flume,但是我没有找到任何资源向我解释如何做到这一点。你知道如何实现这个吗?

谢谢

1 个答案:

答案 0 :(得分:1)

我从来没有在同一台机器上完成它(正如你在评论中提到的那样,关于环境),所以你可能需要做一些测试和调整才能使用以下配置。

在您的情况下,由于文件将在一个(或多个目录)中动态创建,我建议配置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,当您在那里时,您将获得它。

相关问题