需求:将A服务器的日志实时采集到B服务器
技术选型:
exec source + memory channel + avro sink
avro source + memory channel + logger sink
案例架构图:
使用Flume的关键就是写配置文件:
A)配置Source
B)配置Channel
C)配置Sink
D)把以上三个组件串起来
192.168.199.150的exec-memory-avro.conf:
exec-memory-avro.sources = r1
exec-memory-avro.sinks = k1
exec-memory-avro.channels = c1
# 配置source
# Describe/configure the source
exec-memory-avro.sources.r1.type = exec
exec-memory-avro.sources.r1.command = tail -f /home/hadoop/data/data.log
exec-memory-avro.sources.r1.shell = /bin/sh -c
# Describe the sink
# 配置sink
exec-memory-avro.sinks.k1.type = avro
exec-memory-avro.sinks.k1.hostname = 192.168.199.151
exec-memory-avro.sinks.k1.port = 44444
#配置channel
# Use a channel which buffers events in memory
exec-memory-avro.channels.c1.type = memory
exec-memory-avro.channels.c1.capacity = 1000
exec-memory-avro.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
exec-memory-avro.sources.r1.channels = c1
exec-memory-avro.sinks.k1.channel = c1
192.168.199.151的avro-memory-logger.conf:
avro-memory-logger.sources = r1
avro-memory-logger.sinks = k1
avro-memory-logger.channels = c1
# 配置source
# Describe/configure the source
avro-memory-logger.sources.r1.type = avro
avro-memory-logger.sources.r1.bind = 192.168.199.151
avro-memory-logger.sources.r1.port = 44444
# Describe the sink
# 配置sink
avro-memory-logger.sinks.k1.type = logger
#配置channel
# Use a channel which buffers events in memory
avro-memory-logger.channels.c1.type = memory
avro-memory-logger.channels.c1.capacity = 1000
avro-memory-logger.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
avro-memory-logger.sources.r1.channels = c1
avro-memory-logger.sinks.k1.channel = c1
最后,启动Flume:
bin/flume-ng agent --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/exec-memory-avro.conf --name exec-memory-avro -Dflume.root.logger=INFO,console
bin/flume-ng agent --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/avro-memory-logger.conf --name avro-memory-logger -Dflume.root.logger=INFO,console
最后启动成功!
测试如下:
2019-04-08 09:47:56,605 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 68 65 6C 6C 6F hello }
2019-04-08 09:48:05,606 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 77 6F 72 6C 64 world }
END!!!