title: Hive1.2.1安裝筆記
date: 2016/8/22 0:47:36
tags: Hive
categories: 大數(shù)據(jù)
環(huán)境
ubuntu 16.04
4臺(tái)機(jī)器的Hadoop2.7.2集群
Mysql安裝在slave2中
hive安裝在master上
下載Hive
$ wget http://mirrors.cnnic.cn/apache/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz
# 解壓
$ tar -zxvf apache-hive-1.2.1-bin.tar.gz /home/ubuntu/cloud
配置Hive環(huán)境變量
$ sudo vim /etc/profile
#添加
export HIVE_HOME=/home/ubuntu/cloud/apache-hive-1.2.1-bin
export PATH=$PATH:$HIVE_HOME/bin
$source /etc/profile
在Mysql中創(chuàng)建Hive用戶
mysql>CREATE USER 'hive' IDENTIFIED BY 'hive';
mysql>GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' IDENTIFIED BY 'hive' WITH GRANT OPTION;
mysql>flush privileges;
創(chuàng)建Hive數(shù)據(jù)庫(kù)
$ mysql -uhive -phive
mysql>create database hive;
配置Hive
進(jìn)入Hive的conf目錄,找到hive-default.xml.template
,cp份為hive-site.xml
$ vim hive-site.xml
# 刪除configuration標(biāo)簽里的所有內(nèi)容 添加如下內(nèi)容
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://slave2:3306/hive?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>
下載mysql-connector-java-5.1.32-bin.jar
這里用5.1.32版本測(cè)試不報(bào)錯(cuò)所坯,5.1.38會(huì)報(bào)warn
#將連接jar包拷貝到Hive的lib目錄
$ cp mysql-connector-java-5.1.32-bin.jar /home/ubuntu/cloud/apache-hive-1.2.1-bin/lib/
若要裝hive客戶端可在客戶端節(jié)點(diǎn)設(shè)置
vim hive-site.xml
<configuration>
<!-- thrift://<host_name>:<port> 默認(rèn)端口是9083 -->
<property>
<name>hive.metastore.uris</name>
<value>thrift://master:9083</value>
<description>Thrift uri for the remote metastore. Used by metastore client to connect to remote metastore.</description>
</property>
<!-- hive表的默認(rèn)存儲(chǔ)路徑 -->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
</configuration>
Hive啟動(dòng)
要啟動(dòng)metastore服務(wù)
$ hive --service metastore &
$ jps
10288 RunJar #多了一個(gè)進(jìn)程
9365 NameNode
9670 SecondaryNameNode
11096 Jps
9944 NodeManager
9838 ResourceManager
9471 DataNode
啟動(dòng)hive命令行
ubuntu@master:~$ hive
Logging initialized using configuration in jar:file:/home/ubuntu/cloud/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.properties
hive> show tables;
OK
Time taken: 0.705 seconds
啟動(dòng)hiveserver2
hive --service hiveserver2 start &
問(wèn)題解決
問(wèn)題:創(chuàng)建表出先如下錯(cuò)誤憔鬼,刪除表卡住
Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.
初始化
注意:初始化之前先刪除hdfs上的metastore,否則會(huì)出錯(cuò)/user/hive/warehouse
在hive服務(wù)端輸入以下命令
schematool -dbType mysql -initSchema