Flume的简单实践
Flume的实践,主要分为以下几个步骤。
1 配置并启动Flume agent
cd $FLUME_HOME
# 通过nohup守护进程的方式启动agent
nohup bin/flume-ng agent -n a1 -c conf -f conf/flume-conf.properties &
# 查看进程
jps
69178 Application 启动了一个java进程
2 配置好source sink channel
cd $FLUME_HOME
mkdir jobs
cd jobs
# 配置组件信息
vim log_to_console.conf
# 为这个agent中的组件命名
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 描述并配置source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /Users/shufang/logs/pdman/runtime.2020-06-17.0.log
# 配置sink
a1.sinks.k1.type = logger
# 配置channel信息,用来缓存从source接收到的数据
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# 将不同的组件通过配置组合到一起
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
3 开启数据采集
bin/flume-ng agent
--conf conf # 这个是指定所有的flume的配置文件路径
--conf-file jobs/log_to_console.conf # 这是配置的flume的任务的配置文件,以.conf结尾
--name a1 # 这个agent的信息必须与启动的agent的名字保持一致
-Dflume.root.logger=INFO,console # JMX信息
# 常用的日志配置还有,这些配置可以在shell中指定,也可以在flume-env.sh中指定JAVA_OPTS
-Dorg.apache.flume.log.printconfig = true
-Dorg.apache.flume.log.rawdata = true
往日志文件中不断得追加信息。
echo "helloworld" >> /Users/shufang/logs/pdman/runtime.2020-06-17.0.log
控制台的日志打印结果如下。
.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 68 65 6C 6C 6F 77 6F 72 6C 64 helloworld }
2020-06-20 13:46:24,761 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 68 65 6C 6C 6F 77 6F 72 6C 64 helloworld }