本文已参与「新人创作礼」活动,一起开启掘金创作之路。
测试官方例子
# example.conf: A single-node Flume configuration
# Name the components on this agent
a1.sources = r1
#定义sources源的名称
a1.sinks = k1
#定义存储介质的名称
a1.channels = c1
#定义channels通道的名称
# Describe/configure the source
a1.sources.r1.type = netcat
#source类型,监控某个端口,将流经端口的每一个文本行数据作为Event输入
a1.sources.r1.bind = localhost
#监听IP地址
a1.sources.r1.port = 6666
#监听端口
# Describe the sink
a1.sinks.k1.type = logger
#Sink类型是logger,也就是数据是日志类型
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
#channel通道c1类型是内存类型,也就是event数据存储在内存中,然后发送events
a1.channels.c1.capacity = 1000
#存储在通道c1中的事件的最大数量
a1.channels.c1.transactionCapacity = 100
#channel将从一个channel获得的最大事件数量或每次传输给予一个sink的事件数量
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
#选择从channels通道c1来发送events
a1.sinks.k1.channel = c1
#选择从channels通道c1来接收events
启动Flume进程
flume-ng agent -c conf -f /etc/flume/conf/flume-conf.properties.template -n agent
#配置此参数不生效可能与log4j2.xml有关,官网默认是log4j.properties
#-Dflume.root.logger=INFO,console
打开终端进行测试
# telnet localhost 6666
# tail -f /var/log/flume/flume.log
Flume不写日志:
解决方案: - . 在flume的安装下启动,包含Flume配置文件的conf目录。 - . 在执行Flume脚本时的命令行参数时 -c 指定Flume的配置文件的目录。
设置Flume的agent的环境变量
a1.sources.r1.type = netcat
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = ${NC_PORT}
#主要是这里引用了一个变量,注意:它目前仅适用于数值,不适用于按键。
$ NC_PORT=6666 bin/flume-ng agent --conf conf --conf-file conf/flume-conf --name a1 -Dflume.root.logger=INFO,console -DpropertiesImplementation=org.apache.flume.node.EnvVarResolverProperties\
- 通过设置propertiesImplementation = org.apache.flume.node.EnvVarResolverProperties,可以通过代理调用上的Java系统属性启用此功能。
- 环境变量可以用其他方式配置,包括在conf/flume-env.sh中设置。
记录原始数据
记录流经摄取管道的原始数据流在许多生产环境中==不是期望的行为==,因为这可能导致==泄漏敏感数据或安全相关配置==,诸如secret keys,到Flume日志文件。 默认情况下,Flume不会记录这些信息。 另一方面,如果数据管道被破坏,Flume将尝试提供调试问题的线索。 调试事件流水线问题的一种方法是设置一个连接到Logger Sink的额外的Memory Channel,它将输出所有事件数据到Flume日志。 但是在某些情况下,这种方法是不够的。
#为了启用事件和配置相关数据的日志记录,除了log4j属性之外,还必须设置一些Java系统属性。
#要启用配置相关的日志记录,请设置Java系统属性-Dorg.apache.flume.log.printconfig = true。 这可以通过命令行传递,也可以通过在flume-env.sh中的JAVA_OPTS变量中设置。
#要启用数据记录,请按照上述相同的方式设置Java系统属性-Dorg.apache.flume.log.rawdata = true。 对于大多数组件,log4j日志记录级别还必须设置为DEBUG或TRACE,以使特定于事件的日志记录显示在Flume日志中。
#以下是启用配置日志记录和原始数据日志记录的示例,同时还将Log4j日志级别设置为DEBUG以进行控制台输出:
$ NC_PORT=6666 bin/flume-ng agent --conf conf --conf-file conf/flume-conf --name a1 -Dflume.root.logger=DEBUG,console -Dorg.apache.flume.log.printconfig=true -Dorg.apache.flume.log.rawdata=true -DpropertiesImplementation=org.apache.flume.node.EnvVarResolverProperties