博客
关于我
05_Flume_timestamp interceptor实践
阅读量:797 次
发布时间:2023-04-04

本文共 1750 字,大约阅读时间需要 5 分钟。

Flume Agent与HDFS数据存储流程配置及验证

目标场景

本文将介绍如何配置Flume Agent并使用curl发送HTTP POST请求,将数据存储到HDFS中。通过本文的步骤操作,用户能够实现基于时间戳的数据存储到HDFS的目标。

Flume Agent配置

Flume Agent的配置主要包括以下几个方面:

  • 源(Source)配置

    • 数据类型:http
    • 绑定地址:master
    • 端口:6666
    • 处理器:JSONHandler
    a1.sources.r1.type = http  a1.sources.r1.bind = master  a1.sources.r1.port = 6666  a1.sources.r1.handler = org.apache.flume.source.http.JSONHandler
  • 拦截器(Interceptor)配置

    • 类型:timestamp
      -.preserveExisting:false
    a1.sources.r1.interceptors = i1  a1.sources.r1.interceptors.i1.type = timestamp  a1.sources.r1.interceptors.i1.preserveExisting = false
  • 下沉(Sink)配置

    • 类型:hdfs
    • 路径:hdfs://master:9000/flume/%Y-%m-%d
    • 文件类型:DataStream
    • 角色:基于时间戳创建目录
    a1.sinks.k1.type = hdfs  a1.sinks.k1.hdfs.path = hdfs://master:9000/flume/%Y-%m-%d  a1.sinks.k1.hdfs.useLocalTimeStamp = true  a1.sinks.k1.hdfs.filePrefix = interceptor  a1.sinks.k1.hdfs.fileType = DataStream  a1.sinks.k1.hdfs.writeFormat = Text  a1.sinks.k1.hdfs.rollSize = 102400000  a1.sinks.k1.hdfs.rollCount = 5  a1.sinks.k1.hdfs.rollInterval = 0
  • 通道(Channel)配置

    • 类型:memory
    • 容量:1000
    a1.channels.c1.type = memory  a1.channels.c1.capacity = 1000  a1.channels.c1.transactionCapacity = 100
  • 源与下沉绑定

    a1.sources.r1.channels = c1  a1.sinks.k1.channel = c1
  • curl命令,模拟发送HTTP请求(POST方法)

    使用curl命令发送HTTP POST请求,数据格式为JSON:

    curl -X POST -d '[{"headers":{}, "body":"timestamp teset 001"}]' http://master:6666

    说明:

    • -X POST:使用HTTP POST方法
    • -d:指定发送的JSON数据
    • http://master:6666:目标服务器地址和端口

    检查HDFS上基于event时间戳信息的目录是否成功创建

  • 运行curl命令后,Flume Agent打印日志,提示基于时间戳的HDFS目录正在创建

  • 检查HDFS目录

    假设配置正确,运行curl命令后,HDFS上应创建出类似于hdfs://master:9000/flume/2023-10-01的目录。

  • 数据存储验证

    数据将被存储在上述目录中,文件名为interceptor-000000000000000001.json,内容为{"body":"timestamp teset 001"}

  • 总结

    通过以上步骤,可以实现数据从HTTP源发送到HDFS存储的流程。配置Flume Agent和使用curl命令是实现此流程的关键步骤。确保所有配置参数正确无误,才能顺利完成数据存储任务。

    转载地址:http://oirfk.baihongyu.com/

    你可能感兴趣的文章
    mysql8.0新特性-自增变量的持久化
    查看>>
    Mysql8.0注意url变更写法
    查看>>
    Mysql8.0的特性
    查看>>
    MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    查看>>
    MySQL8修改密码的方法
    查看>>
    Mysql8在Centos上安装后忘记root密码如何重新设置
    查看>>
    Mysql8在Windows上离线安装时忘记root密码
    查看>>
    MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
    查看>>
    mysql8的安装与卸载
    查看>>
    MySQL8,体验不一样的安装方式!
    查看>>
    MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
    查看>>
    Mysql: 对换(替换)两条记录的同一个字段值
    查看>>
    mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
    查看>>
    MYSQL:基础——3N范式的表结构设计
    查看>>
    MYSQL:基础——触发器
    查看>>
    Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
    查看>>
    mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
    查看>>
    mysqldump 参数--lock-tables浅析
    查看>>
    mysqldump 导出中文乱码
    查看>>
    mysqldump 导出数据库中每张表的前n条
    查看>>