一.flume安裝及配置
-
安裝flume
上传解压
2.修改配置文件
[hadoop@gboss03 conf]# cp flume-env.sh.template flume-env.sh
export JAVA_HOME=/app/hadoop/jdk1.8.0_141
3.修改flume.conf文件
在conf下创建一个flume.conf
[hadoop@gboss03 conf]# ls
flume.conf flume-env.ps1.template log4j.properties
flume-conf.properties.template flume-env.sh.template
[hadoop@gboss03 conf]#
修改內容
# 指定Agent的组件名称
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 指定Flume source(要监听的路径)
a1.sources.r1.type = spooldir
#先创建这个目录
a1.sources.r1.spoolDir =/app/Hadoop/cpj/data/logs
# 指定Flume sink
a1.sinks.k1.type = logger
# 指定Flume channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# 绑定source和sink到channel上
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
啓動flume agnet
[hadoop@gboss03 apache-flume-1.8.0-bin]#flume-ng agent --conf conf --conf-file conf/flume.conf --name a1 -Dflume.root.logger=INFO,console
向log中寫入數據
[hadoop@gboss03 logs]# vi 1.log
1,xiaoming
2,xiaohong
把日志文件寫入flume監控的目錄中
[hadoop@gboss03 data]# cd logs
[ hadoop@gboss03 logs]# vi 1.log
[hadoop@gboss03 logs]# cp 1.log logs/
[hadoop@gboss03 logs]#
到開啓flume 的總端查看
- org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 31 2C 78 69 61 6F 6D 69 6E 67 1,xiaoming }
2018-07-10 11:05:17,225 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 32 2C 78 69 61 6F 68 6F 6E 67 2,xiaohong }
监控目录
对指定目录进行实时监控,如发现目录新增文件,立刻收集并发送
缺点:不能对目录文件进行修改,如果有追加内容的文本文件,不允许,
监控文件
对文件实时监控,如果发现文件有新日志,立刻收集并发送,通过sink进行入库收集。
缺点:如果中断,不会记录文件的当前收集状态,重启后只会收集新的日志,会造成数据丢失。但速度快些
- 寫conf文件,a.conf
# 指定Agent的组件名称
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 指定Flume source(要监听的路径)
#指定文件类型
a1.sources.r1.type = exec
#指定文件
a1.sources.r1.command = tail -F /app/Hadoop/cpj/data/logs/a.log
# 指定Flume sink
a1.sinks.k1.type = logger
# 指定Flume channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# 绑定source和sink到channel上
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
-啓動
bin/flume-ng agent --conf conf --conf-file conf/a.conf --name a1 -Dflume.root.logger=INFO,console
网友评论