设为首页 收藏本站
查看: 1440|回复: 0

[经验分享] Flume NG 学习笔记(六)Selector(复用与复制)测试

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-11-27 18:10:36 | 显示全部楼层 |阅读模式
  学习心得(三)流配置中介绍多路复用流的时候,有说到Flume支持从一个源发送事件到多个通道中,这被称为事件流的复用。这里需要在配置中定义事件流的复制/复用,选择1个或者多个通道进行数据流向。
  而关于selector配置前面也讲过:

<Agent>.sources.<Source1>.selector.type= replicating

  这个源的选择类型为复制。这个参数不指定一个选择的时候,默认情况下它复制
  复用则是麻烦一下,流的事情是被筛选的发生到不同的渠道,需要指定源和扇出通道的规则,感觉与case when 类&#20284;。
  复用的参数为:

<Agent>.sources.<Source1>.selector.type= multiplexing

  

一、下面给出复制的测试例子:
  
  这里需要配置1个代理作为源发送与2个代理作为接受复制事件,共3个flume配置
  首先是作为源发送的代理配置
  

#配置文件:replicate_source_case11.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1 k2
a1.channels = c1 c2
# Describe/configure the source
a1.sources.r1.type = syslogtcp
a1.sources.r1.port = 50000
a1.sources.r1.host = 192.168.233.128
a1.sources.r1.selector.type = replicating
a1.sources.r1.channels = c1 c2
# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.channel = c1
a1.sinks.k1.hostname = 192.168.233.129
a1.sinks.k1.port = 50000
a1.sinks.k2.type = avro
a1.sinks.k2.channel = c2
a1.sinks.k2.hostname = 192.168.233.130
a1.sinks.k2.port = 50000
# Use a channel which buffers events inmemory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
a1.channels.c2.type = memory
a1.channels.c2.capacity = 1000
a1.channels.c2.transactionCapacity = 100


  
  这里设置了2个channels与2个sinks,那么我们也要设置2个sinks对应的代理配置:
  下面是第一个接受复制事件代理配置
  #配置文件:replicate_sink1_case11.conf
# Name the components on this agent
a2.sources = r1
a2.sinks = k1
a2.channels = c1
# Describe/configure the source
a2.sources.r1.type = avro
a2.sources.r1.channels = c1
a2.sources.r1.bind = 192.168.233.129
a2.sources.r1.port = 50000
# Describe the sink
a2.sinks.k1.type = logger
a2.sinks.k1.channel = c1
# Use a channel which buffers events inmemory
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100




  
  下面是第二个接受复制事件代理配置:
  #配置文件:replicate_sink2_case11.conf
# Name the components on this agent
a3.sources = r1
a3.sinks = k1
a3.channels = c1
# Describe/configure the source
a3.sources.r1.type = avro
a3.sources.r1.channels = c1
a3.sources.r1.bind = 192.168.233.130
a3.sources.r1.port = 50000
# Describe the sink
a3.sinks.k1.type = logger
a3.sinks.k1.channel = c1
# Use a channel which buffers events inmemory
a3.channels.c1.type = memory
a3.channels.c1.capacity = 1000
a3.channels.c1.transactionCapacity = 100


  #敲命令
  首先先启动2个接受复制事件代理,如果先启动源发送的代理,会报他找不到sinks的绑定,因为2个接事件的代理还未起来。
  flume-ng agent -cconf -f conf/replicate_sink1_case11.conf -n a1 -Dflume.root.logger=INFO,console
  flume-ng agent -cconf -f conf/replicate_sink2_case11.conf -n a1 -Dflume.root.logger=INFO,console
  在启动源发送的代理
  flume-ng agent -cconf -f conf/replicate_source_case11.conf -n a1 -Dflume.root.logger=INFO,console
  
  启动成功后
  
  打开另一个终端输入,往侦听端口送数据
  echo &quot;hello looklook5&quot;| nc 192.168.233.128 50000
  #在启动源发送的代理终端查看console输出
   DSC0000.jpg


  
  可以看到他的正常启动以及发送数据成功
  #在启动源第一个接事件的代理终端查看console输出

