• Flume监听端口数据


    目录

    Flume定义

    Flume基础架构

    Flume安装部署

    安装部署

    Flume入门案例

    监控端口数据官方案例


    Flume定义

    Flume是Cloudera提供 的一个高可用的,高可靠的,分布式的海量日志采集、聚合和传输的系统。Flume基于流式架构,灵活简单。

    Flume基础架构

    Flume组成架构如下图所示

    Agent

    Agent是一个JVM进程,它以事件的形式数据从源头送至目的。

    Agent主要有3个部分组成,Source、Channel、Sink。

    Source

    Source是负责接收数据到 Flume Agent 的组件。Source组件可以处理各种类型、各种格式 的日志数据,包括 avro、thrift、exec、jms、spooling directory、netcat、taildir、 sequence generator、syslog、http、legacy。

    Sink

    Sink不断地轮询Channel中的事件且批量地移除它们,并将这些事件批量写入到存储或索引系统、或者被发送到另一个Flume Agent

    Sink 组件目的地包括 hdfs、logger、avro、thrift、ipc、file、HBase、solr、自定 义。

    Channel

    Channel 是位于 Source 和 Sink 之间的缓冲区。因此,Channel 允许 Source 和 Sink 运 作在不同的速率上。Channel 是线程安全的,可以同时处理几个 Source 的写入操作和几个 Sink 的读取操作。

    Flume 自带两种 Channel:Memory Channel 和 File Channel。

    Memory Channel 是内存中的队列。Memory Channel 在不需要关心数据丢失的情景下适 用。如果需要关心数据丢失,那么 Memory Channel 就不应该使用,因为程序死亡、机器宕 机或者重启都会导致数据丢失。

    File Channel 将所有事件写到磁盘。因此在程序关闭或机器宕机的情况下不会丢失数 据。

    Event

    传输单元,Flume数据传输的基本单元,以Event的形式将数据从源头送至目的地。Event由Header和Body两部分组成,Header用来存放该event的一些属性,为K-V结构,Body用来存放该条数据,形式为字节数组。

    Flume安装部署

    安装地址

    (1)Flume 官网地址:Welcome to Apache Flume — Apache Flumehttps://flume.apache.org/index.html(2)文档查看地址:Flume 1.10.0 User Guide — Apache Flumehttps://flume.apache.org/FlumeUserGuide.html

    (3)下载地址:Index of /dist/flume (apache.org)http://archive.apache.org/dist/flume/

    安装部署

    (1)将apache-flume-1.9.0-bin.tar.gz上传到 linux 的 /opt/software目录下

    (2)解压 apache-flume-1.9.0-bin.tar.gz 到/opt/module/目录下

    [atguigu@hadoop102 software]$ tar -zxf /opt/software/apacheflume-1.9.0-bin.tar.gz -C /opt/module/

    (3)修改 apache-flume-1.9.0-bin 的名称为 flume

    [atguigu@hadoop102 module]$ mv /opt/module/apache-flume-1.9.0-bin /opt/module/flume

    (4)将 lib 文件夹下的 guava-11.0.2.jar 删除以兼容 Hadoop 3.1.3

    [atguigu@hadoop102 lib]$ rm -rf guava-11.0.2.jar

    Flume入门案例

    监控端口数据官方案例

    案例需求:

    使用Flume监听一个端口,收集该端口数据,并打印到控制台。

    需求分析:

    实现步骤:

     (1)安装 netcat 工具

    [atguigu@hadoop102 software]$ sudo yum install -y nc

    (2)判断 44444 端口是否被占用

    [atguigu@hadoop102 flume-telnet]$ sudo netstat -nlp | grep 44444

    (3)在 flume 目录下创建 job 文件夹并进入 job 文件夹。

    [atguigu@hadoop102 flume]$ mkdir job

    [atguigu@hadoop102 flume]$ cd job/

    (4)在 job 文件夹下创建 Flume Agent 配置文件 flume-netcat-logger.conf。

    [atguigu@hadoop102 job]$ vim flume-netcat-logger.conf

    (5)在 flume-netcat-logger.conf 文件中添加如下内容。

    1. # Name the components on this agent
    2. a1.sources = r1
    3. a1.sinks = k1
    4. a1.channels = c1
    5. # Describe/configure the source
    6. a1.sources.r1.type = netcat
    7. a1.sources.r1.bind = localhost
    8. a1.sources.r1.port = 44444
    9. # Describe the sink
    10. a1.sinks.k1.type = logger
    11. # Use a channel which buffers events in memory
    12. a1.channels.c1.type = memory
    13. a1.channels.c1.capacity = 1000
    14. a1.channels.c1.transactionCapacity = 100
    15. # Bind the source and sink to the channel
    16. a1.sources.r1.channels = c1
    17. a1.sinks.k1.channel = c1

    配置文件解析(图片来源于尚硅谷)

     测试:

    1、先开启服务端

    [atguigu@hadoop102 flume]$ bin/flume-ng agent -c conf/ -n a1 -f job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console

    参数说明:

    --conf/-c:表示配置文件存储在 conf/目录

    --name/-n:表示给 agent 起名为 a1

    --conf-file/-f:flume 本次启动读取的配置文件是在 job 文件夹下的 flume-telnet.conf 文件。

    -Dflume.root.logger=INFO,console :-D 表示 flume 运行时动态修改 flume.root.logger 参数属性值,并将控制台日志打印级别设置为 INFO 级别。日志级别包括:log、info、warn、 error。 

    监听44444端口 

     2、开启客户端

    [atguigu@hadoop102 ~]$ nc localhost 44444

    使用 netcat 工具向本机的 44444 端口发送内容

    在客户端输入数据,测试服务端是否接收数据;

    测试结果如下图 

    在 Flume 监听页面观察接收数据情况

     

  • 相关阅读:
    Spring Framework6.0 发布了GA版,期待已久的新特性功能一览
    【玩转Redhat Linux 8.0系列 | 从命令行管理文件(一)】
    <数据集>腐烂水果识别数据集<目标检测>
    使用Docker安装ElasticSearch和可视化界面Kibana【图文教学】
    Qt之sendEvent
    Redis Twemproxy 集群,水平扩展 ,扩容方案
    【Hello Algorithm】滑动窗口内最大值最小值
    【数据结构】二叉树&&优先级队列——堆
    MySQL常见问题汇总
    docker容器中访问本地宿主机的服务
  • 原文地址:https://blog.csdn.net/qq_70085330/article/details/126313297