hadoop平台进行小型网站的日志分析

本文详细介绍了如何使用Flume将日志文件从Linux上传输到HDFS,然后通过创建Hive表对数据进行结构化存储与管理。接着,脚本会自动清理数据,并按照日期分区,以便于后续的分析。最后,利用Hive进行数据查询与统计,包括每日PV、点击次数超过20的潜在用户、UV以及注册人数,同时将数据导出至MySQL数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载连接

0.上传日志文件到linux中,通过flume将文件收集到hdfs中。
执行命令/home/cloud/flume/bin/flume-ng agent -n a4 -c conf -f /home/cloud/flume/conf/a4.conf -Dflume.root.logger=DEBUG,console


1.建立hive表
create external table bbslog (ip string,logtime string,url string) partitioned by (logdate string) row format delimited fields terminated by '\t' location '/cleaned';


2.创建shell脚本
touch daily.sh
添加执行权限
chmod +x daily.sh
daily.sh:
CURRENT=`date +%Y%m%d`
#对数据进行清理,保存到cleaned文件夹,按照当前日期进行保存
/home/cloud/hadoop/bin/hadoop jar /home/cloud/cleaner.jar /flume/$CURRENT /cleaned/$CURRENT
#修改hive表,添加当前日期的分区
/home/cloud/hive/bin/hive -e "alter table bbslog add partition (logdate=$CURRENT) location 'cleaned/$CURRENT'"
#使用hive进行分析,根据业务需求而定
#统计pv并计入每日的pv表
/home/cloud/hive/bin/hive -e "create table pv_$CURRENT row format delimited fields terminated by '\t' as select count(*) from bbslog where logdate=$CURRENT;"
#统计点击次数过20的潜在用户
/home/cloud/hive/bin/hive -e "create table vip _$CURRENT row format delimited fields terminated by '\t' as select $CURRENT,ip,count(*) as hits from bbslog where logdate=$CURRENT group by ip having hits > 20 order by hits desc"
#查询uv
/home/cloud/hive/bin/hive -e "create table uv_$CURRENT row format delimited fields terminated by '\t' as select count(distinct ip) from bbslog where logdate=$CURRENT"
#查询每天的注册人数
/home/cloud/hive/bin/hive -e "create table reg_$CURRENT row format delimited fields terminated by '\t' as select count(*) from bbslog where logdate=$CURRENT AND instr(url,'member.php?mod=register')>0"
#将hive表中的数据导入mysql
/home/cloud/sqoop/bin/sqoop export --connect jdbc:mysql://cloud3:3306/jchubby --username root --password JChubby123 --export-dir "/user/hive/warehouse/vip_$CURRENT" --table vip --fields-terminated-by '\t' 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值