后端需要安装
cd /usr/local/nginx/
- 启动nginx
sbin/nginx -c conf/nginx.conf - 通过浏览器访问nginx 。比如192.168.xxx.xxx
- 观察自定义日志采集文件是否有对应的内容输出
tail -f logs/user_defined.log
前端需要安装
- 安装轻量级的web服务器apache server(httpd)
yum install -y httpd
flume采集
-
以前使用exec监控文件 spooldir监控文件夹
-
flume 新source taildir
-
监控一个文件的变化 此时相当于exec source :tail -f xxx
-
监控一个文件夹下文件的变化,并且支持正则匹配 此时相当于spooldir source
-
支持断点续传功能 通过文件记录上传的位置 待重启或者出现故障的时候 可以继续工作
-
启动(需要改一改netcat-logger.conf监控的文件)
bin/flume-ng agent -c conf -f conf/netcat-logger.conf -n a1 -Dflume.root.logger=INFO,console
配置文件编写:
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 三个文件的具体描述
a1.sources.r1.type = TAILDIR
#断点续传
a1.sources.r1.positionFile = /weblog/flume/taildir_position.json
a1.sources.r1.filegroups = f1 f2
a1.sources.r1.filegroups.f1 = /weblog/test1/example.log
a1.sources.r1.filegroups.f2 = /weblog/test2/.*log.*
# 数据采集
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = /weblog/%y-%m-%d/%H-%M/
#文件名的前缀
a1.sinks.k1.hdfs.filePrefix = jiamin-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute
#下面三个条件谁先满足谁先触发
a1.sinks.k1.hdfs.rollInterval = 0
a1.sinks.k1.hdfs.rollSize = 134217728
a1.sinks.k1.hdfs.rollCount = 0
a1.sinks.k1.hdfs.batchSize = 1
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#生成的文件类型,默认是Sequencefile,可用DataStream,则为普通文本
a1.sinks.k1.hdfs.fileType = DataStream
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
数据预处理
在正式处理数据之前对收集的数据进行预先处理的操作。
- 原因:不管通过何种手段收集的数据 往往是不利于直接分析的 数据中存在的格式规整的差异。
- 目的:把不干净的数据 格式不规则的数据 通过预处理清洗变成格式统一规整的结构化数据
- 技术:MapReduce
- 预处理的编程思路问题
- 在使用mr编程的过程中 牢牢把握住key是什么。因为mr中key有很多默认的属性。
分区---->key哈希 % reducetasknums
分组---->key相同分为一组
排序---->按照key的字典序排序
- MapReduce编程技巧
- 涉及多属性数据传递 通常采用建立javabean携带数据 并且需要实现hadoop的序列化机制 Writable
- 有意识的重写对象toString方法 并且以\001进行字段 的分割,便于后续的数据入库操作
- 针对本次分析无效的数据 通过采用建立标记位的形式进行逻辑删除
- 点击流模型
- 点击流(Click Stream)是指用户在网站上持续访问的轨迹。
- 点击流是从用户的角度出发,注重用户浏览网站的整个流程;而网站日志是面向整个站点,它包含了用户行为数据、服务器响应数据等众多日志信息,我们通过对网站日志的分析可以获得用户的点击流数据。
编程: