1、flume是分布式的日志收集系统,把收集来的数据传送到目的地去。
2、flume里面有个核心概念,叫做agent(代理人).agent是一个java进程,这个java进程运行在一个代理
端,就是日志收集节点.
3、agent包含3个核心组件:source,channel(信道),sink(接收器).
3.1 source组件专用于收集日志的,它可以处理各种类型各种格式的日志数据,包括avro、thrift、
exec、jms、spooling directory、NetCat、sequence generator、Syslong、HTTP、legacy、
custom。
source组件把日志收集来以后,临时存放在channel中
3.2 channel组件是在agent中专用于临时存储数据的,可以存放在内存(memory)中,jobc,file,自定义
channel中的数据只有在sink发送成功之后才会被删除
3.3 sink组件用于把数据发送到目的地的组件,目的地包括
logger,hdfs,avro,thrift,ipc,file,null,hbase,solr,自定义。
4、在整个的数据传输过程中流动的是event(一行一行的内容).传输的基本单位是event,
事物保证级别是event级别.
5、安装flume
拷贝flume.xx.src.gz和flume.xx.bin.gz两个文件到/root/Downloads中
[root@hadoop0 local]# tar -zxvf /root/Downloads/apache-flume-1.4.0-bin.tar.gz //解压
[root@hadoop0 local]# tar -zxvf /root/Downloads/apache-flume-1.4.0-src.tar.gz
//复制flume-src下面的文件到bin下面
[root@hadoop0 local]# cp -ri apache-flume-1.4.0-src/* apache-flume-1.4.0-bin/ //复制
[root@hadoop0 local]# cd apache-flume-1.4.0-bin/
[root@hadoop0 apache-flume-1.4.0-bin]# ls
bin flume-ng-configuration flume-ng-sdk NOTICE
CHANGELOG flume-ng-core flume-ng-sinks pom.xml
conf flume-ng-dist flume-ng-sources README
DEVNOTES flume-ng-doc flume-ng-tests RELEASE-NOTES
docs flume-ng-embedded-agent flume-tools tools
flume-ng-channels flume-ng-legacy-sources lib
flume-ng-clients flume-ng-node LICENSE
//删除src,只需要bin就行了
[root@hadoop0 local]# rm -rf apache-flume-1.4.0-src/
//重命名apache-flume-1.4.0-bin
[root@hadoop0 local]# mv apache-flume-1.4.0-bin flume
//进入flume的bin目录下执行flume-ng,会提示如何操作命令
[root@hadoop0 bin]# flume-ng
help display this help text //显示帮助文档
agent run a Flume agent //运行一个flume的代理
avro-client run an avro Flume client //运行一个avro的flume客户端
version show Flume version info //查看flume版本信息
6、支持多级flume的agent,可以前后相接。支持扇入(fan-in),扇出(fin-out)
7、把webserver、source、channel、sink、hdfs连接起来成为一个管道跑数据
agent(代理对象)包含了source,channel(存放数据的通道,临时存放地),sink(发送数据到目的地)
****************************************************************
*如何书写配置文件(example),一一描述source,channel,sink.然后再把它们连接起来
#agent1表示代理名称
agent1.sources=source1
agent1.sinks=sink1
agent1.channels=channel1
#spooling Directory是监控指定文件夹中新文件的变化的,一旦新文件出现,就解析信息文件的内容,然后
#写入到channel中,写入完成后标记该文件,已完成或者删除该文件。
#配置source1(数据从哪儿来) 监控目录中的新文件
agent1.sources.source1.type=spooldir //指定source的类型
agent1.sources.source1.spoolDir=/root/hmbbs //flume监控的目录
agent1.sources.source1.channels=channel1 //指定他使用的channel(信道)1名称
agent1.sources.source1.fileHeader = false //是否标记文件的头部分
agent1.sources.source1.interceptors = i1 //拦截器,event传输过程中可以改变header的信息
agent1.sources.source1.interceptors.i1.type = timestamp //拦截器类型.时间戳,带时间戳信息
#支持占位符,如果是写到hdfs需要依赖hadoop,hadoop必须启动
#配置sink1(数据到哪儿去)
agent1.sinks.sink1.type=hdfs //写入数据的系统类型
agent1.sinks.sink1.hdfs.path=hdfs://hadoop0:9000/hmbbs //写入数据的目录
agent1.sinks.sink1.hdfs.fileType=DataStream //文件格式,数据流,不压缩,直接可以查看文件
agent1.sinks.sink1.hdfs.writeFormat=TEXT-->or(Writable) //写入文件格式
agent1.sinks.sink1.hdfs.rollInterval=1 //回滚周期1秒,即关闭临时文件的时间,很快就会关闭
agent1.sinks.sink1.channel=channel1 //连接那个信道:channel名称
agent1.sinks.sink1.hdfs.filePrefix=%Y-%m-%d //生成的文件使用统一的前缀,时间
#管道,
#(channel管道/信道,把数据的读入和写出连接起来,作为一个桥梁进行数据传输,临时的,channel中的数据
可以写入完成后删除,需要配置)
#配置channel1(信道)
agent1.channels.channel1.type=file //文件类型
agent1.channels.channel1.checkpointDir=/root/hmbbs_tmp123 //指定备份数据的目录
[root@hadoop0 ~]# cd hmbbs_tmp123 //备份文件中的数据
[root@hadoop0 hmbbs_tmp123]# ls
checkpoint checkpoint.meta inflightputs inflighttakes in_use.lock(正在使用)
agent1.channels.channel1.dataDirs=/root/hmbbs_tmp //channel临时存放数据目录
[root@hadoop0 ~]# cd hmbbs_tmp //管道,临时文件存放目录
[root@hadoop0 hmbbs_tmp]# ls
in_use.lock(正在使用,枷锁,不能给占用) log-1 log-1.meta log-2 log-2.meta
******注:一定要创建上面指定的需要的文件夹路径********
8、执行命令指定-n agetn名称,-c conf配置目录,-f指定上面写的那个配置文件所在位置
-D 指定日志级别(调试级别,控制台输出)
[root@hadoop0 flume]#bin/flume-ng agent -n agent1 -c conf -f conf/example
-Dflume.root.logger=DEBUG,console
执行完成之后他会一直处于监控状态,让他运行,重新启动一个客户端,做验证.
[root@hadoop0 ~]# vi hello
//只要一执行这条命令,就会被flume监听到后:然后执行flume监听日志的一系列操作
[root@hadoop0 ~]# cp hello hmbbs
9、只要监听的目录hmbbs有了动静,立面flume就会有反应
[root@hadoop0 ~]# cp install.log hmbbs
他会把数据读入source1,进行一些格式化处理,然后数据送入channel1中,channel1做备份,生成临时
文件夹,并且channel会事先连接source1和sink1,把数据传输到sink1,sink1做一些处理后,把数据写
入到指定的文件系统,我们配置的是hdfs系统,就会写入到指定的hdfs系统的地址中.