zoukankan      html  css  js  c++  java
  • Flume入门

    参考官方文档:http://flume.apache.org/FlumeUserGuide.html

    1. 概述

    1、Flume是一个分布式、可靠、和高可用的海量日志采集、聚合和传输的系统。

    2、Flume可以采集文件,socket数据包等各种形式源数据,又可以将采集到的数据输出到HDFS、hbase、hive、kafka等众多外部存储系统中。

    3、一般的采集需求,通过对flume的简单配置即可实现。

    4、Flume针对特殊场景也具备良好的自定义扩展能力,因此,flume可以适用于大部分的日常数据采集场景。

    2. 运行机制

    1、Flume分布式系统中最核心的角色是agent,flume采集系统就是由一个个agent所连接起来形成。

    2、每一个agent相当于一个数据传递员,内部有三个组件:

    Source:采集源,用于跟数据源对接,以获取数据。

    Sink:下沉地,采集数据的传送目的,用于往下一级agent传递数据或者往最终存储系统传递数据。

    Channel:angent内部的数据传输通道,用于从source将数据传递到sink。

    Source 到 Channel 到 Sink之间传递数据的形式是Event事件;Event事件是一个数据流单元。

     

    两个官网小例子:

    1. 从网络端口获取数据

    在conf/下创建example.conf文件:

    # example.conf: A single-node Flume configuration

    # Name the components on this agent
    a1.sources = r1
    a1.sinks = k1
    a1.channels = c1

    # Describe/configure the source
    a1.sources.r1.type = netcat
    a1.sources.r1.bind = weekend01
    a1.sources.r1.port = 44444

    # Describe the sink
    a1.sinks.k1.type = logger

    # Use a channel which buffers events in memory
    a1.channels.c1.type = memory
    a1.channels.c1.capacity = 1000
    a1.channels.c1.transactionCapacity = 100

    # Bind the source and sink to the channel
    a1.sources.r1.channels = c1
    a1.sinks.k1.channel = c1
    ~

    执行命令: 

    bin/flume-ng agent --conf conf --conf-file conf/example.conf --name a1 -Dflume.root.logger=INFO,console

    演示效果:

    客户端可以通过telnet/netcat weekend01 44444进行连接

    2. 通过指令获取数据

    在conf/下创建文件example2.conf文件:

    # example.conf: A single-node Flume configuration

    # Name the components on this agent
    a1.sources = r1
    a1.sinks = k1
    a1.channels = c1

    # Describe/configure the source
    a1.sources.r1.type = exec
    a1.sources.r1.command = tail -F /home/hadoop/flume/test.log
    a1.sources.r1.channels = c1

    # Describe the sink
    a1.sinks.k1.type = logger

    # Use a channel which buffers events in memory
    a1.channels.c1.type = memory
    a1.channels.c1.capacity = 1000
    a1.channels.c1.transactionCapacity = 100

    # Bind the source and sink to the channel
    a1.sources.r1.channels = c1
    a1.sinks.k1.channel = c1

    执行命令: 

    bin/flume-ng agent --conf conf --conf-file conf/example2.conf --name a1 -Dflume.root.logger=INFO,console

    在自己建的flume/写一段shell程序:

    while true; do echo you are my girl >> test.log; sleep 1; done

    演示效果:

  • 相关阅读:
    深入浅出 Redis client/server 交互流程
    VMware三种网络连接模式(转载)
    ARP 原理及攻击
    symbol lookup error:undefined symbol
    printf 颜色格式串"33[34;1m"
    运行openvas
    openvas 安装
    升级openssl 支持TLS1.2
    Windows登录密码明文获取器
    Linux字符串截取和处理命令 cut、printf、awk、sed、sort、wc
  • 原文地址:https://www.cnblogs.com/DarrenChan/p/6639812.html
Copyright © 2011-2022 走看看