{{format('0')}} {{format('1594')}} {{format('2618')}}

Flume 基本案例 监控目录 自动上传文件到 HDFS [ 哔哔大数据 ]

大数据男孩 文章 正文

想做一个技术博客,奈何实力不够
分享

明妃

{{nature("2022-08-14 17:23:15")}}更新

案例说明

使用 Flume 监控一个本地目录,如果目录有新的文件产生,则会自动传到 HDFS 上

配置本案例任务需要的Flume文件

在 Flume 的 conf/ 目录下创建,名称为 spooldir-hdfs.properties

# 相当定义 Flume 的三个组件变量名
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1

# 配置 source 组件
agent1.sources.source1.type =spooldir
    # 监控的本地路径
agent1.sources.source1.spoolDir =/home/logs/ 
agent1.sources.source1.fileHeader = false

#配置拦截器
agent1.sources.source1.interceptors = i1
agent1.sources.source1.interceptors.i1.type = host
agent1.sources.source1.interceptors.i1.hostHeader = hostname

# 配置 sink 组件
agent1.sinks.sink1.type = hdfs
agent1.sinks.sink1.hdfs.path=hdfs://192.168.176.65:9000/locadir/flume_log/%y-%m-%d/%H-%M
agent1.sinks.sink1.hdfs.filePrefix = events
agent1.sinks.sink1.hdfs.maxOpenFiles = 5000
agent1.sinks.sink1.hdfs.batchSize= 100
agent1.sinks.sink1.hdfs.fileType = DataStream
agent1.sinks.sink1.hdfs.writeFormat =Text
agent1.sinks.sink1.hdfs.rollSize = 102400
agent1.sinks.sink1.hdfs.rollCount = 1000000
agent1.sinks.sink1.hdfs.rollInterval = 60
#agent1.sinks.sink1.hdfs.round = true
#agent1.sinks.sink1.hdfs.roundValue = 10
#agent1.sinks.sink1.hdfs.roundUnit = minute
agent1.sinks.sink1.hdfs.useLocalTimeStamp = true
# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.keep-alive = 120
agent1.channels.channel1.capacity = 500000
agent1.channels.channel1.transactionCapacity = 600

# Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1

任务命令说明

下面命令是在 FLume 的根目录里执行的

flume-ng agent -c conf -f conf/spooldir-hdfs.properties -n agent1 -Dflume.root.logger=INFO,console
参数 作用 实例
conf 或 -c 指定配置文件的地址,包含 flume-env.sh 和 log4j 的配置文件 -c conf
-conf-file 或 -f 当前任务的配置文件地址 -fconf-file conf/spooldir-hdfs.properties
-name 或 -n agent名称 -name agent1
-z zookeeper连接的字符串 -z zkhost:2181,zkhost1:2181
-p zookeeper中的存储路径前缀 -p /flume
-Dflume 启动日志打印到当前控制台 -Dflume.root.logger=INFO,console

测试任务

开启两个窗口,其中一个进入监控的目录,查看 HDFS 上的目录

[mark]() [mark]()

另一个窗口运行命令,这样就运行成功

[mark]()

在 /home/logs 目录下创建一个文件,就会发现该文件被自动上传到了 HDFS 上

[mark]()

评论 0
0
{{userInfo.data?.nickname}}
{{userInfo.data?.email}}
TOP 2
Spark 2.0 单机模式与集群模式 安装

{{nature('2020-01-02 16:47:07')}} {{format('12521')}}人已阅读

TOP 3
Office 2016 Pro Plus 激活

{{nature('2019-12-11 20:43:10')}} {{format('9409')}}人已阅读

TOP 4
Linux上 MySQL 开启远程登陆的两种方法

{{nature('2019-12-26 17:20:52')}} {{format('7404')}}人已阅读

TOP 5
Linux 安装 MySQL 5.7

{{nature('2019-12-26 16:03:55')}} {{format('4878')}}人已阅读

目录

标签云

案例 Flume

一言

# {{hitokoto.data.from || '来自'}} #
{{hitokoto.data.hitokoto || '内容'}}
作者:{{hitokoto.data.from_who || '作者'}}
自定义UI
配色方案

侧边栏