Flume

@Flume

Flume 传输框架

是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集、聚合和传输的系统。Flume基于流式框架,灵活简单。
最主要的作用就是实时采集数据传输给HDFS

组成部分

Source:
负责接收数据带Flume Agent的组件,可以处理各种类型、各种格式的日志数据、包括avro、thrift、spooling directory、netcat、syslog、http。

Sink:
负责不断地轮询Channel中的时间并且批量的移除他们,将这些时间批量写入到存储或索引系统、或者被发送到另一个Flume Agent。目的地包括HDFS、logger、avro、thrift、ipc、file、HBase、solr等

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

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

source可以有多个Channel
Sink只能有一个Channel,一个Channel可以有多个Sink

简单案例

实时监控单个追加文件
实时监控Hive日志,并上传到HDFS上。 创造符合条件的flume配置文件,执行配置文件开启监控=》开启Hive,生成日志=》查看HDFS数据

exec-momory-hdfs.conf

exec-momory-hdfs.sources = r1
exec-momory-hdfs.sinks = k1
exec-momory-hdfs.channels = c1

#Describe/configure the source
exec-momory-hdfs.sources.r1.type = exec
exec-momory-hdfs.sources.r1.command = tail -F /opt/modules/hive-1.1.0-cdh5.15.1/logs/hive.log
#tail -F /opt/modules/hive-1.1.0-cdh5.15.1/logs/hive.log  -c +0  会重新读取数据
exec-momory-hdfs.sources.r1.shell = /bin/sh -c     
              
# Describe the sink
exec-momory-hdfs.sinks.k1.type = hdfs
exec-momory-hdfs.sinks.k1.hdfs.path = /flume/%Y%m%d/%H
#上传文件夹的前缀
exec-momory-hdfs.sinks.k1.hdfs.filePrefix = logs-
#是否按照时间滚动文件夹
exec-momory-hdfs.sinks.k1.hdfs.round = true
#多少时间单维创建一个新的文件夹
exec-momory-hdfs.sinks.k1.hdfs.roundValue = 1
#重新定义时间单位
exec-momory-hdfs.sinks.k1.hdfs.roundUnit = hour
#是否使用本地时间戳
exec-momory-hdfs.sinks.k1.hdfs.useLocalTimeStamp = true
#积攒多少Event才flush到HDFS一次
exec-momory-hdfs.sinks.k1.hdfs.batchSize = 1000
#多久生成一个新的文件
exec-momory-hdfs.sinks.k1.hdfs.rollInterval = 30
#设置文件类型,可支持压缩
exec-momory-hdfs.sinks.k1.hdfs.fileType = DataStream
#设置每个文件的滚动大小
exec-momory-hdfs.sinks.k1.hdfs.rollSize = 134217700
#文件的滚动与Event数量无关
exec-momory-hdfs.sinks.k1.hdfs.rollCount = 0

# Use a channel which buffers events in memory
exec-momory-hdfs.channels.c1.type = memory
exec-momory-hdfs.channels.c1.capacity = 1000
exec-momory-hdfs.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
exec-momory-hdfs.sources.r1.channels = c1
exec-momory-hdfs.sinks.k1.channel = c1

在此之前需先启动namenode,datanode hive metastore
[root@centos7 hadoop-2.6.0-cdh5.15.1]# jps
3072 NameNode
3385 SecondaryNameNode
3211 DataNode
3503 Jps
[root@centos7 hive-1.1.0-cdh5.15.1]# bin/hive --service metastore
[root@centos7 ~]# jps
3072 NameNode
3761 Jps
3528 RunJar
3385 SecondaryNameNode
3211 DataNode

执行命令

bin/flume-ng agent \
-c conf \
-f conf/exec-momery-hdfs.conf \
-n exec-momory-hdfs \
-Dflume.root.logger=INFO,console

此时查看centos7:50070可看到文件已被创立

[root@centos7 hadoop-2.6.0-cdh5.15.1]# bin/hadoop fs -ls /flume/20200331
20/03/31 21:22:34 WARN util.NativeCodeLoader: Unable to load native-hadoop     library for your platform... using builtin-java classes where applicable
Found 1 items
drwxr-xr-x   - root flume          0 2020-03-31 21:20 /flume/20200331/21
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值