Flume案例实战

写在前面

通过前面一篇文章http://blog.csdn.net/liuge36/article/details/78589505的介绍我们已经知道flume到底是什么?flume可以用来做什么?但是,具体怎么做,这就是我们这篇文章想要介绍的。话不多说,直接来案例学习。

实战一:实现官网的第一个简单的小案例-从指定端口采集数据输出到控制台

如何开始呢?

看官网!!!!

地址:http://flume.apache.org/FlumeUserGuide.html#flume-sources

从官网的介绍中,我们知道需要new一个.conf文件,

1.这里我们就在flume的conf文件夹下新建一个test1.conf

2.把官网的A simple example拷贝进去,做简单的修改

[hadoop@hadoop000 conf]$ vim test1.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
#
# # Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = hadoop000
a1.sources.r1.port = 44444 # # Describe the sink
a1.sinks.k1.type = logger # # Use a channel which buffers events in memory
a1.channels.c1.type = memory # # Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1 #不修改也是应该没有什么问题的
#:wq保存退出

3.flume的agent启起来之后,就可以开始测试啦:

[hadoop@hadoop000 data]$ telnet hadoop000 44444
Trying 192.168.1.57...
Connected to hadoop000.
Escape character is '^]'.
你好
OK

这里会发现,刚刚启动的agent界面有输出

到这里,就实现第一个简单的flume案例,很简单是吧

可以看出,使用Flume的关键就是写配置文件

1) 配置Source

2) 配置Channel

3) 配置Sink

4) 把以上三个组件串起来

简单来说,使用flume,就是使用flume的配置文件

实战二:监控一个文件实时采集新增的数据输出到控制台

思路??

前面说到,做flume就是写配置文件

就面临选型的问题

Agent选型,即source选择什么,channel选择什么,sink选择什么

这里我们选择 exec source memory channel logger sink

怎么写呢?

按照之前说的那样1234步骤

从官网中,我们可以找到我们的选型应该如何书写:

1) 配置Source

exec source

Property Name	Default	Description
channels –
type – The component type name, needs to be exec
command – The command to execute
shell – A shell invocation used to run the command. e.g. /bin/sh -c. Required only for commands relying on shell features like wildcards, back ticks, pipes etc.

从官网的介绍中,我们知道我们的exec source得配置type=exec

,配置自己的command,shell也是建议配置上的,其余的配置就不用配置了。是不是很简单。我们这里自己的配置就如下:

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /home/hadoop/data/data.log
a1.sources.r1.shell = /bin/sh -c

2) 配置Channel

memory channel

官网介绍的是:


Property Name Default Description
type – The component type name, needs to be memory

对应着写自己的Channel:

a1.channels.c1.type = memory

3) 配置Sink

logger sink

官网介绍的是:


Property Name Default Description
channel –
type – The component type name, needs to be logger

对应着写自己的Sink:

a1.sinks.k1.type = logger
  1. 把以上三个组件串起来
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

按照1.2.3.4这个固定的套路写任何的agent都是没有问题的

1.我们new一个文件叫做test2.conf

把我们自己的代码贴进去:

[hadoop@hadoop000 conf]$ vim test2.conf
a1.sources = r1
a1.sinks = k1
a1.channels = c1 a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /home/hadoop/data/data.log
a1.sources.r1.shell = /bin/sh -c a1.sinks.k1.type = logger a1.channels.c1.type = memory a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1 #:wq保存退出

2.开启我们的agent

flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/test2.conf \
-Dflume.root.logger=INFO,console

3.开始测试数据

export 到这里,我相信你一定学会如何去写flume了。强调一下,官网是一个好的学习资源,一定不要浪费。这里,我就先简单介绍这么两个小的案例实战,后面还会继续更新更多flume的使用...一起加油

最新文章

  1. 把一个英语句子中的单词次序颠倒后输出。例如输入“how are you”,输出“you are how”;
  2. 【转载】perl接受传递参数的方法
  3. POJ 2762 tarjan缩点+并查集+度数
  4. flex 用footerdatagrid做列的汇总合计
  5. 11g R2 RAC启动关闭步骤
  6. Hadoop1.0.3安装部署
  7. unity图片后期处理
  8. Dagoin之modelform组件
  9. 实验六:通过grub程序引导本地磁盘内核启动系统(busybox)
  10. Docker docker-compose安装
  11. pyqt pyside QPushButton 图标(icon)大小自适应设置
  12. 【云计算】IaaS、PaaS和SaaS
  13. 谈谈javascript数组排序方法sort()的使用,重点介绍参数使用及内部机制?
  14. java.security.NoSuchAlgorithmException: AES KeyGenerator not available
  15. Cordova 8 架构使用sqlite - 谢厂节的博客 - 博客频道 - CSDN.NET - Google Chrome
  16. 利用shell脚本批量提交网站404死链给百度
  17. 新浪微博开放平台账号申请(基于dcloud开发)
  18. 如何防止网页被植入广告,内容被监控-HTTPS
  19. threejs 通过bufferGeometry处理每一个点的位置和颜色
  20. 《DSP using MATLAB》示例 Example 10.2

热门文章

  1. docker An error occurred 虚拟化错误解决
  2. lua_在C#中执行lua脚本
  3. Codeforces 220C
  4. UGUI的图集处理方式-SpriteAtlas的前世今生
  5. 关于简单递归在python3中的实现
  6. Delphi - 通过WinAPI GetCursorPos实现鼠标位置的实时显示
  7. python入门(六)二次编码与文件操作
  8. Java深层复制方式
  9. acm未解之谜-洛谷P1109学生分组
  10. poj 2240 Arbitrage(Bellman_ford变形)