flume 监控目录文件,将内容定时输入到hdfs上

3.3.1  编写脚本文件:tohdfs.conf

#定义agent名, source、channel、sink的名称

a4.sources = r1

a4.channels = c1

a4.sinks = k1

#具体定义source

a4.sources.r1.type = spooldir

a4.sources.r1.spoolDir = /opt/rh

#具体定义channel

a4.channels.c1.type = memory

a4.channels.c1.capacity = 10000

a4.channels.c1.transactionCapacity = 100

#定义拦截器,为消息添加时间戳

a4.sources.r1.interceptors = i1

a4.sources.r1.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder

#具体定义sink

a4.sinks.k1.type = hdfs

#flume这个目录会自动创建

a4.sinks.k1.hdfs.path = hdfs://meboth-master:9000/flume/%Y%m%d

a4.sinks.k1.hdfs.filePrefix = events-

a4.sinks.k1.hdfs.fileType = DataStream

#不按照条数生成文件

a4.sinks.k1.hdfs.rollCount = 0

#HDFS上的文件达到128M时生成一个文件

a4.sinks.k1.hdfs.rollSize = 134217728

#HDFS上的文件达到60秒生成一个文件

a4.sinks.k1.hdfs.rollInterval = 60

 

#组装source、channel、sink

a4.sources.r1.channels = c1

a4.sinks.k1.channel = c1

3.3.2  执行命令

[root@meboth-master flume-1.9.0]# bin/flume-ng agent -c ./execonfbyjurf -f ./execonfbyjurf/tohdfs.conf -n  a4 -Dflume.root.logger=INFO,console

注意:代理的名称要和配置文件设置的代理名称配置一致。如本案例的代理为a4,前面几个为a1,一定配置一致。

3.3.3  将文件扔到指定的目录

[root@meboth-master rh]# cp /opt/tb_user.java .

[root@meboth-master rh]# ls

say.txt.COMPLETED  tb_user.java.COMPLETED

[root@meboth-master rh]#

3.3.4  查看执行命令窗口的日志

3.3.5  查看hdfs上的结果

3.3.6  下载查看内容

打开文件的部分内容截图:

本次案例使用flume-1.9版本操作比较顺利,如果执行命令报错,参考传智介绍的解决方法:

Flume补充hadoop的jar包:

Hadoop-common-xxx.jar

Commons-configuration-xx.jar

Hadoop-auth-xx.jar

Hadoop-hdfs-xx.jar

当执行报错:不知道域名的时候,需要将hadooop下的core-site.xml,hdfs-site.xml拷贝到flume的conf目录下,然后再hosts文件配置:hadoop所在机器的ip与主机的映射。

详情文档见:百度网盘

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
利用FLUME实时读取目录文件HDFS的步骤如下: 1. 首先需要在Flume的conf目录下创建一个新的配置文件,例如my_flume.conf。 2. 在my_flume.conf文件中,需要定义Flume的agent名称以及其它设置,比如数据源、数据目的地、数据处理管道等。例如: ``` # Define an agent named Agent1 agent1.sources = source1 agent1.sinks = sink1 agent1.channels = channel1 # Define a memory channel called channel1 agent1.channels.channel1.type = memory # Define a source that reads files from a directory agent1.sources.source1.type = spooldir agent1.sources.source1.spoolDir = /path/to/spool/directory # Define a sink that writes to HDFS agent1.sinks.sink1.type = hdfs agent1.sinks.sink1.hdfs.path = hdfs://localhost:9000/flume/events agent1.sinks.sink1.hdfs.filePrefix = events- agent1.sinks.sink1.hdfs.fileSuffix = .log agent1.sinks.sink1.hdfs.rollInterval = 3600 agent1.sinks.sink1.hdfs.rollSize = 0 agent1.sinks.sink1.hdfs.rollCount = 10000 # Bind the source and sink to the channel agent1.sources.source1.channels = channel1 agent1.sinks.sink1.channel = channel1 ``` 在这个配置文件中,我们定义了一个名为Agent1的Flume agent,它包含一个source、一个sink和一个channel。source定义了要读取的文件目录,sink定义了数据入的HDFS路径和文件名的前缀、后缀等信息,而channel则定义了source和sink之间的数据传输通道。 3. 启动Flume agent。在命令行中输入以下命令: ``` bin/flume-ng agent --conf conf --conf-file my_flume.conf --name agent1 -Dflume.root.logger=INFO,console ``` 启动后,Flume将开始读取指定目录下的文件,并将其实时HDFS。 注意:在实际使用中,还需要根据具体情况对Flume的配置文件进行调整和优化,以满足实际需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值