Flume
Apache Flume is a distributed, reliable, and available system for efficiently collecting, aggregating and moving large amounts of log data from many different sources to a centralized data store.
Apache Flume是一个分布式的、可靠的、可用的系统,它可以有效地收集、聚合和移动大量的日志数据,这些数据可以从许多不同的来源转移到一个集中的数据存储中。
架构
配置
- 配置Source
- 配置Channel
- 配置Sink
- 把三个组件串起来
a1:agent名称
r1:数据源名称
k1:sink名称
c1:channel名称
netcat:
A netcat-like source that listens on a given port and turns each line of text into an event.
一个类似netcat的源,它监听给定的端口并将每行文本转换成一个事件。
logger:
Logs event at INFO level. Typically useful for testing/debugging purpose.
记录信息级别的事件。通常用于测试/调试。
memory:
The events are stored in an in-memory queue with configurable max size. It’s ideal for flows that need higher throughput and are prepared to lose the staged data in the event of a agent failures.
事件以可配置的最大大小存储在内存队列中。
对于需要更高吞吐量并且准备在代理失败时丢失分段数据的流来说,这是理想的。
# example.conf: A single-node Flume configuration
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = hadoop000
a1.sources.r1.port = 44444
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
一个source可以接多个channel => channels
一个sink只能接一个channel => channel
vi example.conf
将代码粘贴进去
:x
cd $FLUME_HOME/bin
flume-ng agent \
-n a1 \
-c $FLUME_HOME/conf \
-f $FLUME_HOME/conf/example.conf \
-Dflume.root.logger=INFO,console
测试
telnet hadoop000 44444
hello
Flume显示:
2020-03-01 20:52:14,957 (SinkRunner-PollingRunner-DefaultSinkProcessor)
[INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:94)]
Event: { headers:{} body: 68 65 6C 6C 6F 0D hello. }
Event是Flume数据传输的基本单元,Event = 可选的header + byte array