这两天看了一下Flume的开发文档,而且体验了下Flume的使用。html
本文就从以下的几个方面讲述下个人使用心得:java
Flume的配置是真繁琐,source,channel,sink的关系在配置文件里面交织在一块儿,没有Logstash那么简单明了。node
Flume与Logstash相比,我我的的体会以下:redis
Logstash中:shell
在Logstash比较看重input,filter,output之间的协同工做,所以多个输入会把数据汇总到input和filter之间的buffer中。filter则会从buffer中读取数据,进行过滤解析,而后存储在filter于output之间的Buffer中。当buffer知足必定的条件时,会触发output的刷新。apache
在Flume中:windows
Flume比较看重数据的传输,所以几乎没有数据的解析预处理。仅仅是数据的产生,封装成event而后传输。传输的时候flume比logstash多考虑了一些可靠性。由于数据会持久化在channel中(通常有两种能够选择,memoryChannel就是存在内存中,另外一个就是FileChannel存储在文件种),数据只有存储在下一个存储位置(多是最终的存储位置,如HDFS;也多是下一个Flume节点的channel),数据才会从当前的channel中删除。这个过程是经过事务来控制的,这样就保证了数据的可靠性。app
不过flume的持久化也是有容量限制的,好比内存若是超过必定的量,也同样会爆掉。elasticsearch
在官网下载最新版本http://flume.apache.org/download.html,目前最新的版本是1.6.0ide
默认flume是不支持windows的,没有bat的启动命令。不过有一个flume-ng.cmd,其实它也不是启动文件,只是启动了一个powershell而已,若是你本地有这个软件,就能够在windows下运行了。
powershell.exe -NoProfile -InputFormat none -ExecutionPolicy unrestricted -File %~dp0flume-ng.ps1 %*
存放了启动脚本
启动所需的全部组件jar包
提供了几个测试配置文件
文档
跟日志输出有关的一个jar包(不知道有什么不一样)
# 关于license的一大堆 blabla # 配置sources,channels,sinks的名称 agent.sources = seqGenSrc agent.channels = memoryChannel agent.sinks = loggerSink # 配置sources是哪种类型,注意能够由多个source哦! # seq 是专门给测试用的,会自动产生一大堆数据。 # (其实我以为stdin最好,不过flume没这个source) agent.sources.seqGenSrc.type = seq # 配置source输出的channel为memoryChannel(名称,你也能够叫c1) agent.sources.seqGenSrc.channels = memoryChannel # 配置sink是哪种类型,本例子为logger,即log4j输出。 # (log4j会参考conf下的log4j.properties文件,通常开启consoleAppender作测试就行) agent.sinks.loggerSink.type = logger # 配置sink取数据的channel为memoryChannel,注意跟上面的名字保持一致哦! agent.sinks.loggerSink.channel = memoryChannel # 配置channel的类型 agent.channels.memoryChannel.type = memory # 配置channel的容量 agent.channels.memoryChannel.capacity = 100
而后在flume目录下,输入下面的命令:
bin/flume-ng agent --conf-file conf/flume-conf.properties.template --name agent -Dflume.root.logger=INFO,console -C .
而后就能够看到满屏滚动的信息了!
注意:上面启动命令没一个字母是废话!
你能够输入flume-ng help
得到帮助提示:
[root@10 /xinghl/flume]$ bin/flume-ng hekp Usage: bin/flume-ng <command> [options]... commands: help display this help text agent run a Flume agent avro-client run an avro Flume client version show Flume version info global options: --conf,-c <conf> use configs in <conf> directory --classpath,-C <cp> append to the classpath --dryrun,-d do not actually start Flume, just print the command --plugins-path <dirs> colon-separated list of plugins.d directories. See the plugins.d section in the user guide for more details. Default: $FLUME_HOME/plugins.d -Dproperty=value sets a Java system property value -Xproperty=value sets a Java -X option agent options: --name,-n <name> the name of this agent (required) --conf-file,-f <file> specify a config file (required if -z missing) --zkConnString,-z <str> specify the ZooKeeper connection to use (required if -f missing) --zkBasePath,-p <path> specify the base path in ZooKeeper for agent configs --no-reload-conf do not reload config file if changed --help,-h display help text avro-client options: --rpcProps,-P <file> RPC client properties file with server connection params --host,-H <host> hostname to which events will be sent --port,-p <port> port of the avro source --dirname <dir> directory to stream to avro source --filename,-F <file> text file to stream to avro source (default: std input) --headerFile,-R <file> File containing event headers as key/value pairs on each new line --help,-h display help text Either --rpcProps or both --host and --port must be specified.
这里就挑重要的参数将了:
这个是很重要的参数,由于flume可使用不一样的角色启动,好比agent以及client等等。暂时搞不清楚avro-client有什么特殊的,先了解一下吧!平时启动就使用agent就能够了。
--conf 或者 -c ,指定去conf目录下加载配置文件
--classpath 或者 -C,指定类加载的路径(不知道为何我下载flume版本启动的时候找不到log4j配置,只能加上 -C .
才能启动!)
-Dproperty=value 这个参数比较重要,好比logger就须要它来指定传输的级别等信息。若是没有这个参数,logger就很差使了。
其中最终要的就是 --name 或者 -n ,它指定了启动agent的名称,注意是启动agent的名称。
这个名称必须与配置文件中的同样
这个名称必须与配置文件中的同样
这个名称必须与配置文件中的同样
重要的事情重复三遍!
若是写错了!一段小异常就跑来了~(好比我配置文件中为agent,启动命令中写agent123)
2016-06-30 17:04:19,529 (conf-file-poller-0) [WARN - org.apache.flume.node.AbstractConfigurationProvider.getConfiguration(AbstractConfigurationProvider.java:133)] No configuration found for this host:agent123
另外,就是经过--conf-file 或者 -f 指定配置文件。若是配置文件放在conf,也等同于--conf。
参数就介绍到这里了。