hadoop - Flume HDFS sink 使用 netcat source 只存储一行数据源

标签 hadoop flume flume-ng

我尝试使用 Flume 1.7 将数据加载到 HDFS 中。我创建了以下配置:

# Starting with: /opt/flume/bin/flume-ng agent -n Agent -c conf -f /opt/flume/conf/test.conf
# Naming the components on the current agent
Agent.sources = Netcat   
Agent.channels = MemChannel 
Agent.sinks = LoggerSink hdfs-sink LocalOut

# Describing/Configuring the source 
Agent.sources.Netcat.type = netcat 
Agent.sources.Netcat.bind = 0.0.0.0
Agent.sources.Netcat.port = 56565  

# Describing/Configuring the sink 
Agent.sinks.LoggerSink.type = logger  

# Define a sink that outputs to hdfs.
Agent.sinks.hdfs-sink.type = hdfs
Agent.sinks.hdfs-sink.hdfs.path = hdfs://<<IP of HDFS node>>:8020/user/admin/flume_folder/%y-%m-%d/%H%M/
Agent.sinks.hdfs-sink.hdfs.useLocalTimeStamp = true
Agent.sinks.hdfs-sink.hdfs.fileType = DataStream
Agent.sinks.hdfs-sink.hdfs.writeFormat = Text
Agent.sinks.hdfs-sink.hdfs.batchSize = 100
Agent.sinks.hdfs-sink.hdfs.rollSize = 0
Agent.sinks.hdfs-sink.hdfs.rollCount = 0
Agent.sinks.hdfs-sink.hdfs.rollInterval = 0
Agent.sinks.hdfs-sink.hdfs.idleTimeout = 0

# Schreibt input into local Filesystem
#http://flume.apache.org/FlumeUserGuide.html#file-roll-sink
Agent.sinks.LocalOut.type = file_roll  
Agent.sinks.LocalOut.sink.directory = /tmp/flume
Agent.sinks.LocalOut.sink.rollInterval = 0  


# Describing/Configuring the channel 
Agent.channels.MemChannel.type = memory 
Agent.channels.MemChannel.capacity = 1000 
Agent.channels.MemChannel.transactionCapacity = 100 

# Bind the source and sink to the channel 
Agent.sources.Netcat.channels = MemChannel
Agent.sinks.LoggerSink.channel = MemChannel
Agent.sinks.hdfs-sink.channel = MemChannel
Agent.sinks.LocalOut.channel = MemChannel

之后,我使用 netcat 将以下文件发送到源:
cat textfile.csv | nc <IP of flume agent> 56565

该文件包含以下元素:
Name1,1
Name2,2
Name3,3
Name4,4
Name5,5
Name6,6
Name7,7
Name8,8
Name9,9
Name10,10
Name11,11
Name12,12
Name13,13
Name14,14
Name15,15
Name16,16
Name17,17
Name18,18
Name19,19
Name20,20
...
Name490,490
Name491,491
Name492,492

我面临的问题是,flume 正在写入 hdfs 但只有一行传输的文件没有任何错误。
如果您开始使用 nectat 多次将文件推送到源,那么有时水槽会向 hdfs 写入多个文件,包括不止一行。但很少是所有行。

我试图更改 rollSize、batch size 等的 hdfs 参数,但它并没有真正改变行为。

也配置的本地文件接收器工作得很好。

有人知道如何配置它以确保所有条目都写入 hdfs 而不会丢失条目。

谢谢你的帮助。

2016 年 12 月 1 日更新

我删除了除了HDFS的sink之外的所有sink,并更改了一些参数。在此之后,HDFS 接收器按应有的方式执行。

这里的配置:
# Naming the components on the current agent
Agent.sources = Netcat   
Agent.channels = MemChannel 
Agent.sinks = hdfs-sink 

# Describing/Configuring the source 
Agent.sources.Netcat.type = netcat 
Agent.sources.Netcat.bind = 0.0.0.0
Agent.sources.Netcat.port = 56565  


# Define a sink that outputs to hdfs.
Agent.sinks.hdfs-sink.type = hdfs
Agent.sinks.hdfs-sink.hdfs.path = hdfs://<<IP of HDFS node>>/user/admin/flume_folder/%y-%m-%d/%H%M/
Agent.sinks.hdfs-sink.hdfs.useLocalTimeStamp = true
Agent.sinks.hdfs-sink.hdfs.fileType = DataStream
Agent.sinks.hdfs-sink.hdfs.writeFormat = Text
Agent.sinks.hdfs-sink.hdfs.batchSize = 100
Agent.sinks.hdfs-sink.hdfs.rollSize = 0
Agent.sinks.hdfs-sink.hdfs.rollCount = 100


# Describing/Configuring the channel 
Agent.channels.MemChannel.type = memory 
Agent.channels.MemChannel.capacity = 1000 
Agent.channels.MemChannel.transactionCapacity = 100 

# Bind the source and sink to the channel 
Agent.sources.Netcat.channels = MemChannel
Agent.sinks.hdfs-sink.channel = MemChannel

有人知道为什么它使用这种配置但有两个或更多接收器它不再工作了吗?

最佳答案

我自己找到了解决方案。据我了解,我对两个接收器使用了相同的 channel 。因此,更快的接收器接管了所有条目,并且只有一些条目被传递到 hdfs 接收器。

在使用不同的 channel 并包括对带有参数的源进行扇形处理之后

Agent.sources.Netcat.selector.type = replicating

Flume 按预期写入本地文件和 hdfs。

关于hadoop - Flume HDFS sink 使用 netcat source 只存储一行数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40831406/

相关文章:

hadoop - Flume 代理 : add host to message, 然后发布到 kafka 主题

hadoop - Flume 内存 channel 在启动时已满

Node.js 到 Flume-NG

hadoop - 在 Hadoop(单节点集群)上运行排序示例?

indexing - HBase 是如何管理其索引的?

hadoop - 空值从 csv 文件上传到配置单元表

hadoop 警告 EBADF : Bad file descriptor

hadoop - 在Apache Flume中标记匹配关键字

hadoop - 找不到我的数据写在HDFS与水槽

apache - exec flume-ng之后,Apache Flume卡住了