Hive安裝配置詳解
本文主要是在Hadoop單機模式中演示Hive默認(嵌入式Derby模式)安裝配置過程。
1、下載安裝包
到官方網站下載最新的安裝包,這裏以Hive-0.12.0爲例:
$ tar -zxf hive-0.12.0-bin.tar.gz -C /home/ubuntu/hive-0.12.0
在這裏,HIVE_HOME=” /home/ubuntu/hive-0.12.0”。
2、設置環境變量
gedit /etc/profile,添加如下內容:
export HIVE_HOME=/home/ubuntu/hive-0.12.0 export PATH=$HIVE_HOME/bin:$PATH
3、定義配置文件
在目錄<HIVE_HOME>/conf目錄下有4個模板文件:
hive-default.xml.template
hive-env.sh.template
hive-exec-log4j.properties.template
hive-log4j.properties.template
以它們爲模板,定義對應的配置文件,其中最重要的是hive-site.xml和hive-env.sh
$ cd /home/ubuntu/hive-0.12.0/conf $ cp hive-default.xml.template hive-site.xml $ cp hive-env.sh.template hive-env.sh $ cp hive-exec-log4j.properties.template hive-exec-log4j.properties $ cp hive-log4j.properties.template hive-log4j.properties
本文以嵌入式Derby模式做演示,故hive-site.xml
以默認配置即可無需修改相關參數。但是需要根據自己具體的安裝情況來更新 hive-env.sh中的配置信息:
# Set HADOOP_HOME to point to a specific hadoop install directory export HADOOP_HOME=/home/ubuntu/hadoop-1.2.1 # Hive Configuration Directory can be controlled by: export HIVE_CONF_DIR=/home/ubuntu/hive-0.12.0/conf export HIVE_HOME=/home/ubuntu/hive-0.12.0 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 # Folder containing extra ibraries required for hive compilation/execution can be controlled by: # export HIVE_AUX_JARS_PATH=
注意:官方0.12.0的發佈版本中的hive-default.xml.template中有bug,在2000行處
4、配置HDFS中的目錄和權限
$ hadoop dfs -mkdir /tmp $ hadoop dfs -mkdir /user/hive/warehouse $ hadoop dfs -chmod g+w /tmp $ hadoop dfs -chmod g+w /user/hive/warehouse
5、有關 hive.metastore.schema.verification版本檢查的問題,有兩個解決辦法
方法一:運行前先將hive.metastore.schema.verification 設爲false
...... <!-- 設爲false 不做驗證--> <name>hive.metastore.schema.verification</name> <value>false</value> ......
方法二:不改配置,先初始化好數據,執行初始化命令:schematool -dbType derby -initSchema
$ schematool -dbType derby -initSchema Metastore connection URL: jdbc:derby:;databaseName=metastore_db;create=true Metastore Connection Driver : org.apache.derby.jdbc.EmbeddedDriver Metastore connection User: APP Starting metastore schema initialization to 0.12.0 Initialization script hive-schema-0.12.0.derby.sql Initialization script completed schemaTool completeted
查看初始化後的信息:schematool -dbType derby -info
$ schematool -dbType derby -info Metastore connection URL: jdbc:derby:;databaseName=metastore_db;create=true Metastore Connection Driver : org.apache.derby.jdbc.EmbeddedDriver Metastore connection User: APP Hive distribution version: 0.12.0 Metastore schema version: 0.12.0 schemaTool completeted
以上方法都可行,否則第一次運行的時候會出現類似報錯信息:
ERROR exec.DDLTask (DDLTask.java:execute(435)) - org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient at org.apache.hadoop.hive.ql.metadata.Hive.getDatabase(Hive.java:1143)
6、運行和測試
啓動HADOOP的所有進程,然後在命令行方式下執行命令hive即可,然後就可以執行以下測試命令
hive> show databases; OK default Time taken: 4.966 seconds, Fetched: 1 row(s) hive> show tables; OK Time taken: 0.186 seconds hive> CREATE TABLE micmiu_blog (id INT, siteurl STRING); OK Time taken: 0.359 seconds hive> SHOW TABLES; OK micmiu_blog Time taken: 0.023 seconds, Fetched: 1 row(s) hive>
至此,嵌入式derby模式下的Hive安裝配置已經成功。