解决 Hive 报错 NoSuchMethodError 问题
后知后觉 暂无评论

在搭建不同版本的 Hive 和 Hadoop 时出现了以下报错信息:NoSuchMethodError: com.google.common.base.Preconditions.checkArgument

使用的是高版本的 Hive 搭配低版本 Hadoop 就会出现这种问题。

报错

报错信息如下:

$ schematool -initSchema -dbType mysql
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/apache-hive-3.1.3-bin/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/hadoop-3.2.2/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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]
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
        at org.apache.hadoop.conf.Configuration.set(Configuration.java:1357)
        at org.apache.hadoop.conf.Configuration.set(Configuration.java:1338)
        at org.apache.hadoop.mapred.JobConf.setJar(JobConf.java:536)
        at org.apache.hadoop.mapred.JobConf.setJarByClass(JobConf.java:554)
        at org.apache.hadoop.mapred.JobConf.<init>(JobConf.java:448)
        at org.apache.hadoop.hive.conf.HiveConf.initialize(HiveConf.java:5144)
        at org.apache.hadoop.hive.conf.HiveConf.<init>(HiveConf.java:5107)
        at org.apache.hive.beeline.HiveSchemaTool.<init>(HiveSchemaTool.java:96)
        at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:1473)
        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:323)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:236)

解决

这是因为不同版本 Hadoop 内自带的组件版本不同,可以查找下相关的组件版本:

hadoop@hadoop06:/data/apache-hive-3.1.3-bin$ find /data/apache-hive-3.1.3-bin/ -name "*guava*"
/data/apache-hive-3.1.3-bin/lib/guava-19.0.jar
/data/apache-hive-3.1.3-bin/lib/jersey-guava-2.25.1.jar
hadoop@hadoop06:/data/apache-hive-3.1.3-bin$ find /data/hadoop-3.2.2/ -name "*guava*"
/data/hadoop-3.2.2/share/hadoop/common/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
/data/hadoop-3.2.2/share/hadoop/common/lib/guava-27.0-jre.jar
/data/hadoop-3.2.2/share/hadoop/hdfs/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
/data/hadoop-3.2.2/share/hadoop/hdfs/lib/guava-27.0-jre.jar

可以看到版本确实不符,使用高版本的代替低版本 guava。

cd /data/apache-hive-3.1.3-bin/lib/
mv guava-19.0.jar guava-19.0.jar.bak
cp -a /data/hadoop-3.2.2/share/hadoop/hdfs/lib/guava-27.0-jre.jar .

然后重启服务即可看到服务可以正常启动,问题解决。


附录

参考链接

本文撰写于一年前,如出现图片失效或有任何问题,请在下方留言。博主看到后将及时修正,谢谢!
禁用 / 当前已拒绝评论,仅可查看「历史评论」。