flume exec source实时监控单个文件

本文介绍了如何使用Flume exec source实时监控Hive的日志文件,并将这些日志数据上传到HDFS。通过创建flume-agent配置文件,设置HDFS相关参数,并确保Zookeeper、Hadoop和Hive正常运行,可以实现日志的实时传输。当遇到无响应情况时,可以通过调整Flume的日志级别来查看错误信息。
摘要由CSDN通过智能技术生成

1、需求:实时监控Hive日志,并上传到HDFS中

2、需求分析:

在这里插入图片描述

3、创建flume agent配置文件flume-file-hdfs.conf文件

cd /data/flume/apache-flume
vim job/flume-file-hdfs.conf

添加:

# Name the components on this agent
a2.sources = r2
a2.sinks = k2
a2.channels = c2

# Describe/configure the source
a2.sources.r2.type = exec
a2.sources.r2.command = tail -F /data/apache-hive/logs/hive.log
a2.sources.r2.shell = /bin/bash -c

# Describe the sink
a2.sinks.k2.type = hdfs
# a2.sinks.k2.hdfs.path = hdfs://jh/flume/%Y%m%d/%H 这样也行
# 因为我的hadoop集群HA设置的rpc为8020
a2.sinks.k2.hdfs.path = hdfs://jh:8020/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
#积攒多少个Event才flush到HDFS一次
a2.sinks.k2.hdfs.batchSize = 100
#多久生成一个新的文件
a2.sinks.k2.hdfs.rollInterval = 60
#设置每个文件的滚动大小
a2.sinks.k2.hdfs.rollSize = 134217700
#文件的滚动与Event数量无关
a2.sinks.k2.hdfs.rollCount = 0

# Use a channel which buffers events in memory
a2.channels.c2.type = memory
a2.channels.c2.capacity = 10000
a2.channels.c2.transactionCapacity = 1000

# Bind the source and sink to the channel
a2.sources.r2.channels = c2
a2.sinks.k2.channel = c2

注意:
对于所有与时间相关的转义序列,Event Header中必须存在以 “timestamp”的key(除非hdfs.useLocalTimeStamp设置为true,此方法会使用TimestampInterceptor自动添加timestamp)。
a2.sinks.k2.hdfs.useLocalTimeStamp = true

4、运行Flume

bin/flume-ng agent --conf conf/ --name a2 --conf-file job/flume-file-hdfs.conf

5、开启zookeeper、hadoop和hive并操作hive产生日志

bin/zkServer.sh start
sbin/start-all.sh
nohup /data/apache-hive/bin/hive --service metastore &
bin/hive

6、在HDFS上查看文件

在这里插入图片描述

7、如果运行完没反应,多半是报错了,可以执行的时候加上Dflume.root.logger=INFO,console,就可以看到报错信息了

bin/flume-ng agent --conf conf/ --name a2 --conf-file job/flume-file-hdfs.conf -Dflume.root.logger=INFO,console
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值