环境:centos7+hadoop2.5.2+hive1.2.1+mysql5.6.22+indigo service 2
思路:hive加载日志→hadoop分布式执行→需求数据进入mysql
注意:hadoop日志分析系统网上资料很多,但是大多都有写小问题,无法顺利运行,但本文中都是经过亲自验证的,可以一气呵成。另外还包括可能遇到的异常的详细解释及相关解决方案。
1) 日志格式分析
首先分析 Hadoop 的日志格式, 此种日志格式是最简单的,一行一条, 日志格式可以依次描述为:日期、时间、类别、相关类和提示信息。如下所示:
2) hive存储表设计
rdate Time type rclass infor1 Infor2 Infor3
string array string string string string string
3) hive表定义
create table if not exists loginfo(
rdate string,
time array<string>,
type string,
relateclass string,
information1 string,
information2 string,
information3 string)
row format delimited fields terminated by ' '
collection items terminated by ','
map keys terminated by ':';
4) mysql表定义
drop table if exists hadooplog;
create table hadooplog(
id int(11) not null auto_increment,
rdate varchar(50) null,
time varchar(50) default null,
type varchar(50) default null,
relateclass tinytext default null,
information longtext default null,
primary key (id)
) engine=innodb default charset=utf8;
5) mysql数据库操作
[root@master /]# cd /usr/bin
[root@master bin]# service mysql start
Starting MySQL SUCCESS!
[root@master bin]# mysql -uroot –p
mysql> create database hive;
Query OK, 1 row affected (0.03 sec)
mysql> use hive
Database changed
mysql> source /usr/local/mysql/sql/hadooplog.sql
Query OK, 0 rows affected, 1 warning (0.05 sec)
Query OK, 0 rows affected (0.18 sec)
mysql> desc hadooplog;
6) DBHelper: 负责建立与 Hive 和 MySQL 的连接
package com.smq.hive;
impo