Flume--测试

本文介绍如何使用Flume实现日志文件的实时采集,并通过内存通道暂存数据,最后将数据输出到控制台日志中。具体步骤包括配置exec source、memory channel及logger sink等组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、前言

  • step1:开发一个文件,properties类型的文件

  • step2:在文件中要定义一个agent,这个agent中要定义source、channel、sink

    • source:从哪采集数据
    • channel:采集到的数据临时存放在哪
    • sink:将采集的数据发送到哪去
  • step3:使用Flume的命令运行这个文件中的agent即可

  • 官网: http://archive.cloudera.com/cdh5/cdh/5/flume-ng-1.6.0-cdh5.14.0/FlumeUserGuide.html

  • Flume提供了非常全面的组件的支持

  • Source
    在这里插入图片描述

  • Channel
    在这里插入图片描述

  • Sink

在这里插入图片描述

2、测试

cd /export/servers/flume-1.6.0-cdh5.14.0-bin/
  • 创建案例测试目录以及测试的数据文件
mkdir userCase
cd /export/datas
touch hive.log
  • 复制官方的示例程序
cd userCase/
cp ../conf/flume-conf.properties.template ./
mv flume-conf.properties.template log-console.properties
  • 编辑这个文件
# define sourceName/channelName/sinkName for the agent 
a1.sources = s1
a1.channels = c1
a1.sinks = k1
​
# define the s1
a1.sources.s1.type = exec
a1.sources.s1.command  = tail -f /export/datas/hive.log
​
​
# define the c1
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
​
# def the k1
a1.sinks.k1.type = logger
​
#source、channel、sink bond
a1.sources.s1.channels = c1
a1.sinks.k1.channel = c1
  • 运行这个程序
  • 查看命令的用法
Usage: bin/flume-ng <command> [options]...
  • 具体的命令
bin/flume-ng agent -c conf/ -f userCase/log-console.properties -n a1  -Dflume.root.logger=INFO,console

​--conf,-c <conf> :指定Flume的配置文件目录
--name,-n <name>:指定运行的agent的名字
--conf-file,-f <file>:指定运行哪个文件

-Dflume.root.logger=INFO,console:将Flume的日志调整为INFO级别,并显示在控制台
  • 提交运行
bin/flume-ng agent -c conf/ -f userCase/log-console.properties -n a1  -Dflume.root.logger=INFO,console
  • 注意:Flume是前端运行程序,如果要关闭,必须手动Ctrl+c
  • 观察结果
    • 刚启动
      在这里插入图片描述
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值