之前一篇文章介绍了使用MapReduce分析Web日志的过程。本文继续在原来的基础上,利用HBase来处理Web日志。
1、Web日志分析
Web日志中,每条日志都代表用户的一次访问行为,以下面的一条日志为例子:
60.208.6.156 - - [18/Sep/2013:06:49:48 +0000] "GET /wp-content/uploads/2013/07/rcassandra.png HTTP/1.0" 200 185524 "http://cos.name/category/software/packages/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36"每条日志都有用户IP,访问时间,访问页面信息等等。
2、读取日志文件,将其存入HBase
代码实现:
public static void main(String args[]) throws IOException, ClassNotFoundException, InterruptedException
{
/* read data from file ,write in HBase */
String strRowKey = "";
String strIP = "";
String strURL = "";
String fileName = args[0];
Configuration conf = HBaseConfiguration.create();
HTable