Hadoop3.0.3 + hive3.0.0填一個大坑

Hadoop3.0.3 + hive3.0.0填一個大坑


1.問題

  因爲需要熟悉新版本的功能,所以部署了Hadoop3.0.3。看了下hive的配套說明:

這裏寫圖片描述
This release works with Hadoop 3.x.y. 所以選擇hive3.0.0進行安裝。但很無奈hive的文檔真的太不詳細了,按其一步步進行安裝報了兩個錯,困擾了很久,現總結一下配置過程。前置條件爲hadoop3.0.3正常運行,mysql服務配置完全

2. 配置過程

2.1. 解壓文件配置環境變量

  1. 解壓文件
$ tar -xzvf hive-x.y.z.tar.gz
  1. 配置環境變量
export HIVE_HOME={{pwd}}
export PATH=$HIVE_HOME/bin:$PATH
  1. 將mysql的JDBC包放到hive的lib文件夾中。注意是.jar文件

2.2. 配置hive-env.sh

HADOOP_HOME=/opt/modules/hadoop-3.0.3
export HIVE_CONF_DIR=/opt/modules/hive-3.0.0-bin

2.3. 配置hive-site.xml

<configuration>
    <property>
        <name>hive.metastore.schema.verification</name>
        <value>false</value>
    </property>

    <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>/user/hive/warehouse</value>
    </property>
    <property>
        <name>hive.exec.mode.local.auto</name>
        <value>false</value>
        <description> Let Hive determine whether to run in local mode automatically <
/description>
    </property>
    <property>
        <name>hive.metastore.uris</name>
        <value>thrift://spark.bigdata.com:9083</value>
        <description>Thrift URI for the remote metastore. Used by metastore client to
 connect to remote metastore.</description>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://spark.bigdata.com:3306/hive?createDatabaseIfNotExist=true
</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.jdbc.Driver</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>hive</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>hivemysql</value>
    </property>
    <!-- 顯示錶的列名 -->
    <property>
      <name>hive.cli.print.header</name>
      <value>true</value>
    </property>

    <!-- 顯示數據庫名稱 -->
    <property>
      <name>hive.cli.print.current.db</name>
      <value>true</value>
    </property>
</configuration>

2.4. 初始化hive

  1. 使用schematool初始化
schematool -dbType mysql -initSchema

  此處會出現第一個問題:直接修改hive-default.xml,配置未生效,可以看下面的LOG,我已經將hive-default.xml中的hiveuser改爲了hive,URL,Driver也做了相應的修改,可是執行schematool -dbType mysql -initSchema進行初始化的時候,還是使用了默認的URL,Driver和user APP。所以此處需要將hive-default.xml改爲hive-site.xml,執行初始化成功,但在hive官網上沒有明確說明(或者是我沒理解透)。

[hadoop@spark conf]$ schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/modules/hive-3.0.0-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/modules/hadoop-3.0.3/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
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 3.0.0
Initialization script hive-schema-3.0.0.mysql.sql


Error: Syntax error: Encountered "<EOF>" at line 1, column 64. (state=42X01,code=30000)
org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
Underlying cause: java.io.IOException : Schema script failed, errorcode 2
Use --verbose for detailed stacktrace.
*** schemaTool failed ***
  1. (可選)在mysql中進行metastore初始化
    這一步不太確定是否一定需要,可以先跳過,後面發現有問題的話再執行這一句。
mysql> source /opt/modules/hive-3.0.0-bin/scripts/metastore/upgrade/mysql/hive-schema-3.0.0.mysql.sql
  1. 啓動hive的metastore服務
    這一步在官網上完全沒有找到,但是沒有這一步的話就會一直報錯FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient。
[hadoop@spark bin]$ ./hive --service metastore &
  1. 最後進入hive,執行show databases;測試
hive (default)> show databases;
OK
database_name
default
Time taken: 3.157 seconds, Fetched: 1 row(s)

3. 總結

  • 和以前版本相比,從hive2.1開始需要使用schematool 進行初始化操作。Starting from Hive 2.1, we need to run the schematool command below as an initialization step. For example, we can use “derby” as db type.
  • 配置文件目錄也有點不太一樣,hive-site.xml文件需要自己創建,當然也可以從hive-default.xml複製。
  • 需要啓動hive的metastore 服務,不啓動無法關聯到mysql的metastore
  • mysql中的數據庫名更改爲了hive,以前是metastore

坑一:Schema initialization FAILED

org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
Underlying cause: java.io.IOException : Schema script failed, errorcode 2
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

需要在hive-site.xml配置好mysql訪問用戶名和密碼,在hive-default.xml配置未生效。

坑二:Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

hive (default)> show databases;
FAILED: HiveException java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

hive.metastore.schema.verification參數設置需要爲false,且在schemaTool初始化成功後,啓動hive的metastore服務: ./hive –service metastore &

(文檔結束)

Author:@Fighter10    
Shenzhen,2018-07-11 1355
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章