flume的组件
client:客户端(运行agent的地方)
source:数据源,负责收集数据,将数据写入channel
channel:管道,缓存数据的地方(缓存一定有大小),将数据推送到sink
sink:下沉器,负责拉取channel端的数据,将数据存储到存储系统
interceptor:拦截器,flume允许使用拦截器,拦截器可以作用于source端
也可以作用于sink端,支持拦截器链
selector:作用于source端,决定数据往哪儿个channel中发送
event:flume的事件,相当于一条数据。
agent:flume 的客户端,一个agent运行在一个jvm里,是flume运行的最小单元
flume架构图
其他更多采集方式(图解)查看官方文档 http://flume.apache.org/documentation.html
flume利用source和sink,注重数据的多样性(kafka注重吞吐量)
kafka帮助 http://www.searchdoc.cn/kafka/kafka.apache.org/index.com.coder114.cn.html
多种sink、channel、sink查看官方文档 http://flume.apache.org/documentation.html
flume的高可用原理
每个sink设计一个惩罚因子,每当有一个event处理失败减去惩罚因子,如果低于一个阈值就会进行故障转移
举例
a1.sources = r1
a1.channels = c1
a1.sinks = s1
a1.sources.r1.type=exec
a1.sources.r1.command = tail -F /var/log/nginx/access.log
a1.sources.r1.interceptors=i1 i2 i3
a1.sources.r1.interceptors.i1.type=timestamp
a1.sources.r1.interceptors.i1.preserveExisting=false
a1.sources.r1.interceptors.i2.type=host
a1.sources.r1.interceptors.i2.preserveExisting=false
a1.sources.r1.interceptors.i2.useIP=true
a1.sources.r1.interceptors.i2.hostHeader=hostname
a1.sources.r1.interceptors.i3.type=static
a1.sources.r1.interceptors.i3.preserveExisting=false
a1.sources.r1.interceptors.i3.key=hn
a1.sources.r1.interceptors.i3.value=web.log
a1.channels.c1.type=memory
a1.channels.c1.capacity=1000
a1.channels.c1.transactionCapacity=100
a1.channels.c1.keep-alive=3
a1.channels.c1.byteCapacityBufferPercentage=20
a1.channels.c1.byteCapacity=800000
a1.sinks.s1.type=hdfs
a1.sinks.s1.hdfs.path=hdfs://hadoop01:8020/flume/%{hn}/%Y/%m/%d
a1.sinks.s1.hdfs.filePrefix=%{hostname}-%{hn}
a1.sinks.s1.hdfs.fileSuffix=.log
a1.sinks.s1.hdfs.inUseSuffix=.tmp
a1.sinks.s1.hdfs.rollInterval=60
#日志回滚策略:文件大小、时间、event数量(一般不用)
a1.sinks.s1.hdfs.rollSize=1024
a1.sinks.s1.hdfs.rollCount=10
a1.sinks.s1.hdfs.idleTimeout=0
a1.sinks.s1.hdfs.batchSize=100
a1.sinks.s1.hdfs.fileType=DataStream
a1.sinks.s1.hdfs.writeFormat=Text
a1.sinks.s1.hdfs.round=true
a1.sinks.s1.hdfs.roundValue=5
a1.sinks.s1.hdfs.roundUnit=second
a1.sinks.s1.hdfs.useLocalTimeStamp=true
a1.sources.r1.channels=c1
a1.sinks.s1.channel=c1
采集数据
${FLUME_HOME}/bin/flume-ng agent -c ./conf/ -f /flumeconf/exec-mem-hdfs.conf -n a1 -Dflume.root.logger=INFO,console