Flume应用案例三

需求:将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!!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值