本文共 1918 字,大约阅读时间需要 6 分钟。
1.一个简单的例子
1.写配置文件01localDir_local.flu#flume中一个基本单元式agent,可以有多个channel,多个sink#给代理起名称, 不需要声明直接使用#分布给a1代理下的source channel sink起一个名称#a1代理下sources有一个名为s1#如果有多个:a1.channels=c1 c2 c3sources = s1a1.channels=c1a1.sinks=k1#指定source类型 监控本地目录a1.sources.s1.type = spooldir#指定代理中的channela1.sources.s1.channels = c1#本地目录,需要监控的目录,一旦该目录有新的数据写入,就会自动传递a1.sources.s1.spoolDir = /home/wangfutai/a/flume/logsa1.sources.s1.fileHeader = true#channels 类型,使用本地磁盘文件作为缓冲a1.channels.c1.type = file#用于记录消息队列位置a1.channels.c1.checkpointDir = /home/wangfutai/a/flume/checkPoint#数据缓冲原始数据a1.channels.c1.dataDirs = /home/wangfutai/a/flume/dataa1.sinks.k1.type = loggera1.sinks.k1.channel = c12.开启flume 目录agent options: --name,-n指定agent名称 the name of this agent (required) --conf-file,-f 指定配置文件的路径 specify a config file (required if -z missing) --zkConnString,-z specify the ZooKeeper connection to use (required if -f missing) --zkBasePath,-p specify the base path in ZooKeeper for agent configs --no-reload-conf do not reload config file if changed --help,-h display help text命令:flume-ng agent --name a1 --conf-file /home/wangfutai/a/flume/conf/02localDir_local.flu一旦有新的文本,输入到监控目录,此时,flume负责把文本传输到sink指定的位置。每处理一个文本,就会把文本设置成文件名.COMPLETED 表示已经传输完毕在监控目录下,如果文件是隐藏的,隐藏文件不会传输
2.监控一个可执行的进程产生的日志
a1.sources = s1a1.channels=c1a1.sinks=k1a1.sources.s1.type = execa1.sources.s1.command = tail -F /home/wangfutai/a/flume/1.txta1.sources.s1.channels = c1a1.channels = c1a1.channels.c1.type = memory#缓冲 事件个数a1.channels.c1.capacity = 10000传输到sink,一次事件个数a1.channels.c1.transactionCapacity = 10000#阈值百分比a1.channels.c1.byteCapacityBufferPercentage = 20#内存大小a1.channels.c1.byteCapacity = 800000a1.sinks.k1.type = loggera1.sinks.k1.channel = c1测试方式:[wangfutai@wangfutai flume]$ echo "xxxxxxxxxxx">>1.txt[wangfutai@wangfutai flume]$ echo "dddddddddx">>1.txt
测试结果
转载地址:http://pgjxi.baihongyu.com/