hive安装本地模式报错Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient解决

在本地安装了jdk、mysql和hadoop环境后

启动hive,输入show tables;报错

hive> show tables;
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient

未初始化元数据库。

输入

schematool -dbType mysql -initSchema

初始化mysql为hive的元数据库,继续报错

root@zwc-virtual-machine:/home/soft/apache-hive-2.3.3-bin/conf# schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/soft/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/soft/hadoop-2.8.5/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.17.135:3306/hive
Metastore Connection Driver :	 com.mysql.jdbc.Driver
Metastore connection User:	 root
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
Underlying cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException : Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
SQL Error code: 0
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

按照提示加上--verbose打印完整错误堆栈信息

root@zwc-virtual-machine:/home/soft/apache-hive-2.3.3-bin/conf# schematool -dbType mysql -initSchema --verbose
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/soft/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/soft/hadoop-2.8.5/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.17.135:3306/hive
Metastore Connection Driver :	 com.mysql.jdbc.Driver
Metastore connection User:	 root
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
Underlying cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException : Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
SQL Error code: 0
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
	at org.apache.hive.beeline.HiveSchemaHelper.getConnectionToMetastore(HiveSchemaHelper.java:77)
	at org.apache.hive.beeline.HiveSchemaTool.getConnectionToMetastore(HiveSchemaTool.java:144)
	at org.apache.hive.beeline.HiveSchemaTool.testConnectionToMetastore(HiveSchemaTool.java:473)
	at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:577)
	at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:563)
	at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:1145)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.apache.hadoop.util.RunJar.run(RunJar.java:239)
	at org.apache.hadoop.util.RunJar.main(RunJar.java:153)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:342)
	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2197)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2230)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2025)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:778)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
	at java.sql.DriverManager.getConnection(DriverManager.java:571)
	at java.sql.DriverManager.getConnection(DriverManager.java:215)
	at org.apache.hive.beeline.HiveSchemaHelper.getConnectionToMetastore(HiveSchemaHelper.java:73)
	... 11 more
Caused by: java.net.ConnectException: 拒绝连接
	at java.net.PlainSocketImpl.socketConnect(Native Method)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:579)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:301)
	... 26 more
*** schemaTool failed ***

找到问题:mysql拒绝连接,发现root通过本地ip无法登陆mysql,于是把conf/hive-site.xml中的jdbc的ip地址修改为localhost就可以了。(或者给本地ip的root账号赋权)

部分hive-site.xml内容

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://localhost:3306/hive</value>
  <description>JDBC connect string for a JDBC metastore</description>
</property>

进入hive:

root@zwc-virtual-machine:/home/soft/apache-hive-2.3.3-bin/conf# hive
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/soft/apache-hive-2.3.3-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/soft/hadoop-2.8.5/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:/home/soft/apache-hive-2.3.3-bin/lib/hive-common-2.3.3.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. tez, spark) or using Hive 1.X releases.
hive> 
    > show tables;

hive安装成功。

