在cassandra中运行hadoop wordcount示例时出现异常

368yc8dk  于 2021-06-04  发布在  Hadoop
关注(0)|答案(1)|浏览(422)

我有一个2节点的集群,当我在中运行单词计数示例时,我在这些节点上正确地安装了hadoop和cassandra[https://github.com/apache/cassandra/tree/trunk/examples/hadoop_cql3_word_count]
(首先运行wordcountsetup,然后从wordcount创建jar并在hadoop中运行)我得到一个异常:

Exception in thread "main" java.lang.NoClassDefFoundError:**com/datastax/driver/core/policies/LoadBalancingPolicy**
    at WordCount.run(WordCount.java:236)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
    at WordCount.main(WordCount.java:78)
    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.main(RunJar.java:212)
Caused by: java.lang.ClassNotFoundException: com.datastax.driver.core.policies.LoadBalancingPolicy
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 8 more
lc8prwob

lc8prwob1#

mapreduce程序主要有两个部分。司机区,Map/缩小区。驱动程序部分将在触发mapreduce程序的同一台机器上执行,而map/reduce部分将在任何从属节点上执行。在这里,您面临noclassdeffounderror,这意味着在驱动程序代码或mapper/reduce代码中,类com.datastax.driver.core.policies.loadbalancingpolicy都是不可访问的。
如果驱动程序代码中出现异常,则在执行hadoop命令之前设置环境变量。需要找到包含类com.datastax.driver.core.policies.loadbalancingpolicy的jar在占位符中指定jar完整路径

export HADOOP_CLASSPATH=<_JAR_NAME>;     #

如果异常来自mapper/reducer,则上述选项将不起作用。在这种情况下,通过在jar(myjar.jar)中添加依赖jar来创建一个胖jar
或者使用hadoop-libjars选项(需要重写主类中的toolrunner类)

相关问题