DSC0001.jpg
  
  可以看到他的正常启动,以及接受到源代理发送的数据
  #在启动源第二个接事件的代理终端查看console输出

DSC0002.jpg
  
  同样可以可以看到他的正常启动,以及接受到源代理发送的数据
  Ok,成功
  
  

二、下面给出复用的测试例子:
  
  因为复用的流的事件要声明一个头部,然后我们检查头部对应的&#20540;,因为我们这边源类用http source
  下面是源代理的配置
  #配置文件:multi_source_case12.conf
a1.sources= r1
a1.sinks= k1 k2
a1.channels= c1 c2
#Describe/configure the source
a1.sources.r1.type= org.apache.flume.source.http.HTTPSource
a1.sources.r1.port= 50000
a1.sources.r1.host= 192.168.233.128
a1.sources.r1.selector.type= multiplexing
a1.sources.r1.channels= c1 c2
a1.sources.r1.selector.header= state
a1.sources.r1.selector.mapping.CZ= c1
a1.sources.r1.selector.mapping.US= c2
a1.sources.r1.selector.default= c1
#Describe the sink
a1.sinks.k1.type= avro
a1.sinks.k1.channel= c1
a1.sinks.k1.hostname= 192.168.233.129
a1.sinks.k1.port= 50000
a1.sinks.k2.type= avro
a1.sinks.k2.channel= c2
a1.sinks.k2.hostname= 192.168.233.130
a1.sinks.k2.port= 50000
# Usea channel which buffers events in memory
a1.channels.c1.type= memory
a1.channels.c1.capacity= 1000
a1.channels.c1.transactionCapacity= 100
a1.channels.c2.type= memory
a1.channels.c2.capacity= 1000
a1.channels.c2.transactionCapacity= 100


  这里设置了2个channels与2个sinks 同时判断头部属性,当CZ的时,事件发送到sinks1,US时发送到sink2,其他的都发送到sink2,因此我们还有配置2个sinks对于的代理。这里的2个接受代理我们沿用之前复制的接受代理。
  
  #敲命令
  与之前复制的情况一样,首先先启动2个接受复制事件代理,如果先启动源发送的代理,会报他找不到sinks的绑定,因为2个接事件的代理还未起来。
  flume-ng agent -cconf -f conf/multi_sink1_case12.conf -n a1 -Dflume.root.logger=INFO,console
  flume-ng agent -cconf -f conf/multi_sink2_case12.conf -n a1 -Dflume.root.logger=INFO,console
  在启动源发送的代理
  flume-ng agent -cconf -f conf/multi_source_case12.conf -n a1 -Dflume.root.logger=INFO,console
  启动成功后
  打开另一个终端输入,往侦听端口送数据
  curl -X POST -d '[{&quot;headers&quot; :{&quot;state&quot; : &quot;CZ&quot;},&quot;body&quot; :&quot;TEST1&quot;}]' http://192.168.233.128:50000
  curl -X POST -d '[{&quot;headers&quot; :{&quot;state&quot; : &quot;US&quot;},&quot;body&quot; :&quot;TEST2&quot;}]' http://192.168.233.128:50000
  curl -X POST -d '[{&quot;headers&quot; :{&quot;state&quot; : &quot;SH&quot;},&quot;body&quot; :&quot;TEST3&quot;}]' http://192.168.233.128:50000
  #在启动源发送的代理终端查看console输出

DSC0003.jpg
  
  可以看到他的正常启动以及发送数据成功
  #在启动源第一个接事件的代理终端查看console输出

DSC0004.jpg
  
  这里可以清楚的看到,这个接事件代理只收到了2个事件,因为第二个事件因为我们设置复用,将头部信息对于的事件分流的关系,发送到另一个接事件代理去了。

#在启动源第二个接事件的代理终端查看console输出
   DSC0005.jpg


  
  Ok,第二个接事件代理因为复用分流,果然只获得了第二个事件信息。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-144305-1-1.html 上篇帖子: 1.flume简介 下篇帖子: Flume-ng出现HDFS IO error,Callable timed out异常
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表