CentOS6 搭建Hive

CentOS6 搭建Hive

- 1.環境準備

Hadoop 2.x.x

MySQL 5.7 安裝流程(可參考https://www.cnblogs.com/lzj0218/p/5724446.html)親測可用

mysql-connector-java-5.1.47.jar 

Hive 2.3.5 下載地址(https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.5/)

- 2.Hive配置

2.1 將下載好的Hive 2.3.5壓縮文件 拷貝至 /usr/local 進行解壓並重命名hive

用到的命令

tar -zxvf hivexxxxx.xxx

mv hivexxxx hive

2.2 進入hive文件夾下的conf目錄 

cp hive-env.sh.template hive-env.sh 

cp hive-default.xml.template hive-site.xml

#-------------------------------------------------------
vim hive-env.sh 修改兩處參數
#根據自己的情況進行修改(1.hadoop目錄 2.hive配置文件目錄)
# Set HADOOP_HOME to point to a specific hadoop install directory
HADOOP_HOME=/home/hadoop/bdp/hadoop

# Hive Configuration Directory can be controlled by:
export HIVE_CONF_DIR=/usr/local/hive/conf

#-------------------------------------------------------
vim hive-site.xml 
#hive倉庫目錄(hdfs上 非本地)
  <property>
    <name>hive.metastore.warehouse.dir</name>
    <value>/user/hive/warehouse</value>
    <description>location of default database for the warehouse</description>
  </property>

#hive作業的本地臨時空間(本地)
  <property>
    <name>hive.exec.local.scratchdir</name>
    <value>/user/hive/tmp</value>
    <description>Local scratch space for Hive jobs</description>
  </property>

#hive下載資源目錄(hdfs上 非本地)
  <property>
    <name>hive.downloaded.resources.dir</name>
    <value>/user/hive/resource</value>
    <description>Temporary local directory for added resources in the remote file system.</description>
  </property>

#mysql密碼
  <property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>Mysql_%123</value>
    <description>password to use against metastore database</description>
  </property>

#連接mysql創建hive數據庫
 <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://192.168.195.128:3306/db_hive?createDatabaseIfNotExist=true&amp;useSSL=false</value>
    <description>
      JDBC connect string for a JDBC metastore.
      To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
      For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
    </description>
  </property>

2.3 將Hive添加的系統環境變量中

vim /etc/profile
export HIVE_HOME=/usr/local/hive
export PATH=.:$PATH:$HIVE_HOME/bin:$HIVE_HOME/conf

source /etc/profile


2.4 hive元數據庫初始化
執行 
schematool -dbType mysql -initSchema
報錯
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/bdp/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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:mysql://192.168.195.128:3306/db_hive?createDatabaseIfNotExist=true&useSSL=false
Metastore Connection Driver :	 org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User:	 APP
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
Underlying cause: java.sql.SQLException : Access denied for user 'APP'@'hadoop01' (using password: YES)
#這裏記錄一下
SQL Error code: 1045
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

啓動mysql shell 
mysql -uroot -p

#對應hive報的錯
grant all on *.* to 'APP'@'hadoop01' identified by 'password';

#再次執行
schematool -dbType mysql -initSchema

啓動mysql shell 
mysql -uroot -p

mysql> use db_hive;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_db_hive         |
+---------------------------+
| AUX_TABLE                 |
| BUCKETING_COLS            |
| CDS                       |
| COLUMNS_V2                |
| COMPACTION_QUEUE          |
| COMPLETED_COMPACTIONS     |
| COMPLETED_TXN_COMPONENTS  |
| DATABASE_PARAMS           |
| DBS                       |
| DB_PRIVS                  |
| DELEGATION_TOKENS         |
| FUNCS                     |
| FUNC_RU                   |
| GLOBAL_PRIVS              |
| HIVE_LOCKS                |
| IDXS                      |
| INDEX_PARAMS              |
| KEY_CONSTRAINTS           |
| MASTER_KEYS               |
| NEXT_COMPACTION_QUEUE_ID  |
| NEXT_LOCK_ID              |
| NEXT_TXN_ID               |
| NOTIFICATION_LOG          |
| NOTIFICATION_SEQUENCE     |
| NUCLEUS_TABLES            |
| PARTITIONS                |
| PARTITION_EVENTS          |
| PARTITION_KEYS            |
| PARTITION_KEY_VALS        |
| PARTITION_PARAMS          |
| PART_COL_PRIVS            |
| PART_COL_STATS            |
| PART_PRIVS                |
| ROLES                     |
| ROLE_MAP                  |
| SDS                       |
| SD_PARAMS                 |
| SEQUENCE_TABLE            |
| SERDES                    |
| SERDE_PARAMS              |
| SKEWED_COL_NAMES          |
| SKEWED_COL_VALUE_LOC_MAP  |
| SKEWED_STRING_LIST        |
| SKEWED_STRING_LIST_VALUES |
| SKEWED_VALUES             |
| SORT_COLS                 |
| TABLE_PARAMS              |
| TAB_COL_STATS             |
| TBLS                      |
| TBL_COL_PRIVS             |
| TBL_PRIVS                 |
| TXNS                      |
| TXN_COMPONENTS            |
| TYPES                     |
| TYPE_FIELDS               |
| VERSION                   |
| WRITE_SET                 |
+---------------------------+
57 rows in set (0.00 sec)

2.5 啓動hive

[root@hadoop01 conf]# hive
which: no hbase in (.:.:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/jdk/bin:/usr/local/jdk/sbin:/home/hadoop/bdp/hadoop/bin:/home/hadoop/bdp/hadoop/sbin:/usr/local/scala/bin:/usr/local/spark/bin:/usr/local/spark/python:/usr/local/spark/python/lib/py4j-0.10.7-src.zip::/home/hadoop/bin:/usr/local/jdk/bin:/usr/local/jdk/sbin:/home/hadoop/bdp/hadoop/bin:/home/hadoop/bdp/hadoop/sbin:/usr/local/scala/bin:/usr/local/spark/bin:/usr/local/spark/python:/usr/local/spark/python/lib/py4j-0.10.7-src.zip:/usr/local/hive/bin:/usr/local/hive/conf:)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/bdp/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]

Logging initialized using configuration in jar:file:/usr/local/hive/lib/hive-common-2.3.5.jar!/hive-log4j2.properties Async: true
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive> 

- 3.總結錯誤及解決辦法

執行schematool -dbType mysql -initSchema報以下錯誤:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hadoop/bdp/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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:mysql://192.168.195.128:3306/db_hive?createDatabaseIfNotExist=true&useSSL=false
Metastore Connection Driver :	 org.apache.derby.jdbc.EmbeddedDriver
Metastore connection User:	 APP
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
Underlying cause: java.sql.SQLException : Access denied for user 'APP'@'hadoop01' (using password: YES)
SQL Error code: 1045
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

解決辦法:
mysql中執行
grant all on *.* to 'APP'@'hadoop01' identified by 'password';
啓動hive報以下錯誤:
Wed Jun 12 07:40:49 PDT 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

#修改hive-site.xml 對應的配置中追加 &amp;useSSL=false
 <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://192.168.195.128:3306/db_hive?createDatabaseIfNotExist=true&amp;useSSL=false</value>
    <description>
      JDBC connect string for a JDBC metastore.
      To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
      For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
    </description>
  </property>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章