#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