二百一十二、Flume——Flume实时采集Linux中的目录文件写入到HDFS中(亲测、附截图)

一、目的

在实现Flume实时采集Linux中的Hive日志写入到HDFS后,再做一个测试,用Flume实时采集Linux中的目录文件,即使用 Flume 监听Linux整个目录的文件,并上传至 HDFS中

**二、**前期准备

(一)安装好Hadoop、Hive、Flume等工具

(二)Linux中被Flume监控的文件目录

/opt/flume/upload

最初的文件目录为空,没有任何文件!

(三)在HDFS中创建文件夹/flume/upload,即写入的HDFS文件路径

三、创建Flume的任务文件

root@hurys23 conf# vi flume-dir-hdfs.conf

agent a3

a3.sources = r3

a3.sinks = k3

a3.channels = c3

Describe/configure the source

a3.sources.r3.type = spooldir
a3.sources.r3.spoolDir = /opt/flume/upload

a3.sources.r3.fileSuffix = .COMPLETED

a3.sources.r3.fileHeader = true

#忽略所有以.tmp 结尾的文件,不上传

a3.sources.r3.ignorePattern = (\^ *\.tmp)

Describe the sink

a3.sinks.k3.type = hdfs
a3.sinks.k3.hdfs.path = hdfs://hurys23:8020/flume/upload/%Y%m%d/%H

#上传文件的前缀

a3.sinks.k3.hdfs.filePrefix = upload-

#是否按照时间滚动文件夹

a3.sinks.k3.hdfs.round = true

#多少时间单位创建一个新的文件夹

a3.sinks.k3.hdfs.roundValue = 1

#重新定义时间单位

a3.sinks.k3.hdfs.roundUnit = hour

#是否使用本地时间戳

a3.sinks.k3.hdfs.useLocalTimeStamp = true

#积攒多少个 Event 才 flush 到 HDFS 一次

a3.sinks.k3.hdfs.batchSize = 100

#设置文件类型,可支持压缩

a3.sinks.k3.hdfs.fileType = DataStream

#多久生成一个新的文件

a3.sinks.k3.hdfs.rollInterval = 60

#设置每个文件的滚动大小大概是 128M

a3.sinks.k3.hdfs.rollSize = 134217700

#文件的滚动与 Event 数量无关

a3.sinks.k3.hdfs.rollCount = 0

Use a channel which buffers events in memory

a3.channels.c3.type = memory

a3.channels.c3.capacity = 1000

a3.channels.c3.transactionCapacity = 100

Bind the source and sink to the channel

a3.sources.r3.channels = c3

a3.sinks.k3.channel = c3

注意:

1、配置文件中的各项参数需要调式,这里只是为了演示,实现目的、打通路径即可!实际在项目中操作时需要调试参数。

2、a3.sources.r3.spoolDir = /opt/flume/upload 为监控的目录文件在Linux中的路径

3、a3.sinks.k3.hdfs.path = hdfs://hurys23:8020/flume/upload/%Y%m%d/%H 为写入的HDFS文件路径

四、启动Flume任务文件

root@hurys23 flume190# bin/flume-ng agent -n a3 -f /usr/local/hurys/dc_env/flume/flume190/conf/flume-dir-hdfs.conf

五、在Linux中被监控的目录文件夹创建新的文件

(一)到Linux目录文件下

root@hurys23 \~# cd /opt/flume/upload/

root@hurys23 upload# ll

总用量 0

(二)创建.txt文件 .log文件 .tmp文件

root@hurys23 upload# touch atguigu.txt
root@hurys23 upload# touch atguigu.log
root@hurys23 upload# touch atguigu.tmp

(三)创建文件后,ll查看文件状态

root@hurys23 upload# ll

总用量 0

-rw-r--r-- 1 root root 0 12月 5 16:08 atguigu.log.COMPLETED

-rw-r--r-- 1 root root 0 12月 5 16:08 atguigu.tmp

-rw-r--r-- 1 root root 0 12月 5 16:08 atguigu.txt.COMPLETED

由于配置文件中忽略所有以.tmp 结尾的文件,不上传,因此除了atguigu.tmp没变之外,其他文件名都变了

#忽略所有以.tmp 结尾的文件,不上传
a3.sources.r3.ignorePattern = (\^ *\.tmp)

六、Flume任务运行时写入的HDFS文件状况

(一)目前时间戳

2023/12/5 16时

(二)HDFS生成了20231205文件夹、16文件夹及其upload文件

七、关闭Flume任务

首先jps查看Flume任务,然后直接kill程序

root@hurys23 conf# jps

28385 NodeManager

27938 SecondaryNameNode

16642 RunJar

27496 NameNode

27657 DataNode
16113 Application

16310 Jps

28215 ResourceManager
root@hurys23 conf# kill -9 16113

Flume实时采集Linux中的目录文件写入到HDFS的测试就先到这里,后面有问题的话再更新!

这种需求在实际项目中目前还没遇到过,就算提前熟悉一下吧,万一后面碰到呢

相关推荐
狮子再回头10 分钟前
relhat9.1 yum无法安装问题
linux·运维·centos
暮云星影12 分钟前
全志linux开发 USB接口设置
linux·arm开发·驱动开发
江华森29 分钟前
Linux 系统实战完全指南
linux·运维·服务器
Safeploy安策数据31 分钟前
政务云加密太慢?万兆服务器密码机如何破解高并发性能瓶颈
linux·运维·github
阿泽·黑核41 分钟前
06 keyflow 多平台移植指南:STM32/51/ESP32/Linux
linux·stm32·嵌入式硬件
开开心心_Every42 分钟前
近200个工具的电脑故障修复合集
linux·运维·服务器·leetcode·智能手机·电脑·模拟退火算法
NGINX开源社区42 分钟前
NGINX Gateway Fabric 支持 Gateway API Inference Extension
linux·服务器·网络
不会C语言的男孩1 小时前
Linux 系统编程 · 第 9 章:进程创建
linux·c语言·开发语言
babytiger1 小时前
银河麒麟v11,apt 安装不好用了,要打开维护模式
linux·运维·服务器
Android小码家1 小时前
andoird13 + bazel 编译 Linux kernel
linux·运维·服务器