首页 > 代码库 > Flume采集Nginx日志到HDFS

Flume采集Nginx日志到HDFS

下载apache-flume-1.7.0-bin.tar.gz,用

tar -zxvf

解压,在/etc/profile文件中增加设置:

export FLUME_HOME=/opt/apache-flume-1.7.0-binexport PATH=$PATH:$FLUME_HOME/bin

修改$FLUME_HOME/conf/下的两个文件,在flume-env.sh中增加JAVA_HOME:

JAVA_HOME=/opt/jdk1.8.0_121

最重要的,修改flume-conf.properties文件:

# 配置Agenta1.sources = r1a1.sinks = k1a1.channels = c1# 配置Sourcea1.sources.r1.type = execa1.sources.r1.channels = c1a1.sources.r1.deserializer.outputCharset = UTF-8# 配置需要监控的日志输出目录a1.sources.r1.command = tail -F /usr/local/nginx/log/access.log# 配置Sinka1.sinks.k1.type = hdfsa1.sinks.k1.channel = c1a1.sinks.k1.hdfs.useLocalTimeStamp = truea1.sinks.k1.hdfs.path = hdfs://master:9000/flume/events/%Y-%ma1.sinks.k1.hdfs.filePrefix = %Y-%m-%d-%Ha1.sinks.k1.hdfs.fileSuffix = .loga1.sinks.k1.hdfs.minBlockReplicas = 1a1.sinks.k1.hdfs.fileType = DataStreama1.sinks.k1.hdfs.writeFormat = Texta1.sinks.k1.hdfs.rollInterval = 86400a1.sinks.k1.hdfs.rollSize = 1000000a1.sinks.k1.hdfs.rollCount = 10000a1.sinks.k1.hdfs.idleTimeout = 0# 配置Channela1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# 将三者连接a1.sources.r1.channel = c1a1.sinks.k1.channel = c1

以上文件设置了Source、Channel和Sink,将Nginx日志中的记录采集到HDFS,运行

flume-ng agent -n a1 -c conf -f $FLUME_HOME/conf/flume-conf.properties

如果没有报错,则安装设置成功了,Nginx中新增加的记录都会被Flume采集,并且存储到HDFS。

Flume采集Nginx日志到HDFS