使用Docker容器模拟分布式flume

使用Docker模拟分布式flume,agent1通过avro接口连接agent2和agent3,agent2和agent3采用负荷分担方式。

使用docker-hub上的cogniteev/flume作为原始镜像:

docker pull cogniteev/flume
镜像中确实一些必要组件,请自行安装,如log4j

启动agent2和agent3并命名为flume_center_master和flume_center_slave,配置端口44444和45454分别映射虚拟机上,用作avro监听和状态监控,命令如下:

docker run -i -t –name flume_center_master -p 24444:44444 -p 25454:45454 cogniteev/flume /bin/bash
docker run -i -t –name flume_center_slave -p 34444:44444 -p 35454:45454 cogniteev/flume /bin/bash

agent2的flume配置如下,路径:var/flume/conf/collect1.conf:

//Name the compents 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 = 0.0.0.0
a2.sources.r1.port = 44444

//Describe the sink
a2.sinks.k1.type = logger
a2.sinks.k1.channel = c1

//Use a channel which buffers events in memory
a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100

注:由于是在docker中运行,a2.sources.r1.bind = 0.0.0.0是必须这样的,否则在容器之外无法访问

agent3的flume配置与agent2类似,仅将agent命名改为a3,文件名改为collect2

启动flume-ng:

bin/flume-ng agent –conf conf –conf-file conf/collect1.conf –name a2 -Dflume.root.logger=INFO,console -Dflume.monitoring.type=http -Dflume.monitoring.port=45454
bin/flume-ng agent –conf conf –conf-file conf/collect2.conf –name a3 -Dflume.root.logger=INFO,console -Dflume.monitoring.type=http -Dflume.monitoring.port=45454

启动agent1并命名为flume_1_1,配置端口44444和45454分别映射虚拟机上,用作http监听和状态监控,命令如下:
docker run -i -t –name flume_1_1 -p 44444:44444 -p 45454:45454 cogniteev/flume /bin/bash

1.agent1配置:

//Name the components on this agent
a1.sources = r1
a1.sinks = k1 k2
a1.channels = c1

//Describe the sinkgroups
a1.sinkgroups = g1
a1.sinkgroups.g1.sinks = k1 k2
a1.sinkgroups.g1.processor.type = load_balance
a1.sinkgroups.g1.processor.backoff = true
a1.sinkgroups.g1.processer.selector = round_robin

//Describe/configure the source
a1.sources = r1
a1.channels = c1
a1.sources.r1.type = http
a1.sources.r1.port = 44444
a1.sources.r1.channels = c1
a1.sources.r1.handler = org.apache.flume.source.http.JSONHandler
a1.sources.r1.handler.nickname = post test

//Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = 192.168.99.100
a1.sinks.k1.port = 24444
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = 192.168.99.100
a1.sinks.k2.port = 344444

//Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

//Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c1

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