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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章