Flume实战三,将A服务器日志实时采集到B服务器中

架构图:
Flume实战三,将A服务器日志实时采集到B服务器中_第1张图片
技术选型:
exec source + memory channel + avro sink
avro source + memory channel + logger sink

1)server A 数据收集端

在cd $FLUME_HOME/conf
vim exec-memory-avro.conf

    #exec-memory-avro.conf内容
    # a1可以看做是flume服务的名称,每个flume都由sources、channels和sinks三部分组成
    # sources可以看做是数据源头、channels是中间转存的渠道、sinks是数据后面的去向
    exec-memory-avro.sources = exec-source
    exec-memory-avro.sinks = avro-sink
    exec-memory-avro.channels = memory-channel
    
    # 配置Source
    exec-memory-avro.sources.exec-source.type = exec
    exec-memory-avro.sources.exec-source.command = tail -F /data/a.txt
    exec-memory-avro.sources.exec-source.shell = /bin/sh -c
    #exec-memory-avro.sources.exec-source.command = for i in /path/*.txt; do cat $i; done
    
    # 配置Channel
    exec-memory-avro.channels.memory-channel.type = memory
    
    # 配置Sinks
    exec-memory-avro.sinks.avro-sink.type = avro
    exec-memory-avro.sinks.avro-sink.hostname = 0.0.0.0
    exec-memory-avro.sinks.avro-sink.port = 44444
    
    # 绑定
    exec-memory-avro.sources.exec-source.channels = memory-channel
    exec-memory-avro.sinks.avro-sink.channel = memory-channel

2)server B 数据存储端

在cd $FLUME_HOME/conf
vim avro-memory-logger.conf

    # avro-memory-logger.conf内容
    # a1可以看做是flume服务的名称,每个flume都由sources、channels和sinks三部分组成
    # sources可以看做是数据源头、channels是中间转存的渠道、sinks是数据后面的去向
    avro-memory-logger.sources = avro-source
    avro-memory-logger.sinks = logger-sink
    avro-memory-logger.channels = avro-memory-logger-channel
    
    # 配置Source
    #由于我们是在本机测试的,所以port设置的是127.0.0.1
    avro-memory-logger.sources.avro-source.type = avro
    avro-memory-logger.sources.avro-source.bind = 127.0.0.1
    avro-memory-logger.sources.avro-source.port = 44444
    
    # 配置Channel
    avro-memory-logger.channels.avro-memory-logger-channel.type = memory
    
    # 配置Sinks
    avro-memory-logger.sinks.logger-sink.type = logger
    
    # 绑定
    avro-memory-logger.sources.avro-source.channels = avro-memory-logger-channel
    avro-memory-logger.sinks.avro-sink.channel = avro-memory-logger-channel

注意:

需要先启动avro-source端

    $FLUME_HOME/bin/flume-ng agent \
    --name avro-memory-logger \
    --conf $FLUME_HOME/conf \
    --conf-file $FLUME_HOME/conf/avro-memory-logger.conf \
    -Dflume.root.logger=INFO,console

再启动exec-source端

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

日志收集过程:
1)机器A上监控一个文件,当我们访问主站时会有用户行为日志记录到access.log中
2)exec source监控数据,监控到数据后通过channel传输到avro sink指定hostname和port
3)由另一个agent的avro source监控hostname和port,数据后通过channel传递给控制台输出

你可能感兴趣的:(Flume)