Hive on CDH4部署、调错及测试

环境介绍

hadoop是cdh4.2.0的版本,搭建见十分钟搭建自己的hadoop2/CDH4集群

hive版本可以是cdh4.2.0的hive-0.10.0,下载包(win直接下载解压会失败,建议linux下wget下载)。也可以是hive-0.9.0(shark-0.7包里自带的amp实验室提供的版本)。两个版本我都尝试了,都是可以的,使用后者这个版本比较低的hive的原因是为了使用shark。

metastore则是一个MySQL,只有你有mysql server,随便create 一个 空的database即可。


Hive部署

1. conf下面的hive-default等配置不需要改变,增加hive-site.xml,为其添加如下基本配置

dir相关:

  1. <property>  
  2.   <name>hive.metastore.warehouse.dir</name>  
  3.   <value>/home/mywork/work/data/hive/warehouse-${user.name}</value>  
  4.   <description>location of default database for the warehouse</description>  
  5. </property>  
  6.   
  7. <property>  
  8.   <name>hive.exec.scratchdir</name>  
  9.   <value>/home/mywork/work/data/hive/scratch-${user.name}</value>  
  10.   <description>Scratch space for Hive jobs</description>  
  11. </property>  
  12.   
  13. <property>  
  14.   <name>hive.querylog.location</name>  
  15.   <value>/home/mywork/work/data/querylog-${user.name}</value>  
  16.   <description>  
  17.     Location of Hive run time structured log file  
  18.   </description>  
  19. </property>  
hwi相关:
  1. <property>  
  2.   <name>hive.hwi.listen.host</name>  
  3.   <value>10.65.17.192</value>  
  4.   <description>This is the host address the Hive Web Interface will listen on</description>  
  5. </property>  
  6. <property>  
  7.   <name>hive.hwi.listen.port</name>  
  8.   <value>9999</value>  
  9.   <description>This is the port the Hive Web Interface will listen on</description>  
  10. </property>  
  11. <property>  
  12.   <name>hive.hwi.war.file</name>  
  13.   <value>lib/hive-hwi-0.9.0-amplab-4.war</value>  
  14.   <description>This is the WAR file with the jsp content for Hive Web Interface</description>  
  15. </property>  
jdbc相关:
  1. <property>  
  2.   <name>javax.jdo.option.ConnectionURL</name>  
  3.   <value>jdbc:mysql://xx.xx.xx.com:8306/hive?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8  
  4. </value>  
  5.   <description>JDBC connect string for a JDBC metastore</description>  
  6. </property>  
  7.   
  8. <property>  
  9.   <name>javax.jdo.option.ConnectionDriverName</name>  
  10.   <value>com.mysql.jdbc.Driver</value>  
  11.   <description>Driver class name for a JDBC metastore</description>  
  12. </property>  
  13.   
  14. <property>  
  15.   <name>javax.jdo.option.ConnectionUserName</name>  
  16.   <value>xxxx</value>  
  17.   <description>username to use against metastore database</description>  
  18. </property>  
  19.   
  20. <property>  
  21.   <name>javax.jdo.option.ConnectionPassword</name>  
  22.   <value>xxxx</value>  
  23.   <description>password to use against metastore database</description>  
  24. </property>  
2. 在HIVE_HOME/lib下要添加 mysql-driver

3. HADOOP_HOME如果没有在环境变量里的话,请在conf/hive-env.sh里export

3. 启动hive,可以用bin/hive,但是这样报错无法定位到具体原因,建议使用

  1. ./bin/hive -hiveconf hive.root.logger=DEBUG,console  
启动,特别是初次使用和建立的metastore,会遇到一些问题。


Debug Hive

bin/hive初次启动hive,执行 select tables; 可能会遇到如下错误:

  1. FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient  
  2. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask  
使用下面方式启动hive,
  1. ./bin/hive -hiveconf hive.root.logger=DEBUG,console  
可能会遇到如下问题:

问题一

  1. Transaction level-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'  
解决方法,用mysql登录查看hive的metastore数据库,执行
  1. SET GLOBAL binlog_format = 'ROW';  
参考资料http://stackoverflow.com/questions/9665535/why-do-i-get-binary-logging-not-possible-on-my-mysql-server

问题二

  1. MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes)  
解决方法,执行
  1. alter database hive character set latin1;  
参考资料http://www.cnblogs.com/Blueren/archive/2011/06/29/Sir_001.html

如遇到其他问题,可能多数是和metastore有关,自行查阅之。


Test Hive

启动自己的hadoop dfs和yarn,启动hive,创建表:

  1. create table test(num int, name string);  
如果出错信息为:
  1. Field 'IS_STOREDASSUBDIRECTORIES' doesn't have a default value  
解决方法是去hive库里执行
  1. ALTER TABLE `SDS` ALTER  `IS_STOREDASSUBDIRECTORIES` SET DEFAULT 0;  
然后使用examples目录下提供的一些测试数据和脚本,尝试插入数据:
  1. load data local inpath '/home/mywork/work/hive-0.9.0-bin/examples/files/kv1.txt' into table test;   
kv1-kv6共有六份txt,然后执行
  1. select * from test where num > 400;  
体验下MR过程有多蛮长吧。。

(我最简单对比了下,hive使用了14s,用shark仅1s,后续针对hive vs shark会有专门的博文)


(全文完)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值