Flume跨服务器采集数据

在大数据的采集中,我们常用Flume来进行数据的采集,一般的我们会从Web Server服务器中收集数据,将数据存储在另一台服务器的hdfs文件系统做离线分析或者sink到另一台服务器的kafka消息队列中做实时流式计算。

对于实时流处理流程如下:

这里写图片描述

无论是离线数据分析还是实时流数据分析在生产环境中都不可能在同一台机器中完成,因此我们常常会跨服务器进行数据的采集,下面我们使用两台不同服务器的flume串联实现跨服务器数据的采集,原理如下:
这里写图片描述

收集流程如下:

在机器A上使用exec source,当我们向机器A中的一个文件中写入数据的时候,机器A上的avro sink将新产生的数据输出到对应avro source的机器B上去,最后通过机器B的Agent的logger sink将日志输出到控制台上。

这里为了模拟真实环境我准备了两台机器,当然你也可以在同一台机器上进行,只需配置两个配置文件即可。配置如下:

机器A的配置,exec-memory-avro.conf:

# The configuration file needs to define the sources, 
# the channels and the sinks.
# Sources, channels and sinks are defined per agent, 
# in this case called 'agent'
f1.sources = r1
f1.channels = c1
f1.sinks = k1

#define sources
f1.sources.r1.type = exec
f1.sources.r1.command =tail -f /opt/datas/flume.log

#define channels
f1.channels.c1.type = memory
f1.channels.c1.capacity = 1000
f1.channels.c1.transactionCapacity = 100

#define sink
f1.sinks.k1.type = avro
f1.sinks.k1.hostname = hadoop-senior02.shinelon.com
f1.sinks.k1.port =44444

#bind sources and sink to channel 
f1.sources.r1.channels = c1
f1.sinks.k1.channel = c1

机器B上的配置,avro-memory-logger.conf:

# The configuration file needs to define the sources, 
# the channels and the sinks.
# Sources, channels and sinks are defined per agent, 
# in this case called 'agent'
f2.sources = r2
f2.channels = c2
f2.sinks = k2

#define sources
f2.sources.r2.type = avro
f2.sources.r2.bind = hadoop-senior02.shinelon.com
f2.sources.r2.port = 44444

#define channels
f2.channels.c2.type = memory
f2.channels.c2.capacity = 1000
f2.channels.c2.transactionCapacity = 100

#define sink
f2.sinks.k2.type = logger

#bind sources and sink to channel 
f2.sources.r2.channels = c2
f2.sinks.k2.channel = c2

下面启动两台服务器上的flume,应该首先先启动机器B上的Flume:

bin/flume-ng agent \
--conf conf \
--name f2 \
--conf-file conf/avro-memory-logger.conf \
-Dflume.root.logger=DEBUG,console

接着启动机器A上的Flume:

bin/flume-ng agent \
--conf conf \
--name f1 \
--conf-file conf/exec-memory-avro.conf \
-Dflume.root.logger=DEBUG,console

结果如下图所示:
这里写图片描述

这里写图片描述

可以看见我们在机器A的日志文件中追加的数据在机器B的控制台中打印出来,也就是说我们完成了Flume跨服务器的数据采集,当然,这里只是为了模拟,在实际生产环境中就要收集到HDFS文件系统做离线分析或者kafka中实时流数据分析。

猜你喜欢

转载自blog.csdn.net/qq_37142346/article/details/81128521