您现在的位置是:首页 > 博客日记 > Java Java

Flume 简单使用和搭建

2019-09-18 22:24:37 【Java】 人已围观

1.解压flume 到/usr/local/webserver/文件夹下

2.自定义 .config 名字随意起

定义三大组件的名称

  1. ag1.sources = source1
  2. ag1.sinks = sink1
  3. ag1.channels = channel1

配置source组件

  1. ag1.sources.source1.type = spooldir #行为特点是 只要目录出现新的日志文件 就会读取
  2. ag1.sources.source1.spoolDir = /root/log/
  3. ag1.sources.source1.fileSuffix=.FINISHED

采集数据一行的最大K

  1. ag1.sources.source1.deserializer.maxLineLength=5120

配置sink组件

  1. ag1.sinks.sink1.type = hdfs
  2. ag1.sinks.sink1.hdfs.path =hdfs://hdp-01:9000/access_log/%y-%m-%d/%H-%M #文件夹路径
  3. ag1.sinks.sink1.hdfs.filePrefix = app_log # 前缀
  4. ag1.sinks.sink1.hdfs.fileSuffix = .log #后缀
  5. ag1.sinks.sink1.hdfs.batchSize= 100 #多少条数据刷一次hdfs
  6. ag1.sinks.sink1.hdfs.fileType = DataStream #文件类型
  7. ag1.sinks.sink1.hdfs.writeFormat =Text #写到hdfs上 用Text
  8. ## roll:滚动切换:控制写文件的切换规则
  9. ag1.sinks.sink1.hdfs.rollSize = 512000 ## 按文件体积(字节)来切 500K 切切一次
  10. ag1.sinks.sink1.hdfs.rollCount = 1000000 ## 按event条数切 按照多少条记录切一次
  11. ag1.sinks.sink1.hdfs.rollInterval = 60 ## 按时间间隔切换文件 60秒切一次
  12. ## 控制生成目录的规则
  13. ag1.sinks.sink1.hdfs.round = true #是否切换目录
  14. ag1.sinks.sink1.hdfs.roundValue = 10 #10分组切一次
  15. ag1.sinks.sink1.hdfs.roundUnit = minute #分钟
  16. ag1.sinks.sink1.hdfs.useLocalTimeStamp = true #使用本地的时间戳取时间

channel组件配置

  1. ag1.channels.channel1.type = memory
  2. ag1.channels.channel1.capacity = 500000 ## event条数 容量 50W条
  3. ag1.channels.channel1.transactionCapacity = 600 ##flume事务控制所需要的缓存容量600条event

绑定source、channel和sink之间的连接

  1. ag1.sources.source1.channels = channel1
  2. ag1.sinks.sink1.channel = channel1

启动 flume

  1. bin/flume-ng agent -c conf/ -f dir-hdfs.conf -n ag1 -Dflume.root.logger=INFO,console
  1. -c 配置文件目录
  2. -f 采集文件配置
  3. -n ag1
  4. -Dflume.root.logger=INFO,console 打印 日志到控制台

配置2

  1. tail-hdfs.conf

tail-hdfs.conf

用tail命令获取数据,下沉到hdfs
启动命令:

  1. bin/flume-ng agent -c conf -f conf/tail-hdfs.conf -n a1
  1. # Name the components on this agent
  2. a1.sources = r1
  3. a1.sinks = k1
  4. a1.channels = c1
  5. # Describe/configure the source
  6. a1.sources.r1.type = exec
  7. a1.sources.r1.command = tail -F /root/app_weichat_login.log
  8. # Describe the sink
  9. agent1.sinks.sink1.type = hdfs
  10. agent1.sinks.sink1.hdfs.path =hdfs://hdp20-01:9000/app_weichat_login_log/%y-%m-%d/%H-%M
  11. agent1.sinks.sink1.hdfs.filePrefix = weichat_log
  12. agent1.sinks.sink1.hdfs.fileSuffix = .dat
  13. agent1.sinks.sink1.hdfs.batchSize= 100
  14. agent1.sinks.sink1.hdfs.fileType = DataStream
  15. agent1.sinks.sink1.hdfs.writeFormat =Text
  16. agent1.sinks.sink1.hdfs.rollSize = 100
  17. agent1.sinks.sink1.hdfs.rollCount = 1000000
  18. agent1.sinks.sink1.hdfs.rollInterval = 60
  19. agent1.sinks.sink1.hdfs.round = true
  20. agent1.sinks.sink1.hdfs.roundValue = 1
  21. agent1.sinks.sink1.hdfs.roundUnit = minute
  22. agent1.sinks.sink1.hdfs.useLocalTimeStamp = true
  23. # Use a channel which buffers events in memory
  24. a1.channels.c1.type = memory
  25. a1.channels.c1.capacity = 1000
  26. a1.channels.c1.transactionCapacity = 100
  27. # Bind the source and sink to the channel
  28. a1.sources.r1.channels = c1
  29. a1.sinks.k1.channel = c1

