Hadoop Metastore不会初始化

RJ *_*ole 5 hive derby metastore

序言:我是hadoop/hive的新手.已经安装了独立的hadoop,现在我正试图让hive工作.我一直收到关于初始化Metastore的错误,似乎无法弄清楚如何解决.(hadoop 2.7.2和hive 2.0)

HADOOP_HOME和HIVE_HOME设置

ubuntu15-laptop: ~ $>echo $HADOOP_HOME
/usr/hadoop/hadoop-2.7.2

ubuntu15-laptop: ~ $>echo $HIVE_HOME
/usr/hive
Run Code Online (Sandbox Code Playgroud)

hdfs正在运行

ubuntu15-laptop: ~ $>hadoop fs -ls /
Found 2 items
drwxrwxr-x   - testuser supergroup          0 2016-04-13 21:37 /tmp
drwxrwxr-x   - testuser supergroup          0 2016-04-13 21:38 /user

ubuntu15-laptop: ~ $>hadoop fs -ls /user
Found 1 items
drwxrwxr-x   - testuser supergroup          0 2016-04-13 21:38 /user/hive

ubuntu15-laptop: ~ $>hadoop fs -ls /user/hive
Found 1 items
drwxrwxr-x   - testuser supergroup          0 2016-04-13 21:38 /user/hive/warehouse

ubuntu15-laptop: ~ $>groups
testuser adm cdrom sudo dip plugdev lpadmin sambashare
Run Code Online (Sandbox Code Playgroud)

蜂巢不起作用.说我需要初始化我的Metastore

ubuntu15-laptop: ~ $>hive

Logging initialized using configuration in
jar:file:/usr/hive/lib/hive-common-2.0.0.jar!/hive-log4j2.properties
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)
Run Code Online (Sandbox Code Playgroud)

所以我尝试初始化它使用postgres - 但schematool尝试使用德比

ubuntu15-laptop: ~ $>schematool -initSchema -dbType postgres
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 2.0.0
Initialization script hive-schema-2.0.0.postgres.sql
Error: Syntax error: Encountered "statement_timeout" at line 1, column 5.
(state=42X01,code=30000)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization
FAILED! Metastore state would be inconsistent !!
*** schemaTool failed ***
Run Code Online (Sandbox Code Playgroud)

所以我改变hive-site.xml使用postgres驱动程序等,但因为我没有安装驱动程序,它失败了

ubuntu15-laptop: ~ $>cp /usr/hive/conf/hive-site.xml.templ /usr/hive/conf/hive-site.xml
ubuntu15-laptop: ~ $>schematool -initSchema -dbType postgres
Metastore connection URL:  jdbc:postgresql://localhost:5432/hivedb
Metastore Connection Driver :  org.postgresql.Driver
Metastore connection User:   123456
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to load driver
*** schemaTool failed ***
Run Code Online (Sandbox Code Playgroud)

所以然后我尝试使用derby首先移动hive-site.xml,因此默认为derby

ubuntu15-laptop: ~ $>mv /usr/hive/conf/hive-site.xml /usr/hive/conf/hive-site.xml.templ
Run Code Online (Sandbox Code Playgroud)

然后我尝试再次使用德比进行初始化,但似乎已经根据错误初始化"错误:功能'NUCLEUS_ASCII'已经存在"

ubuntu15-laptop: ~ $>schematool -initSchema -dbType derby
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 2.0.0
Initialization script hive-schema-2.0.0.derby.sql
Error: 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 ***
Run Code Online (Sandbox Code Playgroud)

我已经在这两天了.任何帮助将非常感谢.

RJ *_*ole 10

所以..

这是发生了什么.

安装配置单元后,我做的第一件事是运行配置单元,它试图创建/初始化metastore_db,但显然没有正确.在最初的运行中,我收到了这个错误:

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)
Run Code Online (Sandbox Code Playgroud)

运行配置单元即使失败,也会在我运行配置单元的目录中创建一个metastore_db目录:

ubuntu15-laptop: ~ $>ls -l |grep meta
drwxrwxr-x 5 testuser testuser 4096 Apr 14 12:44 metastore_db
Run Code Online (Sandbox Code Playgroud)

所以当我试着跑步的时候

ubuntu15-laptop: ~ $>schematool -initSchema -dbType derby
Run Code Online (Sandbox Code Playgroud)

Metastore已经存在,但还没有完整的形式.

Soooooo的答案是:

  1. 在您第一次运行配置单元之前,请运行

    schematool -initSchema -dbType derby

  2. 如果您已经运行了hive,然后尝试使用initSchema并且它失败了:

    mv metastore_db metastore_db.tmp

  3. 重新跑

    schematool -initSchema -dbType derby

  4. 再次运行配置单元

**另外值得注意的是:如果更改目录,将无法找到上面创建的metastore_db!我确信有一个很好的理由,我还不知道,因为我今天第一次尝试使用蜂巢.啊,这里的信息是: 我在运行Hive的地方创建了metastore_db