flume的安装非常简单,只需要解压的tar.gz的包后,就可以启动
大数据之数据采集引擎flum
flum是用来采集文件的比如.log文件,也可以指定一个目录
flum由三个组件组成,分别是:source 、channel、sink
source组件是用来采集日志
channel组件是用来缓冲日志的
sink组件是用来保存日志的
我们把这三个组件共同组成框架叫做agent=source+channel+sink
sink组件可以吧采集到日志信息保存到hdfs、hive、hbase等
接下来我们就为这个agent来配置文件:
#bin/flume-ng agent -n a4 -f myagent/a4.conf -c conf -Dflume.root.logger=INFO,console
#定义agent名, source、channel、sink的名称
a4.sources = r1
a4.channels = c1
a4.sinks = k1
#具体定义source
a4.sources.r1.type = spooldir
a4.sources.r1.spoolDir = /root/training/logs
#定义拦截器,为消息添加时间戳
a4.sources.r1.interceptors = i1
a4.sources.r1.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder
#具体定义channel
a4.channels.c1.type = memory
a4.channels.c1.capacity = 10000
a4.channels.c1.transactionCapacity = 100
#具体定义sink
a4.sinks.k1.type = hdfs
a4.sinks.k1.hdfs.path = hdfs://192.168.157.111:9000/flume/%Y%m%d
a4.sinks.k1.hdfs.filePrefix = events-
a4.sinks.k1.hdfs.fileType = DataStream
#不按照条数生成文件
a4.sinks.k1.hdfs.rollCount = 0
#HDFS上的文件达到128M时生成一个文件
a4.sinks.k1.hdfs.rollSize = 134217728
#HDFS上的文件达到60秒生成一个文件
a4.sinks.k1.hdfs.rollInterval = 60
#组装source、channel、sink
a4.sources.r1.channels = c1
a4.sinks.k1.channel = c1
第一行就是启动命令
启动后可以自动收集日志,但是只能整个文件整个文件的收取,并不是当我写完一条我就收集一条
在收集完后的日志后把原日志文件后添加一个complete的后缀