两个agent 级联
串联 flume 采集数据 发送到另一个 flume上处理数据 最后存到hdfs
发送消息客户端配置
tail-avro.conf
从tail命令获取数据发送到avro端口
另一个节点可配置一个avro源来中继数据,发送外部存储

  1. ##################
  2. # Name the components on this agent
  3. a1.sources = r1
  4. a1.sinks = k1
  5. a1.channels = c1
  6. # Describe/configure the source
  7. a1.sources.r1.type = exec
  8. a1.sources.r1.command = tail -F /root/log/access.log
  9. # Describe the sink
  10. a1.sinks.k1.type = avro
  11. a1.sinks.k1.hostname = hdp-05 #目标主机
  12. a1.sinks.k1.port = 4141 #目标端口
  13. a1.sinks.k1.batch-size = 2 #2条发一次
  14. # Use a channel which buffers events in memory
  15. a1.channels.c1.type = memory
  16. a1.channels.c1.capacity = 1000
  17. a1.channels.c1.transactionCapacity = 100
  18. # Bind the source and sink to the channel
  19. a1.sources.r1.channels = c1
  20. a1.sinks.k1.channel = c1

发送消息服务端配置
avro-hdfs.conf
从avro端口接收数据,下沉到hdfs

  1. bin/flume-ng agent -c conf -f conf/avro-m-log.conf -n a1 -Dflume.root.logger=INFO,console

采集配置文件,avro-hdfs.conf

  1. # Name the components on this agent
  2. a1.sources = r1
  3. a1.sinks = k1
  4. a1.channels = c1
  5. # Describe/configure the source
  6. ##source中的avro组件是一个接收者服务
  7. a1.sources.r1.type = avro
  8. a1.sources.r1.bind = hdp-05
  9. a1.sources.r1.port = 4141
  10. # Describe the sink
  11. a1.sinks.k1.type = hdfs
  12. a1.sinks.k1.hdfs.path = /flume/taildata/%y-%m-%d/
  13. a1.sinks.k1.hdfs.filePrefix = tail-
  14. a1.sinks.k1.hdfs.round = true
  15. a1.sinks.k1.hdfs.roundValue = 24
  16. a1.sinks.k1.hdfs.roundUnit = hour
  17. a1.sinks.k1.hdfs.rollInterval = 0
  18. a1.sinks.k1.hdfs.rollSize = 0
  19. a1.sinks.k1.hdfs.rollCount = 50
  20. a1.sinks.k1.hdfs.batchSize = 10
  21. a1.sinks.k1.hdfs.useLocalTimeStamp = true
  22. #生成的文件类型,默认是Sequencefile,可用DataStream,则为普通文本
  23. a1.sinks.k1.hdfs.fileType = DataStream
  24. # Use a channel which buffers events in memory
  25. a1.channels.c1.type = memory
  26. a1.channels.c1.capacity = 1000
  27. a1.channels.c1.transactionCapacity = 100
  28. # Bind the source and sink to the channel
  29. a1.sources.r1.channels = c1
  30. a1.sinks.k1.channel = c1

发送数据:

  1. $ bin/flume-ng avro-client -H localhost -p 4141 -F /usr/logs/log.10


关注TinyMeng博客,更多精彩分享,敬请期待!
 

很赞哦! ()