官方文档(中文)
Flume 1.9用户手册中文版 — 可能是目前翻译最完整的版本了
官方文档(英文)
1、netcat- logger
安装telnet工具
sudo yum install telnet-server.x86_64 -y
sudo yum install telnet -y
sudo rpm -qa telnet-server
判断44444端口是否被占用
sudo netstat -tunlp | grep 44444
在/usr/local/soft/apache-flume-1.9.0-bin/conf/目录下创建flume-telnet-logger.properties文件,内容如下
# 指定agent的名字为a1
# 指定a1的sources为r1
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
# netcat用来监听指定端口号的数据
a1.sources.r1.type = netcat
# 监听localhost的44444端口
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
# Describe the sink,日志方式
a1.sinks.k1.type = logger
# 指定数据放到channel的内存中
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
执行
cd /usr/local/soft/apache-flume-1.9.0-bin/conf/
flume-ng agent -n a1 -c conf -f flume-telnet-logger.properties -Dflume.root.logger=DEBUG,console
另起一个控制台,使用telnet工具向本机的44444端口发送内容
telnet localhost 44444
2、spooldir-logger
创建文件flume-spooldir-logger.properties
#分别指定agent的sources,sinks, channels的名称 名称可以自定义 a1.sources = s1 a1.sinks = k1 a1.channels = c1 #配置目录scource a1.sources.s1.type =spooldir a1.sources.s1.spoolDir =/usr/local/logs a1.sources.s1.fileHeader= true a1.sources.s1.channels =c1 #配置sink a1.sinks.k1.type = logger a1.sinks.k1.channel = c1 #配置channel(内存做缓存) a1.channels.c1.type = memory
启动
cd /usr/local/soft/apache-flume-1.9.0-bin/conf/ flume-ng agent -n a1 -c conf -f flume-spooldir-logger.properties -Dflume.root.logger=DEBUG,console
3、taildir-logger
taildir:可实时监控一批文件,并记录每个文件最新消费位置,agent进程重启后不会有重复消费的问题。
在/usr/local/soft/apache-flume-1.9.0-bin创建log文件夹,并在log中创建taildir_position.json文件
创建文件flume-taildir-logger.properties
#agent_name a1.sources=r1 a1.sinks=k1 a1.channels=c1 #source的配置 # source类型 a1.sources.r1.type = TAILDIR # 元数据位置 a1.sources.r1.positionFile = /usr/local/soft/apache-flume-1.9.0-bin/log/taildir_position.json # 监控的目录 a1.sources.r1.filegroups = f1 a1.sources.r1.filegroups.f1=/usr/local/data/.*log a1.sources.r1.fileHeader = true #sink的配置 a1.sinks.k1.type = logger #channel的配置 a1.channels.c1.type = memory a1.channels.c1.capacity = 10000 a1.channels.c1.transactionCapacity = 100 #用channel链接source和sink a1.sources.r1.channels = c1 a1.sinks.k1.channel =c1
启动
cd /usr/local/soft/apache-flume-1.9.0-bin/conf/ flume-ng agent -n a1 -c conf -f flume-taildir-logger.properties -Dflume.root.logger=DEBUG,console
在/usr/local/data/路径下分别创建demo.log、demo1.log,然后添加内容,查看shell界面输出