本文已参与「新人创作礼」活动,一起开启掘金创作之路。
Configuration
1. 定义流程
要在一个agent中定义流程,需要通过一个channel将source和sink连接起来,需要给一个agent列出sources,sink和channels,然后将source和sink指向一个channel。一个source实例可以指定多个通道,但一个接收器实例只能指定一个通道。 格式如下:
# list the sources, sinks and channels for the agent
<Agent>.sources = <Source>
<Agent>.sinks = <Sink>
<Agent>.channels = <Channel1> <Channel2>
# set channel for source
<Agent>.sources.<Source>.channels = <Channel1> <Channel2> ...
# set channel for sink
<Agent>.sinks.<Sink>.channel = <Channel1>
2. 配置单个组件
需要为Flume的每个组件设置属性“type”来理解它需要的对象类型。每个source,sink和channel类型都有其自己的一组属性,以使其按预期运行。所有这些都需要根据需要设置。
agent_foo.sources = avro-AppSrv-source
agent_foo.sinks = hdfs-Cluster1-sink
agent_foo.channels = mem-channel-1
# set channel for sources, sinks
# properties of avro-AppSrv-source
agent_foo.sources.avro-AppSrv-source.type = avro
agent_foo.sources.avro-AppSrv-source.bind = localhost
agent_foo.sources.avro-AppSrv-source.port = 10000
# properties of mem-channel-1
agent_foo.channels.mem-channel-1.type = memory
agent_foo.channels.mem-channel-1.capacity = 1000
agent_foo.channels.mem-channel-1.transactionCapacity = 100
# properties of hdfs-Cluster1-sinka
gent_foo.sinks.hdfs-Cluster1-sink.type = hdfs
agent_foo.sinks.hdfs-Cluster1-sink.hdfs.path = hdfs://namenode/flume/webdata\
#...
3. 在一个agent中添加多个流
一个Flume代理可以包含多个独立的flows。 可以在配置中列出多个source,sink和channel。然后,可以将sources和sinks链接到相应的channels以设置两个不同的流。例如,如果需要在agent中设置两个流程,一个从外部avro客户端到外部HDFS,另一个从尾部输出到avro接收器,则可以使用以下配置:
# list the sources, sinks and channels in the agent
agent_foo.sources = avro-AppSrv-source1 exec-tail-source2
agent_foo.sinks = hdfs-Cluster1-sink1 avro-forward-sink2
agent_foo.channels = mem-channel-1 file-channel-2
# flow #1 configuration
agent_foo.sources.avro-AppSrv-source1.channels = mem-channel-1
agent_foo.sinks.hdfs-Cluster1-sink1.channel = mem-channel-1
# flow #2 configuration
agent_foo.sources.exec-tail-source2.channels = file-channel-2
agent_foo.sinks.avro-forward-sink2.channel = file-channel-2
4. 配置多个agent flow
要设置一个多层流,需要一个avro/thrift sink第一跳指向avro/thrift source为下一跳。这将导致第一个Flume agent将事件转发到下一个Flume agent。例如,如果定期使用avro客户端向本地Flume agent发送文件(每个事件一个文件),那么这个本地agent可以将其转发给另一个已安装存储的agent。
Weblog代理配置:
# list sources, sinks and channels in the agent
agent_foo.sources = avro-AppSrv-source
agent_foo.sinks = avro-forward-sinka
gent_foo.channels = file-channel
# define the flowa
gent_foo.sources.avro-AppSrv-source.channels = file-channel
agent_foo.sinks.avro-forward-sink.channel = file-channel
# avro sink properties
agent_foo.sinks.avro-forward-sink.type = avro
agent_foo.sinks.avro-forward-sink.hostname = 10.1.1.100
agent_foo.sinks.avro-forward-sink.port = 10000
# configure other pieces#...
HDFS代理配置:
# list sources, sinks and channels in the agent
agent_foo.sources = avro-collection-source
agent_foo.sinks = hdfs-sink
agent_foo.channels = mem-channel
# define the flow
agent_foo.sources.avro-collection-source.channels = mem-channel
agent_foo.sinks.hdfs-sink.channel = mem-channel
# avro source properties
agent_foo.sources.avro-collection-source.type = avro
agent_foo.sources.avro-collection-source.bind = 10.1.1.100
agent_foo.sources.avro-collection-source.port = 10000
# configure other pieces
#...
在这里,我们将weblog代理的avro-forward-sink链接到hdfs代理的avro-collection-source。 这将导致来自外部应用服务器源的事件最终被存储在HDFS中。
5. Fan out flow
Flume支持从一个source流向多个信道。删除有复制和复用两种模式。在复制流程中,事件被发送到所有配置的通道。在多路复用的情况下,事件只被发送到合格channel的一个子集。为了扇区流出,需要为指定源指定一个channels列表和一个faning it out策略。这是通过添加可以复制或复用的通道“selector(筛选器)”来完成的。然后进一步指定选择规则,如果它是一个多路复用器。如果您不指定选择器,则默认情况下它是复制:
# List the sources, sinks and channels for the agent
<Agent>.sources = <Source1>
<Agent>.sinks = <Sink1> <Sink2>
<Agent>.channels = <Channel1> <Channel2>
# set list of channels for source (separated by space)
<Agent>.sources.<Source1>.channels = <Channel1> <Channel2>
# set channel for sinks\
<Agent>.sinks.<Sink1>.channel = <Channel1>
<Agent>.sinks.<Sink2>.channel = <Channel2>
<Agent>.sources.<Source1>.selector.type = replicating
多路复用选择还有一组属性来分流。 这要求指定一个事件属性到一个通道集的映射。选择器检查事件头中的每个配置的属性。 如果它匹配指定的值,则该事件被发送到映射到该值的所有通道。如果没有匹配,则将事件发送到配置为默认值的一组通道:
# Mapping for multiplexing selector
<Agent>.sources.<Source1>.selector.type = multiplexing
<Agent>.sources.<Source1>.selector.header = <someHeader>
<Agent>.sources.<Source1>.selector.mapping.<Value1> = <Channel1>
<Agent>.sources.<Source1>.selector.mapping.<Value2> = <Channel1> <Channel2>
<Agent>.sources.<Source1>.selector.mapping.<Value3> = <Channel2>
#...
<Agent>.sources.<Source1>.selector.default = <Channel2>
映射允许重叠每个值的通道。以下示例具有复用到两个路径的单个流。 名为agent_foo的代理具有一个avro源和两个链接到两个接收器的通道:
# list the sources, sinks and channels in the agent
agent_foo.sources = avro-AppSrv-source1
agent_foo.sinks = hdfs-Cluster1-sink1 avro-forward-sink2
agent_foo.channels = mem-channel-1 file-channel-2
# set channels for source
agent_foo.sources.avro-AppSrv-source1.channels = mem-channel-1 file-channel-2
# set channel for sinks
agent_foo.sinks.hdfs-Cluster1-sink1.channel = mem-channel-1
agent_foo.sinks.avro-forward-sink2.channel = file-channel-2
# channel selector configuration
agent_foo.sources.avro-AppSrv-source1.selector.type = multiplexing
agent_foo.sources.avro-AppSrv-source1.selector.header = State
agent_foo.sources.avro-AppSrv-source1.selector.mapping.CA = mem-channel-1
agent_foo.sources.avro-AppSrv-source1.selector.mapping.AZ = file-channel-2
agent_foo.sources.avro-AppSrv-source1.selector.mapping.NY = mem-channel-1 file-channel-2
agent_foo.sources.avro-AppSrv-source1.selector.default = mem-channel-1
上面是选择器检查名为“State”的标题。 如果值是“CA”,那么它发送到mem-channel-1,如果它的“AZ”则转到文件通道-2或者如果它的“NY”那么两者。 如果“状态”标题没有设置或不匹配任何三个,那么它将转到被指定为“默认”的mem-channel-1。
#选择器还支持可选通道。 要为标题指定可选通道,配置参数“optional”用于以下方式:
# channel selector configuration
agent_foo.sources.avro-AppSrv-source1.selector.type = multiplexing
agent_foo.sources.avro-AppSrv-source1.selector.header = State
agent_foo.sources.avro-AppSrv-source1.selector.mapping.CA = mem-channel-1
agent_foo.sources.avro-AppSrv-source1.selector.mapping.AZ = file-channel-2
agent_foo.sources.avro-AppSrv-source1.selector.mapping.NY = mem-channel-1 file-channel-2
agent_foo.sources.avro-AppSrv-source1.selector.optional.CA = mem-channel-1 file-channel-2
agent_foo.sources.avro-AppSrv-source1.selector.mapping.AZ = file-channel-2
agent_foo.sources.avro-AppSrv-source1.selector.default = mem-channel-1
选择器将首先尝试写入所需的通道,并且==如果这些通道中的一个通道不能传输事件,则传输将失败==。传输重新再所有通道上进行。一旦所有必需的频道都没有消费了这些event,==那么选择器将尝试写入可选的通道==。任何可选渠道去消费这些event发生==故障简单地被忽略,而不是重试==。
如果可选通道和特定报头所需通道之间存在重叠,则认为该通道是必需的,而通道故障将导致重试整组所需的通道。
请注意,如果标题没有任何所需的频道,则该事件将被写入默认频道,并将尝试写入该标题的可选频道。 如果没有指定所需的通道,则指定可选通道仍然会将事件写入默认通道。 如果没有频道被指定为默认频道,并且没有要求,则选择器将尝试将事件写入到可选频道。 在这种情况下,任何失败都会被忽略。