Hive元数据相关配置
hive的配置
下面是Hive元存储”的存储位置为MySQL数据库,必要的配置。包括连接URL,驱动类,数据库账号以及密码
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master1-1:3306/hive?characterEncoding=UTF-8</value>
<description>连接的url</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>连接驱动类名</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>********</value>
<description>连接数据库用户名</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>********</value>
<description>连接数据库密码</description>
</property>
mysql数据库配置
- 首先我们要创建一个用于保存hive元数据的数据库
create database hive charset=utf8
2.赋予hive连接mysql用户远程的权限(这里我使用的是root账户来进行连接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION
3.将连接mysql的驱动包放到hive的lib目录下
cp mysql-connector-java.jar ${HIVE_HOME}/lib/
初始化hive的元数据
使用schematool 初始化hive的元数据
schematool -initSchema -dbType mysql
检查数据库
use hive
show tables;
我们会看到存放hive元数据的数据库已经生成了很多表,到这里,就表示你hive元数据配置和初始化成功了!
hive初始化元数据常见的报错
错误1
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
这里的排查方法是:
-
检查hive-site.xml的数据库用户名密码有没有写错
-
检查用于连接的用户是否有远程登陆的权限
错误2
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
对于这个错误,我们把${HADOOP_HOME}/share/hadoop/yarn/lib/jline-0.9.94.jar
这个文件删除就可以了
rm ${HADOOP_HOME}/share/hadoop/yarn/lib/jline*.jar
错误3
有时候,由于你不是用的root用户进行安装会导致一些临时文件或者目录没有权限的问题
Logging initialized using configuration in file:/opt/apache-hive-2.3.5-bin/conf/hive-log4j2.properties Async: true
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
at org.apache.hadoop.fs.Path.initialize(Path.java:254)
at org.apache.hadoop.fs.Path.<init>(Path.java:212)
at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:659)
at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:582)
at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:549)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:750)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:686)
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:239)
at org.apache.hadoop.util.RunJar.main(RunJar.java:153)
Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
at java.net.URI.checkPath(URI.java:1823)
at java.net.URI.<init>(URI.java:745)
at org.apache.hadoop.fs.Path.initialize(Path.java:251)
我们需要配置一下临时文件目录,而且hive的管理用户拥有访问这些目录的权限,最好的创建在安装hive的用户的用户目录下,我这里是hive用户,就创建在/home/hive这个目录下
<property>
<name>Hive.exec.local.scratchdir</name>
<value>/home/hive/tmp/</value>
<description>资源文件目录</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/home/hive/tmp/resources</value>
<description>下载资源目录</description>
</property>
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>/home/hive/tmp/operation_logs</value>
<description>日志文件目录</description>