一、环境准备:
操作系统:Ubuntu 14.04.1 x86_64
hadoop:hadoop-2.7.6
下载链接:https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-2.7.6/
hive:apache-hive-2.3.3
下载链接:https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.3/
使用账户:learn_hadoop
二、hadoop配置
在/home/learn_hadoop下创建目录/home/learn_hadoop/hadoop,将下载的安装包hadoop-2.7.6.tar.gz保存在该目录下,执行如下操作解压安装包:
learn_hadoop@localhost:~$ cd ~/hadoop/
learn_hadoop@localhost:~/hadoop$ tar xvf hadoop-2.7.6
配置hadoop环境变量,vim ~/.bashrc,在文件末尾添加如下内容并保存:
export HADOOP_HOME=/home/learn_hadoop/hadoop/hadoop-2.7.6
export PATH=$PATH:/home/learn_hadoop/hadoop/hadoop-2.7.6/bin
export CLASSPATH=$CLASSPATH:/home/learn_hadoop/hadoop/hadoop-2.7.6/lib/*:.
export CLASSPATH=$CLASSPATH:/home/learn_hadoop/apache-hive-2.3.3-bin/hive/lib/*:.
由于本文介绍的是本地模式,所以hadoop暂时不需要修改配置文件。
三、hive配置
在/home/learn_hadoop下创建目录/home/learn_hadoop/hive,将下载的安装包apache-hive-2.3.3-bin.tar.gz保存在该目录下,执行如下操作解压安装包:
learn_hadoop@localhost:~$ cd ~/hive/
learn_hadoop@localhost:~/hadoop$ tar xvf apache-hive-2.3.3-bin.tar.gz
配置hadoop环境变量,vim ~/.bashrc,在文件末尾添加如下内容并保存:export HIVE_HOME=/home/learn_hadoop/hive/apache-hive-2.3.3-bin
export PATH=$PATH:/home/learn_hadoop/hive/apache-hive-2.3.3-bin/bin
设置好环境变量之后,使用source ~/.bashrc使环境变量生效。
接下来,需要修改hive的配置文件:
learn_hadoop@localhost:~$ cd ~/hive/apache-hive-2.3.3-bin/conf/
learn_hadoop@localhost:~/hive/apache-hive-2.3.3-bin/conf$ cp hive-default.xml.template hive-site.xml
修改hive-site.xml:vim hive-site.xml,修改如下内容并保存:
<property>
<name>hive.exec.local.scratchdir</name>
- <value>${system:java.io.tmpdir}/${system:user.name}</value>
+ <value>/home/learn_hadoop/hive/iotmp</value>
<description>Local scratch space for Hive jobs</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
- <value>${system:java.io.tmpdir}/${hive.session.id}_resources</value>
+ <value>/home/learn_hadoop/hive/iotmp</value>
<description>Temporary local directory for added resources in the remote file system.</description>
</property>
<property>
@@ -363,7 +363,7 @@
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
- <value>/user/hive/warehouse</value>
+ <value>/home/learn_hadoop/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
<property>
@@ -542,7 +542,7 @@
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
- <value>jdbc:derby:;databaseName=metastore_db;create=true</value>
+ <value>jdbc:derby:;databaseName=/home/learn_hadoop/hive/metastore_db;create=true</value>
<description>
JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
@@ -1682,7 +1682,7 @@
</property>
<property>
<name>hive.querylog.location</name>
- <value>${system:java.io.tmpdir}/${system:user.name}</value>
+ <value>/home/learn_hadoop/hive/iotmp</value>
<description>Location of Hive run time structured log file</description>
</property>
<property>
@@ -3973,7 +3973,7 @@
</property>
<property>
<name>hive.server2.logging.operation.log.location</name>
- <value>${system:java.io.tmpdir}/${system:user.name}/operation_logs</value>
+ <value>/home/learn_hadoop/hive/iotmp/operation_logs</value>
<description>Top level directory where operation logs are stored if logging functionality is enabled</description>
</property>
<property>
四、初始化derby数据库
hive启动需要指定数据库,在第三节中配置了数据库为derby,所以需要先完成对derby的初始化:
learn_hadoop@localhost:~$ ~/hive/apache-hive-2.3.3-bin/bin/schematool -initSchema -dbType derby
五、启动hive
由于我们在第三节在~/.bashrc中添加了hive的bin目录至PATH,所以直接执行hive即可:
learn_hadoop@localhost:~$ hive
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/yang/hive/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/yang/hadoop/hadoop-2.7.6/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Logging initialized using configuration in jar:file:/home/yang/hive/apache-hive-2.3.3-bin/lib/hive-common-2.3.3.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive>
六、
看到上述hive>界面之后,即可进行hive的测试练习。如下简单的创建一个包含一个INT行数据a的TABLE x,并使用SELECT和DROP等对该TABLE进行操作:
hive> CREATE TABLE x(a INT);
OK
Time taken: 6.411 seconds
hive> SELECT * FROM a;
OK
Time taken: 1.672 seconds
hive> DROP TABLE a;
OK
Time taken: 1.742 seconds