使用flume将文件从本地文件系统复制到hdfs

3hvapo4f  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(411)

使用java中的文件生成器,我将在本地文件系统中有一个目录和文件流,需要在hdfs中移动。我在互联网上搜索,我看到我可以使用flume,但我没有找到任何资源来解释如何做到这一点。你知道怎么实施吗?
谢谢您

68de4m5k

68de4m5k1#

我从来没有在同一台机器上做过(正如您在评论中提到的,关于环境),所以您可能需要做一些测试和调整,以使以下配置正常工作。
在您的例子中,由于文件将在一个(或多个)目录中动态创建,因此我建议配置假脱机目录源(每个目录)和hdfs接收器。创建一个文件 test.confconf 目录并放置类似的配置:


# 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,您将在那里得到它。

相关问题