#Enviroment variables can be set here.
export JAVA_HOME=/opt/jdk1.8.0_11
bin/flume-ng
global options:
--conf,-c <conf> use configs in <conf> directory
-Dproperty=value sets a Java system property value
agent options:
--name,-n <name> the name of this agent (required)
--conf-file,-f <file> specify a config file (required if -z missing)
我们需要自己编写agent,具体属性查看官网点击打开链接
收集log
hive的日志
/opt/cdh-5.5.0/hive-1.1.0-cdh5.5.0/logs/hive.log
source: exec可执行方式 如命令 "tail -f"进行读取
channel: memory channel缓存到内存
sink: HDFS sink 存到HDFS中 /user/bpf/flume/hive_logs/
编写agent
# define agent
a2.sources = r2
a2.channels = c2
a2.sinks = k2
# definde sources
a2.sources.r2.type = exec
a2.sources.r2.command = tail -f /opt/cdh-5.5.0/hive-1.1.0-cdh5.5.0/logs/hive.log
a2.sources.r2.shell = /bin/bash -c
# define channels
a2.channels.c2.type = memory
a2.channels.c2.capacity = 1000
a2.channels.c2.transactionCapacity = 100
# define sinks
a2.sinks.k2.type = hdfs
a2.sinks.k2.hdfs.path = hdfs://BPF:9000/user/bpf/flume/hive_logs/
a2.sinks.k2.hdfs.fileType = DataStream
a2.sinks.k2.hdfs.writeFormat = Text
a2.sinks.k2.hdfs.batchSize = 10
# bind channels to sources and sinks
a2.sources.r2.channels = c2
a2.sinks.k2.channel = c2
bin/flume-ng agent \
-c conf \
-n a2 \
-f conf/flume-hive_tail.conf \
-Dflume.root.logger=DEBUG,console
简单介绍一下spooling directory source
a3.sources = r3
a3.channels = c3
a3.sinks = k3
a3.sources.r3.type = spooldir
a3.sources.r3.ignorePattern = ^(.)*\\.log$ #正则表达式,该属性意思为忽略后缀为.log的文件
a3.sources.r3.spoolDir = /opt/cdh-5.5.0/flume-1.6.0-cdh5.5.0/spool_logs
a3.sources.r3.fileSuffix = .finish #文件一旦被监控收集,原文件就会加一个.finish后缀
a3.channels.c3.type = file
#下面这两个文件夹自己创建
a3.channels.c3.checkpointDir = /opt/cdh-5.5.0/flume-1.6.0-cdh5.5.0/filechannel/chkpoint
a3.channels.c3.dataDirs = /opt/cdh-5.5.0/flume-1.6.0-cdh5.5.0/filechannel/data
a3.sinks.k3.type = hdfs
#下面两条属性可以自动按照当前日期(年月日)生成子目录
a3.sinks.k3.hdfs.useLocalTimeStamp = true
a3.sinks.k3.hdfs.path = hdfs://BPF:9000/user/bpf/flume/spooling_logs/%Y%m%d
#
a3.sinks.k3.hdfs.hdfs.fileType = DataStream
a3.sinks.k3.hdfs.writeFormat = Text
a3.sinks.k3.hdfs.batchSize = 10
a3.sources.r3.channels = c3
a3.sinks.k3.channel = c3
bin/flume-ng agent \
-c conf \
-n a3 \
-f conf/flume-app.conf \
-Dflume.root.logger=DEBUG,console