采集需求:比如业务系统使用log4j生成的日志,日志内容不断增加,需要把追加到日志文件中的数据实时采集到hdfs,使用agent串联

根据需求,首先定义以下3大要素

第一台flume agent

l  采集源,即source——监控文件内容更新 :        exec  ‘tail -F file’

l  下沉目标,即sink——数据的发送者,实现序列化  :  avro sink

l  Source和sink之间的传递通道——channel,可用file channel 也可以用 内存channel

第二台flume agent

l  采集源,即source——接受数据。并实现反序列化 : avro source

l  下沉目标,即sink——HDFS文件系统 :  HDFS sink

l  Source和sink之间的传递通道——channel,可用file channel 也可以用 内存channel

配置文件编写:

在mini1的conf下

 vi execsource-avrosink.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1 # Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /root/logs/test.log # Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.channel = c1
a1.sinks.k1.hostname = mini2
a1.sinks.k1.port =
a1.sinks.k1.batch-size = # Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity =
a1.channels.c1.transactionCapacity = # Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

在mini2造数据

while true; do date >>test.log ;sleep .5s; done            

在mini2的conf下

avro-sink.conf
a1.sources = r1
a1.sinks =s1
a1.channels = c1 ##source中的avro组件是一个接收者服务
a1.sources.r1.type = avro
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = a1.sinks.s1.type=hdfs
a1.sinks.s1.hdfs.path=/flumedata
a1.sinks.s1.hdfs.filePrefix = access_log
a1.sinks.s1.hdfs.batchSize=
a1.sinks.s1.hdfs.fileType = DataStream
a1.sinks.s1.hdfs.writeFormat =Text
a1.sinks.s1.hdfs.rollSize =
a1.sinks.s1.hdfs.rollCount =
a1.sinks.s1.hdfs.rollInterval =
a1.sinks.s1.hdfs.round = true
a1.sinks.s1.hdfs.roundValue =
a1.sinks.s1.hdfs.roundUnit = minute a1.channels.c1.type = memory
a1.channels.c1.capacity =
a1.channels.c1.transactionCapacity = a1.sources.r1.channels = c1
a1.sinks.s1.channel = c1

启动

在mini2先启动 bin/flume-ng agent -c conf -f conf/avro-sink.conf -n a1 -Dflume.root.logger=INFO,console
在mini1再启动 bin/flume-ng agent -c conf -f conf/execsource-avrosink.conf -n a1 -Dflume.root.logger=INFO,console

结果

最新文章

  1. C#遐想/瞎想
  2. jQuery初探 jQuery选取和操纵元素的特点
  3. IE8的parseInt
  4. 对CPU做下性能测试
  5. only for equality comparisons Hash Index Characteristics
  6. Java部分总结图片版(已经加上原图链接下载!!!)
  7. Float Equal Problem
  8. 常用Ubuntu 命令
  9. SQL 局域网远程备份
  10. 201521123036 《Java程序设计》第14周学习总结
  11. C++ 精英化趋势
  12. Exp3 免杀原理与实践 20164302 王一帆
  13. javascript var变量删除
  14. 开源流媒体服务器SRS学习笔记(1) - 安装、推流、拉流
  15. NoSQL——not onlySQL不仅仅是SQL
  16. AWS S3 CLI的安装和配置
  17. Mysql安装(win10 64位)
  18. 初识云计算的三种服务模式 (IaaS SaaS PaaS)
  19. JavaScript的事件的处理函数(鼠标,键盘,HTML)
  20. [Angular-Scaled web] 5. ui-router $stateParams for sharing information

热门文章

  1. H5图片预览功能
  2. idea web项目热部署
  3. linux小白成长之路13————用U盘安装linux服务器
  4. Dom 获取、Dom动态创建节点
  5. let块级引起的闭包思考
  6. android studio MQTT测试成功
  7. JAVA解析XML的几种方法
  8. Java子类与父类方法的隐藏和覆盖
  9. codevs 2905 足球晋级
  10. 3.12 在运算和比较时使用NULL值