zoukankan      html  css  js  c++  java
  • Flume分布式日志收集系统

    1.flume是分布式的日志收集系统,把收集来的数据传送到目的地去。
    2.flume里面有个核心概念,叫做agent。agent是一个java进程,运行在日志收集节点。通过agent接收日志,然后暂存起来,再发送到目的地。
    3.agent里面包含3个核心组件:source、channel、sink。
      3.1 source组件是专用于收集日志的,可以处理各种类型各种格式的日志数据,包括avro、thrift、exec、jms、spooling directory、netcat、sequence generator、syslog、http、legacy、自定义。
        source组件把数据收集来以后,临时存放在channel中。
      3.2 channel组件是在agent中专用于临时存储数据的,可以存放在memory、jdbc、file、自定义。
        channel中的数据只有在sink发送成功之后才会被删除。
      3.3 sink组件是用于把数据发送到目的地的组件,目的地包括hdfs、logger、avro、thrift、ipc、file、null、hbase、solr、自定义。
    4.在整个数据传输过程中,流动的是event。事务保证是在event级别。
    5.flume可以支持多级flume的agent,支持扇入(fan-in)、扇出(fan-out)。

    6、安装Flume:

    1、先将flume的bin.jar和src.jar复制到/usr/local下,然后解压,将src目录下的文件复制到bin目录下:cp -ri apache-flume-1.4.0-src/* apache-flume-1.4.0-bin/
    2、删除/usr/lcoal下的解压好的src文件,再将bin重命名:mv apache-flume-1.4.0-bin flume
    3、flume/bin/ #flume-ng 可以看到命令的相关用法
    4、核心是写配置文件

    7.书写配置文件example

    在flume/conf/下创建配置文件example:
    vi example 或者直接在winSCP中创建

    #agent1表示代理名称
    agent1.sources=source1
    agent1.sinks=sink1
    agent1.channels=channel1
    
    
    #Spooling Directory是监控指定文件夹中新文件的变化,一旦新文件出现,就解析该文件内容,然后写入到channle。写入完成后,标记该文件已完成或者删除该文件。
    #配置source1   interceptor可以在数据传递过程中改变其属性信息
    agent1.sources.source1.type=spooldir
    agent1.sources.source1.spoolDir=/root/hmbbs
    agent1.sources.source1.channels=channel1
    agent1.sources.source1.fileHeader = false
    agent1.sources.source1.interceptors = i1   
    agent1.sources.source1.interceptors.i1.type = timestamp
    
    #配置sink1
    agent1.sinks.sink1.type=hdfs
    agent1.sinks.sink1.hdfs.path=hdfs://hadoop0:9000/hmbbs
    agent1.sinks.sink1.hdfs.fileType=DataStream
    agent1.sinks.sink1.hdfs.writeFormat=TEXT
    agent1.sinks.sink1.hdfs.rollInterval=1
    agent1.sinks.sink1.channel=channel1
    agent1.sinks.sink1.hdfs.filePrefix=%Y-%m-%d
    
    #配置channel1
    agent1.channels.channel1.type=file
    agent1.channels.channel1.checkpointDir=/root/hmbbs_tmp/123
    agent1.channels.channel1.dataDirs=/root/hmbbs_tmp/

    在/root下创建文件夹hmbbs:mkdir hmbbs
    在HDFS中创建文件夹:hadoop fs -mkdir /hmbbs

    8.执行命令bin/flume-ng agent -n agent1 -c conf -f conf/example -Dflume.root.logger=DEBUG,console
    执行完了,flume就会监控/root/hmbbs中数据的变化

    在/root/hmbbs下:
      vi hello
        hello you
        hello me
      cp hello hmbbs
    现在数据就发生了变化!flume就会监控到变化,并把数据文件上传到hdfs中

    可在hadoop0:50070中观察到日志文件

    也可在hadoop0/root/hmbbs下,观察到有个hello.COMPLETED,之前的hello变成了hello.COMPLETED(因为这里使用的是Spooling Directory导致的。对hello从不删除,上传完成只会重命名)

    在/root/hmbbs_tmp目录下,这个目录是channel使用的目录。在/root/hmbbs_tmp123目录下,表示的是备份数据。

  • 相关阅读:
    项目上线前的优化
    vue项目打包上线流程以及遇到的问题
    js放大镜
    vue中mixins(混入)的使用
    vue中的provide和inject (依赖注入)
    Vue Virtual Dom 和 Diff原理
    vue 过滤器
    vue自定义指令的使用场景
    php---前后端分离跨域问题的解决
    PHP---for、while、foreach性能比较
  • 原文地址:https://www.cnblogs.com/ahu-lichang/p/6688200.html
Copyright © 2011-2022 走看看