也是初识,陆续的看了几篇文档懵懵懂懂的做了个实验
一共三台机器 一台master 两台slave
hive 安装在master 上(安装方法待整理)
同时也需要安装mysql
修改hive的conf目录下的hive-site.xml
增加
<property> <name>hive.aux.jars.path</name> <value>file:///opt/hive/lib/hive-contrib-0.10.0.jar</value> </property>
file:///opt/hive/lib/hive-contrib-0.10.0.jar 这个为我的安装目录,如果你的hive 不是这个版本那么请找hive-contrib 开头的.jar 文件
然后开始创建数据库表,#hive 进入 hive模式下 输入以下SQL语句
hive> CREATE TABLE apachelog (ipaddress STRING,identity STRING,user STRING,time 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")STORED AS TEXTFILE;
如果出现错误,请先确定你的mysql 是否已经启动 或者 你的hive 已经配置好mysql
执行完毕 创建表语句后 我们可以 执行 show tables 命令来查看我们刚创建的表
最后我们导入要分析的日志文件
hive>load data local inpath '/home/log/map.gz' overwrite into table apachelog;
导入完毕后 可以执行 select * from apachelog limit 10 ; 来查看前十条数据
记录的粗糙 希望能帮助到大家,新手共同学习中……