1.6 定义agent 读取日志存入hdfs

Posted weiyiming007

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1.6 定义agent 读取日志存入hdfs相关的知识,希望对你有一定的参考价值。

一、定义agent,并运行

1、配置文件

#计划
##收集hive的日志,存到hdfs
/opt/cdh-5.3.6/hive-0.13.1-cdh5.3.6/logs/hive.log
命令:tail -f    

source:Exec source 在启动时运行一个给定的Unix命令,并期望该进程在标准输出上不断地生成数据
channel:memory
sink:hdfs    #/user/root/flume/hive-logs/




##准备agent配置文件:flume-tail.conf 如下:

# The configuration file needs to define the sources, 
# the channels and the sinks.

####define agent
a2.sources = r2
a2.channels = c2
a2.sinks = k2

###define sources
a2.sources.r2.type = exec
a2.sources.r2.command = tail -f /opt/cdh-5.3.6/hive-0.13.1-cdh5.3.6/logs/hive.log
a2.sources.r2.shell = /bin/bash -c


###define channel
a2.channels.c2.type = memory
a2.channels.c2.capacity = 1000
a2.channels.c2.transactionCapacity = 100


###define sink
a2.sinks.k2.type = hdfs
a2.sinks.k2.hdfs.path = hdfs://hadoop-senior.ibeifeng.com:8020/user/root/flume/hive-logs/
a2.sinks.k2.hdfs.fileType = DataStream
a2.sinks.k2.hdfs.writeFormat = Text
a2.sinks.k2.hdfs.batchSize = 10


###bind the soures and sink to the channel
a2.sources.r2.channels = c2
a2.sinks.k2.channel = c2


2、运行

##flume开始实时监听抽取
[[email protected] flume-1.5.0-cdh5.3.6]# bin/flume-ng agent -c conf -n a2 -f conf/flume-tail.conf -Dflume.root.logger=DEBUG,console


##此时可以去hive中执行一些命令,产生日志


##hdfs查看,已经抽取到很多文件了
[[email protected] hadoop-2.5.0-cdh5.3.6]# bin/hdfs dfs -ls -R /user/root/flume/hive-logs/
-rw-r--r--   3 root supergroup       1133 2019-05-08 13:43 /user/root/flume/hive-logs/FlumeData.1557294191838
-rw-r--r--   3 root supergroup        534 2019-05-08 13:43 /user/root/flume/hive-logs/FlumeData.1557294191839
-rw-r--r--   3 root supergroup       1056 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160087
-rw-r--r--   3 root supergroup        408 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160088
-rw-r--r--   3 root supergroup       1319 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160089
-rw-r--r--   3 root supergroup        240 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160090
-rw-r--r--   3 root supergroup       1083 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160091
-rw-r--r--   3 root supergroup        255 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160092
-rw-r--r--   3 root supergroup        122 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160093
-rw-r--r--   3 root supergroup        956 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160094
-rw-r--r--   3 root supergroup        515 2019-05-08 13:59 /user/root/flume/hive-logs/FlumeData.1557295160095.tmp


3、当hdfs的架构为HA时

##当hdfs的架构为HA时,define sink字段定义:
a2.sinks.k2.type = hdfs

a2.sinks.k2.hdfs.path = hdfs://代理名:8020/user/root/flume/hive-logs/

把主机名改为HA的代理名称,然后可以直接把core-site.xml   hdfs-site.xml放进flume的conf目录中,让flume读取;

以上是关于1.6 定义agent 读取日志存入hdfs的主要内容,如果未能解决你的问题,请参考以下文章

ELK采集MySQL慢日志实现

flume从kafka读取数据到hdfs中的配置

水槽系统日志代理没有选择消息并将其放入 HDFS

Flume概述

读取日志,将有用信息存入excel

读取日志,将有用信息存入excel