<think>我们正在处理一个关于CDH集群中运行Spark任务时出现的Hive Metastore客户端实例化错误的问题。 错误信息:'unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetastoreClient' 根据经验,这个错误通常与Hive Metastore服务的配置或访问有关。可能的原因包括: 1. Hive Metastore服务未运行。 2. Spark任务无法连接到Hive Metastore服务(网络问题、配置错误等)。 3. 类路径问题,缺少必要的依赖(如Hive相关的JAR包)。 4. 版本不兼容问题。 由于环境是CDH集群,我们可以通过Cloudera Manager来管理服务,因此首先检查Hive Metastore服务状态。 解决步骤: 步骤1:检查Hive Metastore服务状态 - 登录Cloudera Manager,检查Hive Metastore服务是否运行正常。 - 如果服务未启动,则启动它。 步骤2:检查网络连接 - 确保运行Spark任务的节点可以访问Hive Metastore服务的主机和端口(默认端口9083)。 - 使用telnet命令测试连通性:`telnet <metastore_host> 9083` 步骤3:检查Spark配置 - 确保Spark任务配置了正确的Hive Metastore URI。在spark-defaults.conf中,通常需要设置: spark.hadoop.hive.metastore.uris thrift://<metastore_host>:9083 - 如果是在YARN集群模式运行,确保将Hive的配置文件(hive-site.xml)添加到Spark的配置中。在CDH中,通常可以通过在Spark的配置中添加服务范围或通过Spark的“高级配置”来设置。 步骤4:检查类路径 - 确保Spark任务包含Hive Metastore客户端所需的JAR包。在CDH环境中,通常这些JAR包位于Hive安装目录下。 - 可以通过设置Spark的`spark.driver.extraClassPath`和`spark.executor.extraClassPath`来添加Hive的JAR包。例如: spark.driver.extraClassPath /opt/cloudera/parcels/CDH/lib/hive/lib/*:/opt/cloudera/parcels/CDH/lib/hive-metastore/lib/* spark.executor.extraClassPath /opt/cloudera/parcels/CDH/lib/hive/lib/*:/opt/cloudera/parcels/CDH/lib/hive-metastore/lib/* (注意:路径需要根据实际CDH安装路径调整,通常CDH安装在/opt/cloudera/parcels/CDH-xxxx,其中xxxx是版本号,但通常有一个软链接/opt/cloudera/parcels/CDH指向当前版本) 步骤5:检查版本兼容性 - 确保Spark和Hive的版本兼容。CDH通常保证了其组件之间的兼容性,但如果自行升级了某个组件,可能会出现问题。 步骤6:查看详细日志 - 如果上述步骤无法解决问题,查看Spark任务的详细日志,寻找更具体的错误信息。 额外提示:在CDH中,使用Spark on YARN时,可以通过Cloudera Manager为Spark服务添加配置项来设置Hive Metastore URI和类路径。 示例配置(在Cloudera Manager中): - 进入Spark服务配置页面。 - 搜索“Spark服务高级配置代码段(安全阀)” - 添加: spark.hadoop.hive.metastore.uris thrift://<metastore_host>:9083 - 搜索“Spark客户端高级配置代码段(安全阀)” - 添加类路径配置(如果必要): spark.driver.extraClassPath /opt/cloudera/parcels/CDH/lib/hive/lib/*:/opt/cloudera/parcels/CDH/lib/hive-metastore/lib/* spark.executor.extraClassPath /opt/cloudera/parcels/CDH/lib/hive/lib/*:/opt/cloudera/parcels/CDH/lib/hive-metastore/lib/* 注意:在集群中每一台运行Spark的节点上,路径都必须存在。 另外,也可以考虑将Hive的配置文件(hive-site.xml)复制到Spark的配置目录(通常是/etc/spark/conf/),这样Spark就可以自动读取Hive的配置。 如果问题仍然存在,请检查Hive Metastore日志(通常位于/var/log/hive/)以获取更多信息。 最后,请确保Hive Metastore服务使用的数据库(如MySQL)是可用的,并且Hive Metastore有正确的权限访问该数据库。 根据以上步骤,应该能够解决这个问题。 相关问题: 1. 如何检查Hive Metastore服务是否正常运行? 2. 在CDH集群中,如何配置Spark以集成Hive? 3. 如何查看Hive Metastore服务的日志? 4. 在Spark任务中,如何添加额外的依赖JAR包? </think>### CDH集群运行Spark任务报错 `unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetastoreClient` 的解决方案 此错误通常由 **Hive Metastore 服务连接问题** 或 **依赖配置缺失** 引起,以下是具体解决步骤: --- #### 1. **检查 Hive Metastore 服务状态** - 登录 Cloudera Manager,确认 **Hive Metastore Server** 是否正常运行。 - 若服务未启动: ```bash # 通过CM启动服务或命令行操作 sudo service hive-metastore start ``` - 验证端口 `9083` 是否监听: ```bash netstat -tuln | grep 9083 ``` --- #### 2. **配置 Spark 连接 Hive Metastore** - **添加 Hive Metastore URI** 在 `spark-defaults.conf` 中增加配置(路径:`/etc/spark/conf`): ``` spark.sql.hive.metastore.version 2.1.1 # 与CDH的Hive版本一致 spark.sql.hive.metastore.jars builtin # 使用内置Hive库 spark.hadoop.hive.metastore.uris thrift://<metastore_host>:9083 ``` > 替换 `<metastore_host>` 为实际主机名(可通过 `hive --service metastore -h` 查看)。 - **同步配置到集群** 通过 Cloudera Manager 将更新分发到所有节点,并重启 Spark 服务。 --- #### 3. **添加 Hive 依赖 JAR 包** - **指定额外 Classpath** 在 `spark-defaults.conf` 中添加: ``` spark.driver.extraClassPath /opt/cloudera/parcels/CDH/lib/hive/lib/* spark.executor.extraClassPath /opt/cloudera/parcels/CDH/lib/hive/lib/* ``` - **提交任务时附加 JAR** 通过 `--jars` 参数显式加载 Hive JAR: ```bash spark-submit --jars $(echo /opt/cloudera/parcels/CDH/lib/hive/lib/*.jar | tr ' ' ',') ... ``` --- #### 4. **检查配置一致性** - 确保所有节点的以下文件内容一致: - `/etc/spark/conf/spark-defaults.conf` - `/etc/hive/conf/hive-site.xml` - 重点检查 `hive.metastore.uris` 是否指向正确地址(在 `hive-site.xml` 中)。 --- #### 5. **验证网络连通性** - 从 Spark 执行节点测试 Metastore 连通性: ```bash telnet <metastore_host> 9083 ``` - 若不通,检查防火墙规则或 DNS 解析。 --- #### 6. **数据库连接检查** 若 Metastore 使用外部数据库(如 MySQL): - 确认数据库服务正常(通过 `sudo service mysql status`)。 - 检查 `hive-site.xml` 中的 JDBC 配置: ```xml <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://<db_host>/hive?createDatabaseIfNotExist=true</value> </property> ``` --- #### 7. **查看日志定位问题** - **Spark 驱动日志**:在 YARN Web UI 中查找任务日志。 - **Hive Metastore 日志**: ```bash tail -f /var/log/hive/hive-metastore.log ``` 常见错误如数据库权限不足、JDBC 驱动缺失等会在此显示。 --- ### 相关问题 1. 如何验证 Spark 与 Hive Metastore 的连通性? 2. CDH 中如何查找 Hive Metastore 的主机名和端口? 3. 如何为 Spark on YARN 动态添加 Hive 依赖库? 4. Hive Metastore 连接数据库失败时如何排查? > 提示:若仍无法解决,提供 `hive-metastore.log` 和 Spark 任务日志可进一步分析[^1]。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值