本文環境如下:
操作系統:CentOS 6 32位
Hive版本:2.0.0
JDK版本:1.8.0_77 32位
Hadoop版本:2.6.4
Hive 2.0需要以下運行環境:
Java1.7以上(強烈建議使用Java 1.8)
Hadoop 2.X
Hive官網地址:http://hive.apache.org/
例如:
wget "http://mirrors.cnnic.cn/apache/hive/hive-2.0.0/apache-hive-2.0.0-bin.tar.gz"tar -xzvf apache-hive-2.0.0-bin.tar.gzmv apache-hive-2.0.0-bin /opt/hive-2.0.0
將hive-2.0.0/bin添加到path,以方便訪問
vi /etc/profile
在末尾添加:
HIVE_HOME=/opt/hive-2.0.0PATH=$PATH:$HIVE_HOME/bin
Hive和Hadoop一樣,有3種啟動模式,分別是單機模式,偽分布模式,分布模式。這裡先來說一下單機模式的啟動方式。
cd /opt/hive-2.0.0/confvi hive-site.xml //也可以用hive-default.xml.template去改,不過這個文件中的配置項太多了
輸入以下內容後保存:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration><property> <name>hive.metastore.warehouse.dir</name> <value>/opt/hive-2.0.0/warehouse</value> <description>location of default database for the warehouse</description></property><property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:derby:/opt/hive-2.0.0/metastore_db;create=true</value> <description>JDBC connect string for a JDBC metastore</description></property></configuration>
schematool -initSchema -dbType derby
出現以下幾行說明初始化成功:
Starting metastore schema initialization to 2.0.0Initialization script hive-schema-2.0.0.derby.sqlInitialization script completedschemaTool completed
mkdir -p /opt/hive-2.0.0/warehouse // 創建元數據存儲文件夾chmod a+rwx /opt/hive-2.0.0/warehouse // 修改文件權限hive
如果出現hive>
提示符則說明啟動成功
Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql)
錯誤原因: 數據庫沒有初始化,請參照4.2
Initialization script hive-schema-2.0.0.derby.sqlError: FUNCTION 'NUCLEUS_ASCII' already exists. (state=X0Y68,code=30000)org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!*** schemaTool failed ***
錯誤原因:數據庫文件夾中已經存在一些文件,解決方法就是清空數據庫文件夾(也就是前面配置的/opt/hive-2.0.0/metastore_db
文件夾)
http://xxxxxx/Linuxjc/1134302.html TechArticle