附录G Hive环境安装

G.1 Hive的安装

装好Hadoop的环境后,我们可以把Hive装在namenode服务上。Hadoop的环境配置,请参考附录F。Hive的安装首先下载 hive-0.9.0.tar.gz ,然后解压到 /home/cos/toolkit/hive-0.9.0。进入hive目录,创建配置文件。

~ cd /home/cos/toolkit/hive-0.9.0
~ cp hive-default.xml.template hive-site.xml  # 复制一份配置文件
~ cp hive-log4j.properties.template hive-log4j.properties  # 复制一份日志文件

修改配置文件hive-site.xml。设置把Hive的元数据存储到MySQL中。

~ vi conf/hive-site.xml
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive_metadata?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>

<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>

<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>username to use against metastore database</description>
</property>

<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>

<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>

修改日志文件hive-log4j.properties 。

#log4j.appender.EventCounter=org.apache.hadoop.metrics.jvm.EventCounter
log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter

设置环境变量

~ sudo vi /etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/cos/toolkit/ant184/bin:/home/cos/toolkit/jdk16/bin:/home/cos/toolkit/maven3/bin:/home/cos/toolkit/hadoop-1.0.3/bin:/home/cos/toolkit/hive-0.9.0/bin"
JAVA_HOME=/home/cos/toolkit/jdk16
ANT_HOME=/home/cos/toolkit/ant184
MAVEN_HOME=/home/cos/toolkit/maven3
HADOOP_HOME=/home/cos/toolkit/hadoop-1.0.3
HIVE_HOME=/home/cos/toolkit/hive-0.9.0
HADOOP_STREAMING=/home/conan/hadoop/hadoop-1.0.3/contrib/streaming/hadoop-streaming-1.0.3.jar
CLASSPATH=/home/cos/toolkit/jdk16/lib/dt.jar:/home/cos/toolkit/jdk16/lib/tools.jar
在hdfs上面,创建hive的目录
$HADOOP_HOME/bin/hadoop fs -mkidr /tmp
$HADOOP_HOME/bin/hadoop fs -mkidr /user/hive/warehouse
$HADOOP_HOME/bin/hadoop fs -chmod g+w /tmp
$HADOOP_HOME/bin/hadoop fs -chmod g+w /user/hive/warehouse

在MySQL中创建数据库

create database hive_metadata;
grant all on hive_metadata.* to hive@'%' identified by 'hive';
grant all on hive_metadata.* to hive@localhost identified by 'hive';
ALTER DATABASE hive_metadata CHARACTER SET latin1;

手动上传mysql的jdbc库到hive/lib

~ ls /home/cos/toolkit/hive-0.9.0/lib
mysql-connector-java-5.1.22-bin.jar

启动hive服务器。

~ bin/hive --service metastore &  #启动metastore服务
Starting Hive Metastore Server

~ bin/hive --service hiveserver &    #启动hiveserver服务
Starting Hive Thrift Server
~ bin/hive shell      #启动hive客户端
Logging initialized using configuration in file:/root/hive-0.9.0/conf/hive-log4j.properties
Hive history file=/tmp/root/hive_job_log_root_201211141845_1864939641.txt
hive> show tables
OK
t_hive
Time taken: 0.099 seconds

这样我们成功地把Hive安装在Linux Ubuntu系统中,并进行了简单的使用介绍。

results matching ""

    No results matching ""