CDH-5.14.2添加Hive

1. 分发mysql-connector
添加mysql-connector-java.jar包到hive的lib目录下,并分发到每一个节点中(集群分发脚本)

[root@node01 ~]# cp /opt/software/mysql-connector-java.jar /opt/cloudera/parcels/CDH-5.14.2-1.cdh5.14.2.p0.3/lib/hive/lib/
[root@node01 lib]# xsync mysql-connector-java.jar

2. 添加Hive服务

CDH-5.14.2添加Hive_第1张图片
3. 创建metastore数据库

在所选择MetaStore的节点上,配置hive的hive-site.xml(/opt/cloudera/parcels/CDH/lib/hive/conf/hive-site.xml),添加以下配置:

<configuration>
  <property>
    <name>javax.jdo.option.ConnectionURLname>
    <value>jdbc:mysql://node02.kaikeba.com:3306/metastore?createDatabaseIfNotExist=true&useSSL=falsevalue>
  property>
  <property>
    <name>javax.jdo.option.ConnectionDriverNamename>
    <value>com.mysql.jdbc.Drivervalue>
  property>
  <property>
    <name>javax.jdo.option.ConnectionUserNamename>
    <value>scmvalue>
  property>
  <property>
    <name>javax.jdo.option.ConnectionPasswordname>
    <value>Passwordvalue>
  property>
  <property>
    <name>datanucleus.autoCreateSchemaname>
    <value>truevalue>
  property>
  <property>
    <name>hive.metastore.schema.verificationname>
    <value>falsevalue>
  property>
  ...
configuration>

参数含义:

  • javax.jdo.option.ConnectionURL:jdbc连接字符串,设置数据库为metastore,且如果不存在则创建
  • javax.jdo.option.ConnectionDriverName:设置使用mysql作为metastore存储库
  • javax.jdo.option.ConnectionUserName:数据库连接用户名
  • javax.jdo.option.ConnectionPassword:数据库连接密码
  • datanucleus.autoCreateSchema:(true)自动创建和升级 Hive Metastore 数据库架构
  • hive.metastore.schema.verification:(false)不使用严格的 Hive Metastore 架构验证

使用hive自带的schematool创建metastore

[root@node02 ~]# cd /opt/cloudera/parcels/CDH/lib/hive/bin
[root@node02 bin]# ./schematool -initSchema -dbType mysql
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
Metastore connection URL:        jdbc:mysql://node02.kaikeba.com:3306/metastore?createDatabaseIfNotExist=true&characterEncoding=UTF-8
Metastore Connection Driver :    com.mysql.jdbc.Driver
Metastore connection User:       scm
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
*** schemaTool failed ***

该错误出现是由于用户权限不足

mysql> use mysql;
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> select user,host from user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| maxwell       | %         |
| root          | %         |
| scm           | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
+---------------+-----------+
5 rows in set (0.02 sec)

mysql> grant all on *.* to 'scm'@'%' identified by 'Password';
Query OK, 0 rows affected, 1 warning (0.08 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

再次执行:

[root@node02 bin]# ./schematool -initSchema -dbType mysql
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
Metastore connection URL:        jdbc:mysql://node02.kaikeba.com:3306/metastore?createDatabaseIfNotExist=true&useSSL=false
Metastore Connection Driver :    com.mysql.jdbc.Driver
Metastore connection User:       scm
Starting metastore schema initialization to 1.1.0-cdh5.14.2
Initialization script hive-schema-1.1.0.mysql.sql
Initialization script completed
schemaTool completed

查看mysql中的数据库,已经创建了metastore:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| maxwell            |
| metastore          |
| mysql              |
| performance_schema |
| scm                |
| sys                |
| test               |
+--------------------+
8 rows in set (0.02 sec)

4. 继续安装
CDH-5.14.2添加Hive_第2张图片
CDH-5.14.2添加Hive_第3张图片
继续安装(如果此步骤没有提前设置好metastore数据库会报错,解决方法在文末)
CDH-5.14.2添加Hive_第4张图片
安装完成:
CDH-5.14.2添加Hive_第5张图片
【注意】

如果一开始没有使用schematool创建metastore,直接安装会报以下错误:
CDH-5.14.2添加Hive_第6张图片
报错内容:

org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version, Cause:Table 'scm.VERSION' doesn't exist
	at org.apache.hadoop.hive.metastore.CDHMetaStoreSchemaInfo.getMetaStoreSchemaVersion(CDHMetaStoreSchemaInfo.java:300)
	at org.apache.hive.beeline.HiveSchemaTool.validateSchemaVersions(HiveSchemaTool.java:686)
	at org.apache.hive.beeline.HiveSchemaTool.doValidate(HiveSchemaTool.java:579)
	at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:1144)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
	at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

这种情况下可以先通过以上所说的方式创建metastore,然后在新的标签页中打开Cloudera Manager(当前安装界面仍然保留),打开后发现虽然hive没有安装完成但是可以配置参数,编辑Hive配置以下参数:

  • hive.metastore.schema.verification

CDH-5.14.2添加Hive_第7张图片

  • datanucleus.autoCreateSchema

CDH-5.14.2添加Hive_第8张图片

  • Hive Metastore 数据库名称

CDH-5.14.2添加Hive_第9张图片
然后再切换到安装界面继续安装即可。

参考:
https://blog.csdn.net/qq_28844767/article/details/80164402
https://blog.csdn.net/wyzlwyzl/article/details/86546514
https://my.oschina.net/u/1240328/blog/1818803

你可能感兴趣的:(环境搭建,Hive)