• (二十一)大数据实战——Flume数据采集之复制和多路复用案例实战


    前言

    本节内容我们完成Flume数据采集的一个多路复用案例,使用三台服务器,一台服务器负责采集本地日志数据,通过使用Replicating ChannelSelector选择器,将采集到的数据分发到另外俩台服务器,一台服务器将数据存储到hdfs,另外一台服务器将数据存储在本机,使用Avro的方式完成flume之间采集数据的传输。整体架构如下:

    正文

    ①在hadoop101服务器的/opt/module/apache-flume-1.9.0/job目录下创建job-file-flume-avro.conf配置文件,用于监控hive日志并传输到avro sink

    - job-file-flume-avro.conf配置文件

    1. # Name the components on this agent
    2. a1.sources = r1
    3. a1.sinks = k1 k2
    4. a1.channels = c1 c2
    5. # 将数据流复制给所有 channel
    6. a1.sources.r1.selector.type = replicating
    7. # Describe/configure the source
    8. a1.sources.r1.type = exec
    9. a1.sources.r1.command = tail -F /tmp/hadoop/hive.log
    10. a1.sources.r1.shell = /bin/bash -c
    11. # Describe the sink
    12. # sink 端的 avro 是一个数据发送者
    13. a1.sinks.k1.type = avro
    14. a1.sinks.k1.hostname = hadoop102
    15. a1.sinks.k1.port = 4141
    16. a1.sinks.k2.type = avro
    17. a1.sinks.k2.hostname = hadoop103
    18. a1.sinks.k2.port = 4142
    19. # Describe the channel
    20. a1.channels.c1.type = memory
    21. a1.channels.c1.capacity = 1000
    22. a1.channels.c1.transactionCapacity = 100
    23. a1.channels.c2.type = memory
    24. a1.channels.c2.capacity = 1000
    25. a1.channels.c2.transactionCapacity = 100
    26. # Bind the source and sink to the channel
    27. a1.sources.r1.channels = c1 c2
    28. a1.sinks.k1.channel = c1
    29. a1.sinks.k2.channel = c2

    ②在hadoop102服务器的/opt/module/apache-flume-1.9.0/job目录下创建job-avro-flume-hdfs.conf配置文件,将监控数据传输到hadoop的hdfs系统

    - job-avro-flume-hdfs.conf配置文件

    1. # Name the components on this agent
    2. a2.sources = r1
    3. a2.sinks = k1
    4. a2.channels = c1
    5. # Describe/configure the source
    6. # source 端的 avro 是一个数据接收服务
    7. a2.sources.r1.type = avro
    8. a2.sources.r1.bind = hadoop102
    9. a2.sources.r1.port = 4141
    10. # Describe the sink
    11. a2.sinks.k1.type = hdfs
    12. a2.sinks.k1.hdfs.path = hdfs://hadoop101:8020/flume2/%Y%m%d/%H
    13. #上传文件的前缀
    14. a2.sinks.k1.hdfs.filePrefix = flume2-
    15. #是否按照时间滚动文件夹
    16. a2.sinks.k1.hdfs.round = true
    17. #多少时间单位创建一个新的文件夹
    18. a2.sinks.k1.hdfs.roundValue = 1
    19. #重新定义时间单位
    20. a2.sinks.k1.hdfs.roundUnit = hour
    21. #是否使用本地时间戳
    22. a2.sinks.k1.hdfs.useLocalTimeStamp = true
    23. #积攒多少个 Event 才 flush 到 HDFS 一次
    24. a2.sinks.k1.hdfs.batchSize = 100
    25. #设置文件类型,可支持压缩
    26. a2.sinks.k1.hdfs.fileType = DataStream
    27. #多久生成一个新的文件
    28. a2.sinks.k1.hdfs.rollInterval = 30
    29. #设置每个文件的滚动大小大概是 128M
    30. a2.sinks.k1.hdfs.rollSize = 134217700
    31. #文件的滚动与 Event 数量无关
    32. a2.sinks.k1.hdfs.rollCount = 0
    33. # Describe the channel
    34. a2.channels.c1.type = memory
    35. a2.channels.c1.capacity = 1000
    36. a2.channels.c1.transactionCapacity = 100
    37. # Bind the source and sink to the channel
    38. a2.sources.r1.channels = c1
    39. a2.sinks.k1.channel = c1

    ③在hadoop103服务器的/opt/module/apache-flume-1.9.0/job目录下创建job-avro-flume-dir.conf配置文件,将监控数据传输到/opt/module/apache-flume-1.9.0/flume3目录下

    - job-avro-flume-dir.conf配置文件

    1. # Name the components on this agent
    2. a3.sources = r1
    3. a3.sinks = k1
    4. a3.channels = c2
    5. # Describe/configure the source
    6. a3.sources.r1.type = avro
    7. a3.sources.r1.bind = hadoop103
    8. a3.sources.r1.port = 4142
    9. # Describe the sink
    10. a3.sinks.k1.type = file_roll
    11. a3.sinks.k1.sink.directory = /opt/module/apache-flume-1.9.0/flume3
    12. # Describe the channel
    13. a3.channels.c2.type = memory
    14. a3.channels.c2.capacity = 1000
    15. a3.channels.c2.transactionCapacity = 100
    16. # Bind the source and sink to the channel
    17. a3.sources.r1.channels = c2
    18. a3.sinks.k1.channel = c2

    - 创建数据存储目录/opt/module/apache-flume-1.9.0/flume3

    ④启动hadoop集群

     

    ⑤启动hadoop102上的flume任务job-avro-flume-hdfs.conf

    - 命令:

    bin/flume-ng agent -c conf/ -n a2 -f job/job-avro-flume-hdfs.conf -Dflume.root.logger=INFO,console

     ⑥启动hadoop103上的flume任务job-avro-flume-dir.conf

    - 命令:

    bin/flume-ng agent -c conf/ -n a3 -f job/job-avro-flume-dir.conf -Dflume.root.logger=INFO,console

    ⑦启动hadoop101上的flume任务job-file-flume-avro.conf

    - 命令:

    bin/flume-ng agent -c conf/ -n a1 -f job/job-file-flume-avro.conf -Dflume.root.logger=INFO,console

    ⑧启动hive

     ⑨查看监控结果

    - 查看hdfs

    - 查看存储目录/opt/module/apache-flume-1.9.0/flume3下的文件

    结语

    至此,关于Flume数据采集之复制和多路复用案例实战到这里就结束了,我们下期见。。。。。。

  • 相关阅读:
    量化接口代码能不能用?
    Mybatis plus
    DSMM是什么?一篇内容让你快速了解
    this指向
    [附源码]java毕业设计物理中考复习在线考试系统
    软件测试项目该如何规避风险?
    【软考软件评测师】第二十五章 系统安全设计(网络攻击)
    Golang goroutine 进程、线程、并发、并行
    阿里云Maven和Gradle仓库最新配置
    网络技术二十一:ACL包过滤
  • 原文地址:https://blog.csdn.net/yprufeng/article/details/132626743