官方文档:
https://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html
实现的大致思路是使用exec读取一个命令的执行结果,并将该结果发送至HDFS中。
- 创建conf文件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24[root@hadoop01 test_conf]# pwd /usr/local/wyh/apache-flume-1.8.0-bin/test_conf [root@hadoop01 test_conf]# cat test-exec-hdfs.conf myagent.sources=mysource1 myagent.channels=mychannel1 myagent.sinks=mysink1 myagent.sources.mysource1.channels=mychannel1 myagent.sinks.mysink1.channel=mychannel1 myagent.sources.mysource1.type=exec #指定exec要监控的命令 myagent.sources.mysource1.command=tail -F /usr/local/wyh/test_data/test-exec-hdfs.txt myagent.channels.mychannel1.type=memory myagent.sinks.mysink1.type=hdfs #指定将数据存在HDFS的哪个目录下,如果目录不存在会自动创建目录 myagent.sinks.mysink1.hdfs.path=hdfs://hadoop01:8020/testflume #官方文档指出发送到hdfs的数据必须要包含一个timestamp myagent.sinks.mysink1.hdfs.useLocalTimeStamp=true myagent.sinks.mysink1.hdfs.writeFormat=Text myagent.sinks.mysink1.hdfs.fileType=DataStream
- 启动flume agent
复制代码
1
2[root@hadoop01 test_conf]# flume-ng agent -c /usr/local/wyh/apache-flume-1.8.0-bin/conf -f /usr/local/wyh/apache-flume-1.8.0-bin/test_conf/test-exec-hdfs.conf -n myagent -Dflume.root.logger=INFO,console
source和sink已启动:
重新打开一个终端,创建数据文件:
复制代码
1
2
3
4
5[root@hadoop01 test_data]# cat test-exec-hdfs.txt hello exec - hdfs flume~ [root@hadoop01 test_data]# pwd /usr/local/wyh/test_data
回到启动flume agent的终端可以看到数据已经写入HDFS:
也可以从目录树中看到数据文件已经存在:
以上就是flume中使用exec监听命令执行结果并将数据写入HDFS的实现过程。
最后
以上就是平淡羊最近收集整理的关于使用Flume exec读取数据并读入HDFS的全部内容,更多相关使用Flume内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复