hive的metastore有好几种部署方式,默认的方法是直接用自带的Derby数据库,但是这会导致hive服务和metastore必须同时启动,在实际使用时一般不使用这种方法,这里介绍一下自己配置metastore到Mysql的步骤和一些坑。
Hive下载下载链接 https://dlcdn.apache.org/hive/
wget https://dlcdn.apache.org/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz tar zxvf apache-hive-3.1.2-bin.tar.gz ln -s apache-hive-3.1.2-bin hive export HIVE_HOME=/opt/tool/hive export PATH=$PATH:$HIVE_HOME/bin export CLASSPATH=$CLASSPATH:$HIVE_HOME/lib/*:. 下面的命令是用来执行〜/.bashrc文件。 source ~/.bashrc
配置hive
配置Hive用于Hadoop环境中,需要编辑hive-env.sh文件,该文件放置在 $HIVE_HOME/conf目录。下面的命令重定向到Hive config文件夹并复制模板文件:
$ cd $HIVE_HOME/conf $ cp hive-env.sh.template hive-env.sh
Hive安装成功完成,接下来需要配置metastore相关信息。
配置 metastore 到 MySql编辑hive-site.xml中以下property,添加数据库的配置信息。
javax.jdo.option.ConnectionURL jdbc:mysql://10.79.231.84:3306/metastore_db?createDatabaseIfNotExist=true JDBC connect string for a JDBC metastore javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver Driver class name for a JDBC metastore javax.jdo.option.ConnectionUserName root username to use against metastore database javax.jdo.option.ConnectionPassword asd123 password to use against metastore database
需要先安装mysql的driver,将mysql-connector-java-8.0.25.jar复制到$HIVE_PATH/lib下
cp mysql-connector-java-8.0.25.jar $HIVE_PATH/lib/
在hive/bin目录运行指令初始化元数据库
schematool -dbType mysql -initSchema运行
运行hive
$HIVE_HOME/bin/hive
在成功安装Hive后,能看到以下回应:
Logging initialized using configuration in jar:file:/opt/tool/apache-hive-3.1.2-bin/lib/hive-common-3.1.2.jar!/hive-log4j2.properties Async: true Hive Session ID = f7ea2414-fa57-47f3-86f7-3081cd4ad469 hive> show tables; OK Time taken: 0.901 seconds hive>远程模式部署
远程模式部署metastore服务地址关闭元数据存储授权 hive.metastore.uris thrift://td0:9083 Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore. 关闭元数据存储版本的验证 hive.metastore.event.db.notification.api.auth false Should metastore do authorization against database notification related APIs such as get_next_notification. If set to true, then only the superusers in proxy settings have the permission hive.metastore.schema.verification false
需要启动metastore服务
前台启动 hive --service metastore nohup hive --service metastore & hive --service metastore --hiveconf hive.root.logger=DEBUG,console报错信息 报错1
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument
错误原因:系统找不到这个类所在的jar包或者jar包的版本不一样系统不知道使用哪个。hive启动报错的原因是后者
解决办法:
1、com.google.common.base.Preconditions.checkArgument这个类所在的jar包为:guava.jar
2、hadoop-3.2.1(路径:hadoopsharehadoopcommonlib)中该jar包为 guava-27.0-jre.jar;而hive-3.1.2(路径:hive/lib)中该jar包为guava-19.0.1.jar
3、将jar包变成一致的版本:删除hive中低版本jar包,将hadoop中高版本的复制到hive的lib中。
报错2com.ctc.wstx.exc.WstxParsingException: Illegal character entity: expansion character (code 0x8 at [row,col,system-id]: [3215,96,"file:/opt/tool/apache-hive-3.1.2-bin/conf/hive-site.xml"]
存在异常字符需要修改,在第3220行,修改之后恢复正常
vim hive-site.xml +3215报错3
Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
发现${system:java.io.tmpdir}并没有定义,所以在hive-si te.xml中加入以下的property
报错4system:java.io.tmpdir /opt/tool/hive/tmp system:user.name ${user.name}
Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHivemetaStoreClient
没有初始化元数据库,需要运行schematool -dbType mysql -initSchema



