前言
安裝過程中遇到的問題從以下部落格學習而得,現對其進行整理
在Hadoop1.2.1分布式叢集環境下安裝hive0.12
CentOS下Hive2.0.0單機模式安裝詳解
CentOS下Hive2.0.0叢集模式安裝詳解
解決Hive installation issues: Hive metastore database is not initialized
hive啟動報錯 java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7B
1.準備環境
java 1.7以上
hadoop版本參見hive官網的支援版本号,并啟動hadoop叢集。
2.下載下傳、解壓hive安裝包
Hive官網位址: http://hive.apache.org/
下載下傳安裝包後用tar -xzvf指令解壓,并用mv對檔案夾重命名為hive
3.配置環境變量
vim /etc/profile,加入下面幾行
HIVE_HOME=/home/hive
CLASSPATH=$CLASSPATH:$HIVE_HOME/lib
PATH=$PATH:$HIVE_HOME/bin
export HIVE_HOME CLASSPATH PATH
儲存後使用指令:source /etc/profile使環境變量立即生效
4. 建立hive-env.sh、hive-site.xml檔案
進入hive/conf根據各template建立這兩個檔案
4.1修改hive-env.sh檔案
HADOOP_HOME=/home/hadoop
export HIVE_CONF_DIR=/home/hive/conf
4.2修改hive-site.xml檔案
此處需要修改的部分2.1.0版本都不用修改,低版本可能需要修改
<value>auth</auth>修改為<value>auth</value>
把hive.metastore.schema.verification=true,修改為 hive.metastore.schema.verification=false
至此hive的相關配置工作完成。
5.MySQL
5.1安裝MySQL
Hive預設使用derby資料庫存儲中繼資料,但是該資料庫不适用于生産環境,這邊使用MySQL作為中繼資料的存儲資料庫。
是以需要先安裝好
MySQL
。
安裝過程使用sudo apt-get install mysql-server mysql-client指令安裝即可,但是注意如果出現Encountered a section with no Package: header錯誤時,使用如下指令解決:
sudo rm /var/lib/apt/lists/* -vf
sudo apt-get update
安裝MySQL過程中會為root使用者設定密碼,安裝完畢後輸入mysql -u root -p以及密碼啟動MySQL來建立資料庫使用者
5.2建立MySQL使用者
create user 'hive' identified by 'hive';
grant all privileges on *.* to 'hive' with grant option;
flush privileges;
create database hive;
5.3拷貝MySQL驅動檔案
下載下傳位址:http://dev.mysql.com/downloads/connector/j/ ,解壓後拷貝其中的
mysql-connector-java-5.1.39-bin.jar
到hive的lib檔案夾下。
6.修改hive-site.xml檔案
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost: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>
7.初始化資料庫
在使用hive或者hive --service cli來運作之前需要初始化資料庫,如果在初始化之前已經運作了上述指令并且失敗,則需要删除産生的metastore_db檔案
使用指令schematool -initSchema -dbType mysql
初始化mysql資料庫
出現以下幾行說明初始化成功:
Starting metastore schema initialization to 2.1.0
Initialization script hive-schema-2.1.0.derby.sql
Initialization script completed
schemaTool completed
8.啟動hive
在使用hive或者hive --service cli運作hive時出現java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D錯誤
需要修改hive-site.xml的以下部分
<property>
<name>hive.exec.scratchdir</name>
<value>/tmp/hive</value>
<description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/<username> is created, with ${hive.scratch.dir.permission}.</description>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/tmp/hive/local</value>
<description>Local scratch space for Hive jobs</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/tmp/hive/resources</value>
<description>Temporary local directory for added resources in the remote file system.</description>
</property>
然後即可正常運作。
9.測試
使用指令:
show tables;
create table test1(id int,name string);
select * from test1;
drop table test1;
來測試HiveQL是否能使用。