hive安装
刚刚安装好hadoop迫不及待要玩下hive,所以自己找了些资料,安装了下hive,这里记录详细的安装过程和碰到的问题:
1.在安装hadoop之前首先确定hadoop已经安装成功,具体安装方法请参考hadoop安装。
2.下载hive版本 我下载的是
下载地址为http://hive.apache.org/releases.htm
解压文件:
- tar -zxvf hive-0.7.0-bin.tar.gz
- tar -zxvf hive-0.7.0-bin.tar.gz
3.配置环境变量:
- [root@localhost hive]# vim /etc/profile
- [root@localhost hive]# vim /etc/profile
- export HADOOP_HOME=/root/hadoop-0.20.2
- export PATH=$PATH:$HADOOP_HOME/bin
- export HIVE_HOME=/usr/hive/hive-0.7.0-bin
- PATH=$PATH:$HIVE_HOME/bin
- export PATH
- export JAVA_HOME=/usr/java/jdk1.7.0_01
- export HADOOP_HOME=/root/hadoop-0.20.2
- export PATH=$PATH:$HADOOP_HOME/bin
- export HIVE_HOME=/usr/hive/hive-0.7.0-bin
- PATH=$PATH:$HIVE_HOME/bin
- export PATH
- export JAVA_HOME=/usr/java/jdk1.7.0_01
4.我存储元数据是采用第三方的mysql数据库,这种情况下需要下载一个数据包mysql-connector-java-5.1.18-bin.jar,放到hive的lib目录下;
为Hive建立相应的MySQL账户,并赋予足够的权限,执行命令如下:
hadoop@ubuntu:~$ mysql -u root -pmysql mysql> CREATE USER 'hive' IDENTIFIED BY 'mysql'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' WITH GRANT OPTION; mysql> flush privileges;
5,0.8.1的hive版本忽略hive-default.xml,因此需要将hive/conf下的hive-default.xml.template复制并改名为hive-site.xml。并将hive-site.xml复制到hadoop/conf下
修改hive-site.xml中的如下几项:
<configuration> <property> <name>hive.metastore.local</name> <value>true</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/metastore_db?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123456</value> </property>
5.运行hive
- [root@localhost conf]# hive
- Hive history file=/tmp/root/hive_job_log_root_201112061510_1145168119.txt
- hive> show tables;
- OK
- log
- log_info
- log_new
- maptile
- result
- Time taken: 2.889 seconds
- hive>
- [root@localhost conf]# hive
- Hive history file=/tmp/root/hive_job_log_root_201112061510_1145168119.txt
- hive> show tables;
- OK
- log
- log_info
- log_new
- maptile
- result
- Time taken: 2.889 seconds
- hive>
6.这里遇到点问题:刚开始执行hive时,执行show tables;报如下错误:
- FAILED: Hive Internal Error: java.lang.RuntimeException(Error while making MR scratch directory - check filesystem config (null))
- java.lang.RuntimeException: Error while making MR scratch directory - check filesystem config (null)
- FAILED: Hive Internal Error: java.lang.RuntimeException(Error while making MR scratch directory - check filesystem config (null))
- java.lang.RuntimeException: Error while making MR scratch directory - check filesystem config (null)
后来询问了google,得到如下解决办法:
原有的hadoop配置文件core-site.xml信息如下:
- <pre name="code" class="plain"><!-- Put site-specific property overrides in this file. -->
- <configuration>
- <property>
- <name>hadoop.tmp.dir</name>
- <value>/hadoop-root/tmp</value>
- </property>
- <property>
- <name>fs.default.name</name>
- <value>hdfs://192.168.30.149:9000/</value>
- </property>
- </configuration>
- <pre name="code" class="plain"><!-- Put site-specific property overrides in this file. -->
- <configuration>
- <property>
- <name>hadoop.tmp.dir</name>
- <value>/hadoop-root/tmp</value>
- </property>
- <property>
- <name>fs.default.name</name>
- <value>hdfs://192.168.30.149:9000/</value>
- </property>
- </configuration>
改成:
- <!-- Put site-specific property overrides in this file. -->
- <configuration>
- <property>
- <name>hadoop.tmp.dir</name>
- <value>/hadoop-root/tmp</value>
- </property>
- <property>
- <name>fs.default.name</name>
- <value>hdfs://hadoop149:9000/</value>
- </property>
- </configuration>
- <!-- Put site-specific property overrides in this file. -->
- <configuration>
- <property>
- <name>hadoop.tmp.dir</name>
- <value>/hadoop-root/tmp</value>
- </property>
- <property>
- <name>fs.default.name</name>
- <value>hdfs://hadoop149:9000/</value>
- </property>
- </configuration>
重启hadoop,运行hive,问题解决。
之后创建表一直很顺利,但是到查询表例如我执行:select size from log limit 10;时,又报错如下:
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hive/conf/HiveConf
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hive/conf/HiveConf
后来问了下百度和google都没有结果,自己觉得是缺少了类文件,我便把hive/lib下所有的hive-*文件拷贝到hadoop的lib下
重启hadoop,问题解决。但是归根结底我觉得是$HADOOP_CLASSPATH变量没有配置清楚,这个之后再解决这里做个标记。
执行select 后运行正常:
- hive> select size from log_info limit 12;
- Total MapReduce jobs = 1
- Launching Job 1 out of 1
- Number of reduce tasks is set to 0 since there's no reduce operator
- Starting Job = job_201112061127_0004, Tracking URL = http://hadoop149:50030/jobdetails.jsp?jobid=job_201112061127_0004
- Kill Command = /root/hadoop-0.20.2/bin/hadoop job -Dmapred.job.tracker=hdfs://192.168.30.149:9004 -kill job_201112061127_0004
- 2011-12-06 15:35:47,923 Stage-1 map = 0%, reduce = 0%
- 2011-12-06 15:35:50,952 Stage-1 map = 9%, reduce = 0%
- 2011-12-06 15:35:52,975 Stage-1 map = 27%, reduce = 0%
- 2011-12-06 15:35:53,984 Stage-1 map = 45%, reduce = 0%
- 2011-12-06 15:35:56,001 Stage-1 map = 64%, reduce = 0%
- 2011-12-06 15:35:59,023 Stage-1 map = 82%, reduce = 0%
- 2011-12-06 15:36:00,038 Stage-1 map = 100%, reduce = 0%
- 2011-12-06 15:36:03,062 Stage-1 map = 100%, reduce = 100%
- Ended Job = job_201112061127_0004
- hive> select size from log_info limit 12;
- Total MapReduce jobs = 1
- Launching Job 1 out of 1
- Number of reduce tasks is set to 0 since there's no reduce operator
- Starting Job = job_201112061127_0004, Tracking URL = http://hadoop149:50030/jobdetails.jsp?jobid=job_201112061127_0004
- Kill Command = /root/hadoop-0.20.2/bin/hadoop job -Dmapred.job.tracker=hdfs://192.168.30.149:9004 -kill job_201112061127_0004
- 2011-12-06 15:35:47,923 Stage-1 map = 0%, reduce = 0%
- 2011-12-06 15:35:50,952 Stage-1 map = 9%, reduce = 0%
- 2011-12-06 15:35:52,975 Stage-1 map = 27%, reduce = 0%
- 2011-12-06 15:35:53,984 Stage-1 map = 45%, reduce = 0%
- 2011-12-06 15:35:56,001 Stage-1 map = 64%, reduce = 0%
- 2011-12-06 15:35:59,023 Stage-1 map = 82%, reduce = 0%
- 2011-12-06 15:36:00,038 Stage-1 map = 100%, reduce = 0%
- 2011-12-06 15:36:03,062 Stage-1 map = 100%, reduce = 100%
- Ended Job = job_201112061127_0004
现在又找到的心得问题:在执行删除表操作时,出现如下错误:
- NestedThrowables:
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes
- FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
- NestedThrowables:
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes
- FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
这个问题还没有解决:期待牛人解决
另外两点需要注意:
hive是做为客户端被安装的,调用了hadoop的脚本,有两点需要注意:
(1)问题1:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hive/conf/HiveConf
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
解决方法:在hadoop-env.sh中增加以下脚本
#import hive jar for LIB in `ls -1 $HIVE_HOME/lib/*.jar ./lib/*.zip 2>/dev/null` do HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$LIB done
加载所有hive/lib下的jar包
(2)问题:所有配置都设置好了,Hive就是无法连接到mysql:郁闷的不得了:
解决方法如下:
将hive-site.xml、hive-env.sh.template、hive-exec-log4j.properties、hive-log4j.properties配置文件
拷贝到{Hadoop_Home}/conf下