使用flume实时监控hive文件到HDFS

Flume最主要的作用就是,实时读取服务器本地磁盘的数据,将数据写入HDFS。

Flume组成架构如下所示:

Flume Agent内部原理如图所示:

 

1.配置hive日志文件存放位置:

2.修改配置项:

在hive的根目录下创建logs文件夹 

3.创建flume的配置文件

在flume的根目录下创建job文件夹用来存放flume的配置文件:

 创建file-flume-hdfs.conf配置文件:

 file-flume-hdfs.conf配置文件内容如下所示:

# Name the components on this agent
a2.sources = r2   #定义source
a2.sinks = k2     #定义sink
a2.channels = c2  #定义channel
# Describe/configure the source
a2.sources.r2.type = exec #定义source类型为exec可执行命令的
a2.sources.r2.command = tail -F /usr/local/hive/logs/hive.log  #hive日志信息存放信息
a2.sources.r2.shell = /bin/bash -c  #执行shell脚本的绝对路径
# Describe the sink 
a2.sinks.k2.type = hdfs 
a2.sinks.k2.hdfs.path = hdfs://master:9000/flume/%Y%m%d/%H 
a2.sinks.k2.hdfs.filePrefix = logs- #上传文件的前缀 
a2.sinks.k2.hdfs.round = true       #是否按照时间滚动文件夹
a2.sinks.k2.hdfs.roundValue = 1     #多少时间单位创建一个新的文件夹
a2.sinks.k2.hdfs.roundUnit = hour   #重新定义时间单位
a2.sinks.k2.hdfs.useLocalTimeStamp = true  #是否使用本地时间戳
a2.sinks.k2.hdfs.batchSize = 1000   #积攒多少个Event才flush到HDFS一次
a2.sinks.k2.hdfs.fileType = DataStream #设置文件类型,可支持压缩
a2.sinks.k2.hdfs.rollInterval = 600    #多久生成一个新的文件
a2.sinks.k2.hdfs.rollSize = 134217700  #设置每个文件的滚动大小
a2.sinks.k2.hdfs.rollCount = 0         #文件的滚动与Event数量无关
a2.sinks.k2.hdfs.minBlockReplicas = 1  #最小冗余数
# Use a channel which buffers events in memory 
a2.channels.c2.type = memory
a2.channels.c2.capacity = 1000
a2.channels.c2.transactionCapacity = 100
# Bind the source and sink to the channel
a2.sources.r2.channels = c2 
a2.sinks.k2.channel = c2 

4.上传jar包到flume的lib文件夹下:

5. 启动flume

6.打开HDFS查看文件:

 

这样,hive的日志文件就实时发送到HDFS上 

发布了85 篇原创文章 · 获赞 39 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_41338249/article/details/101420440