一、数据仓库架构
二、flume收集数据存储到hdfs
文档:http://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html#hdfs-sink
三、监控日志目录日志数据,实时抽取之hdfs系统上-实验
1、Source:Spooling Directory
在使用exec来监听数据源虽然实时性较高,但是可靠性较差,当source程序运行异常或者Linux命令中断都会造成数据丢失,
在恢复正常运行之前数据的完整性无法得到保障。
Spooling Directory Paths通过监听某个目录下的新增文件,并将文件的内容读取出来,实现日志信息的收集。实际生产中会结合log4j来使用。
被传输结束的文件会修改后缀名,添加.COMPLETED后缀(可修改)。
2、
监控目录
>日志目录,抽取完整的日志文件,写的日志文件不抽取
使用FileChannel
>本地文件系统缓冲,比内存安全性更高
数据存储HDFS
>存储对应hive表的目录或者hdfs目录
3、配置flume agent
##agent 配置文件:flume-app.conf 如下:
# The configuration file needs to define the sources,
# the channels and the sinks.
####define agent
a3.sources = r3
a3.channels = c3
a3.sinks = k3
###define sources
a3.sources.r3.type = spooldir
a3.sources.r3.spoolDir = /opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/spoollogs
a3.sources.r3.ignorePattern = ^(.)*\.log$
a3.sources.r3.fileSuffix = .delete
###define channel
a3.channels.c3.type = file
a3.channels.c3.checkpointDir = /opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/filechannel/checkpoint
a3.channels.c3.dataDirs = /opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/filechannel/data
###define sink
a3.sinks.k3.type = hdfs
a3.sinks.k3.hdfs.path = hdfs://hadoop-senior.ibeifeng.com:8020/user/root/flume/splogs/
a3.sinks.k3.hdfs.fileType = DataStream
a3.sinks.k3.hdfs.writeFormat = Text
a3.sinks.k3.hdfs.batchSize = 10
###bind the soures and sink to the channel
a3.sources.r3.channels = c3
a3.sinks.k3.channel = c3
对agent配置文件的解释:
##define sources字段:
type : spooldir //通过监听某个目录下的新增文件,并将文件的内容读取出来,实现日志信息的收集
spoolDir //从哪个目录中读取数据
ignorePattern //排除哪些文件,用正则匹配
fileSuffix //给读取完的文件,加上一个后缀名
##define channel
type = file //channel存到文件中,而不是内存,这样不易丢失数据
checkpointDir //存储检查点文件的存放目录
dataDirs //逗号分隔的目录列表,用于存储日志文件。在单独的磁盘上使用多个目录可以提高文件通道的性能
##define sink
type = hdfs //抽取完的数据存到hdfs上
hdfs.path //在hdfs上的存储路径
hdfs.fileType //hdfs上的存储的文件格式,DataStream不会压缩输出文件
writeFormat //序列文件记录的格式,应该设置为Text,否则这些文件不能被Apache Impala(孵化)或Apache Hive读取
batchSize //number of events written to file before it is flushed to HDFS
4、运行agent
##先准备一些数据
mkdir -p /opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/spoollogs #创建待抽取数据存放目录
[root@hadoop-senior spoollogs]# ls #准备三个数据文件
emp.txt hivef.log hivef.sql
mkdir -p /opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/filechannel/{checkpoint,data} #创建channel数据存放目录
bin/hdfs dfs -mkdir -p /user/root/flume/splogs/ #在hdfs上创建此目录
##运行agent
bin/flume-ng agent \
-c conf \
-n a3 \
-f conf/flume-app.conf \
-Dflume.root.logger=DEBUG,console
##此时查看/opt/cdh-5.3.6/flume-1.5.0-cdh5.3.6/spoollogs中的数据,emp.txt hivef.sql后缀加上了.delete
##hivef.log没有加后缀,因为我们排除了.log的文件
[root@hadoop-senior spoollogs]# ls
emp.txt.delete hivef.log hivef.sql.delete
##查看hdfs上有没有数据,已经有了
[root@hadoop-senior hadoop-2.5.0-cdh5.3.6]# bin/hdfs dfs -ls -R /user/root/flume/splogs/
-rw-r--r-- 3 root supergroup 463 2019-05-09 09:37 /user/root/flume/splogs/FlumeData.1557365835585
-rw-r--r-- 3 root supergroup 228 2019-05-09 09:37 /user/root/flume/splogs/FlumeData.1557365835586
© 著作权归作者所有
发表评论