用hive+hdfs+sqoop分析日志的步骤
2013-09-17 14:42
225 查看
现在的部分工作是进行日志分析,由于每天的日志压缩前80多G左右,用lzop压缩后10G左右,如果用shell直接进行统计,需要花费很长时间才能完成,而且还需要用java函数对request url进行转换,于是采用hive+hdfs+sqoop方案进行日志统计分析
hadoop+hive+hdfs+sqoop的架构就不详细说了,可以直接用cloudera的repo直接安装
日志分析步骤
一 下载服务器中的日志,因为应用服务使用了多台服务器,所以需要对日志进行合并整理,然后用lzop进行压缩
二 在hive中创建表
[html] view
plaincopyprint?
hive>CREATE TABLE maptile (ipaddress STRING,identity STRING,user STRING,time STRING,method STRING,request STRING,protocol STRING,status STRING,size STRING,referer STRING,agent STRING) ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' WITH SERDEPROPERTIES ("input.regex" = "([^ ]*) ([^ ]*) ([^ ]*) (-|\\[[^\\]]*\\]) (\"[^ ]*) ([^ ]*) ([^ ]*\") (-|[0-9]*) (-|[0-9]*)(?: ([^ \"]*|\".*\") ([^ \"]*|\".*\"))?","output.format.string" = "%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s")STORED AS TEXTFILE;
三 导入日志数据
[html] view
plaincopyprint?
hive>load data local inpath '/home/log/1.lzo' overwrite into table maptile;
四 在hive中创建日志统计后结果表
[html] view
plaincopyprint?
hive>create table result (ip string,num int) partitioned by (dt string);
五 统计日志并将统计结果插入到新表中
[html] view
plaincopyprint?
hive>insert overwrite table result partition (dt='2011-09-22') select ipaddress,count(1) as numrequest from maptile group by ipaddress sort by numrequest desc;
六 将统计结果导出到mysql中
[html] view
plaincopyprint?
sqoop export --connect jdbc:mysql://localhost:3306/result --username root --password admin --table ip_info --export-dir /user/hive/warehouse/result/dt=2011-09-22 --input-fields-terminated-by '\001'
以上步骤可以写入到shell script中设置定时任务自动完成
hadoop+hive+hdfs+sqoop的架构就不详细说了,可以直接用cloudera的repo直接安装
日志分析步骤
一 下载服务器中的日志,因为应用服务使用了多台服务器,所以需要对日志进行合并整理,然后用lzop进行压缩
二 在hive中创建表
[html] view
plaincopyprint?
hive>CREATE TABLE maptile (ipaddress STRING,identity STRING,user STRING,time STRING,method STRING,request STRING,protocol STRING,status STRING,size STRING,referer STRING,agent STRING) ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' WITH SERDEPROPERTIES ("input.regex" = "([^ ]*) ([^ ]*) ([^ ]*) (-|\\[[^\\]]*\\]) (\"[^ ]*) ([^ ]*) ([^ ]*\") (-|[0-9]*) (-|[0-9]*)(?: ([^ \"]*|\".*\") ([^ \"]*|\".*\"))?","output.format.string" = "%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s")STORED AS TEXTFILE;
三 导入日志数据
[html] view
plaincopyprint?
hive>load data local inpath '/home/log/1.lzo' overwrite into table maptile;
四 在hive中创建日志统计后结果表
[html] view
plaincopyprint?
hive>create table result (ip string,num int) partitioned by (dt string);
五 统计日志并将统计结果插入到新表中
[html] view
plaincopyprint?
hive>insert overwrite table result partition (dt='2011-09-22') select ipaddress,count(1) as numrequest from maptile group by ipaddress sort by numrequest desc;
六 将统计结果导出到mysql中
[html] view
plaincopyprint?
sqoop export --connect jdbc:mysql://localhost:3306/result --username root --password admin --table ip_info --export-dir /user/hive/warehouse/result/dt=2011-09-22 --input-fields-terminated-by '\001'
以上步骤可以写入到shell script中设置定时任务自动完成
相关文章推荐
- 用hive+hdfs+sqoop分析日志的步骤
- 用hive+hdfs+sqoop分析日志的步骤(转)
- 用hive+hdfs+sqoop分析日志的步骤
- hadoop日志分析系统二 第二部分利用hadoop平台进行数据处理 第三种方式 hive+sqoop+zookeeper方式
- Flume-NG + HDFS + HIVE 日志收集分析 | EyeLu技术Blog
- Flume-NG + HDFS + HIVE 日志收集分析
- 论坛日志分析:Flume+MapReduce+Hive+Sqoop+MySQL
- 基于Hadoop+Hive+Sqoop+HBase+Zookeeper+MySql日志统计分析项目
- hadoop日志分析系统二 第二部分利用hadoop平台进行数据处理 第三种方式 hive+sqoop+zookeeper方式
- Flume-NG + HDFS + HIVE 日志收集分析
- Flume-NG + HDFS + HIVE 日志收集分析
- hive分析nginx日志之UDF清洗数据
- hive数据仓库框架之日志分析
- 使用Hive的正则解析器RegexSerDe分析nginx日志
- 日志文件分析工具—AWStats在IIS中的配置步骤
- Hadoop分析日志实例的详细步骤及出现的问题分析和解决
- 十九、Hive日志分析案例一
- hadoop日志【1】--hive服务和sqoop服务运行
- 日志文件分析工具—AWStats在IIS中的配置步骤
- Flume + HDFS + Hive日志收集系统