采用Flume实时采集和处理数据

它已成功安装Flume在...的基础上。本文将总结使用Flume实时采集和处理数据,详细过程,如下面:

第一步,在$FLUME_HOME/conf文件夹下,编写Flume的配置文件,命名为flume_first_conf,详细内容例如以下:

#agent1表示代理名称
agent1.sources=source1
agent1.sinks=sink1
agent1.channels=channel1

#Spooling Directory是监控指定目录中新文件的变化,一旦新文件出现,就解析该文件内容。然后写入到channle。写入完毕后。标记该文件已完毕或者删除该文件。

#配置source1 agent1.sources.source1.type=spooldir agent1.sources.source1.spoolDir=/home/yujianxin/hmbbs agent1.sources.source1.channels=channel1 agent1.sources.source1.fileHeader = false agent1.sources.source1.interceptors = i1 agent1.sources.source1.interceptors.i1.type = timestamp #配置channel1 agent1.channels.channel1.type=file agent1.channels.channel1.checkpointDir=/home/yujianxin/hmbbs/hmbbs_tmp123 agent1.channels.channel1.dataDirs=/home/yujianxin/hmbbs/hmbbs_tmp #配置sink1 agent1.sinks.sink1.type=hdfs agent1.sinks.sink1.hdfs.path=hdfs://slave3:9000/hmbbs agent1.sinks.sink1.hdfs.fileType=DataStream agent1.sinks.sink1.hdfs.writeFormat=TEXT agent1.sinks.sink1.hdfs.rollInterval=1 agent1.sinks.sink1.channel=channel1 agent1.sinks.sink1.hdfs.filePrefix=%Y-%m-%d

第二步,编写Shell脚本,运行Flume任务

     <span style="font-size:18px;">        vi flume1.sh

             #!/bin/sh
           flume-ng agent -n agent1 -c conf-f /home/yujianxin/flume/apache-flume-1.4.0-bin/conf/flume_first_conf   
           -Dflume.root.logger=DEBUG,console >./flume1.log 2>&1 &
          让日志收集任务以后台进程执行,且将执行日志重定向到./flume1.log保存。

验证

通过命令行查看新启的进程


不断往Flume监控的文件夹/home/yujianxin/hmbbs1下放置文件

查看./flume.log执行日志,截部分关键图例如以下


查看成功上传到HDFS中的文件

OK。使用Flume自己主动监控指定文件夹下文件的变化,自己主动处理。上传到HDFS。比曾经自己写Shell脚本便利、快捷键、更高效。哈哈


版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/zfyouxi/p/4825142.html