【问题标题】:Error when trying to write to hdfs: Server IPC version 9 cannot communicate with client version 4尝试写入 hdfs 时出错:服务器 IPC 版本 9 无法与客户端版本 4 通信
【发布时间】:2014-07-01 08:20:31
【问题描述】:

我正在尝试使用 scala 将文件写入 hdfs,但我不断收到以下错误

Caused by: org.apache.hadoop.ipc.RemoteException: Server IPC version 9 cannot communicate with client version 4
at org.apache.hadoop.ipc.Client.call(Client.java:1113)
at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:229)
at com.sun.proxy.$Proxy1.getProtocolVersion(Unknown Source)
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.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:85)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:62)
at com.sun.proxy.$Proxy1.getProtocolVersion(Unknown Source)
at org.apache.hadoop.ipc.RPC.checkVersion(RPC.java:422)
at org.apache.hadoop.hdfs.DFSClient.createNamenode(DFSClient.java:183)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:281)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:245)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:100)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1446)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:67)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1464)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:263)
at bcomposes.twitter.Util$.<init>(TwitterStream.scala:39)
at bcomposes.twitter.Util$.<clinit>(TwitterStream.scala)
at bcomposes.twitter.StatusStreamer$.main(TwitterStream.scala:17)
at bcomposes.twitter.StatusStreamer.main(TwitterStream.scala)
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)

我在this tutorial 之后安装了hadoop。下面的代码是我用来向 hdfs 插入示例文件的代码。

val configuration = new Configuration();
val hdfs = FileSystem.get( new URI( "hdfs://192.168.11.153:54310" ), configuration );
val file = new Path("hdfs://192.168.11.153:54310/s2013/batch/table.html");
if ( hdfs.exists( file )) { hdfs.delete( file, true ); } 
val os = hdfs.create( file);
val br = new BufferedWriter( new OutputStreamWriter( os, "UTF-8" ) );
br.write("Hello World");
br.close();
hdfs.close();

Hadoop版本是2.4.0,我使用的hadoop库版本是1.2.1。我应该做些什么改变才能完成这项工作?

【问题讨论】:

    标签: scala hadoop hdfs


    【解决方案1】:

    如错误消息中所述 Server IPC version 9 cannot communicate with client version 4 您的服务器的版本比您的客户端稍新。您必须降级您的 hadoop 集群(很可能不是一个选项)或将您的客户端库从 1.2.1 升级到 2.x 版本。

    【讨论】:

    【解决方案2】:

    我在使用 Hadoop 2.3 时遇到了同样的问题,我在 build.sbt 文件中添加了以下几行来解决它:

    libraryDependencies += "org.apache.hadoop" % "hadoop-client" % "2.3.0"
    
    libraryDependencies += "org.apache.hadoop" % "hadoop-hdfs" % "2.3.0"
    

    所以我认为在你的情况下你使用 2.4.0 版本。

    PS:它也适用于您的代码示例。我希望它会有所帮助

    【讨论】:

    • 请给出build.sbt文件的位置。
    • 您使用的是哪个构建工具? SBT 运气好吗?
    • hadoop2.5.0 和 eclipse kepler 版本。
    • Maven、gradle 还是 SBT?还是你不知道我在说什么?
    • 我是 hadoop/hdfs 的新手。我也不知道这三个工具。但我想告诉你的是我想在 eclipse 中运行 java 程序,它将数据存储在 hdfs 中,但我陷入了这个错误。线程“主”org.apache.hadoop.ipc.RemoteException 中的异常:服务器 IPC 版本 9 无法与客户端版本 4 通信。
    【解决方案3】:

    hadoopspark versions 应该是同步的。 (就我而言,我正在使用 spark-1.2.0hadoop 2.2.0

    第 1 步 - 转到 $SPARK_HOME

    第 2 步 - 只需 mvn build spark with the version of hadoop client you want,

    mvn -Pyarn -Phadoop-2.2 -Dhadoop.version=2.2.0 -DskipTests clean package
    

    第 3 步 - spark 项目也应该有合适的 spark 版本,

    name := "smartad-spark-songplaycount"
    
    version := "1.0"
    
    scalaVersion := "2.10.4"
    
    //libraryDependencies += "org.apache.spark" %% "spark-core" % "1.1.1"
    libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.2.0"
    
    libraryDependencies += "org.apache.hadoop" % "hadoop-client" % "2.2.0"
    
    libraryDependencies += "org.apache.hadoop" % "hadoop-hdfs" % "2.2.0"
    
    resolvers += "Akka Repository" at "http://repo.akka.io/releases/"
    

    参考文献

    Building apache spark with mvn

    【讨论】:

      猜你喜欢
      • 2015-03-19
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 2013-09-29
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      相关资源
      最近更新 更多