java 操作上传下载 HDFS:could only be replicated to 0 nodes instead of minReplication (=1). There are 1 da

来源:互联网 发布:服务器80端口被占用 编辑:程序博客网 时间:2024/05/22 12:40

环境

阿里云服务器
伪分布模式
版本:2.9.0,java 1.8
配置:http://blog.csdn.net/u012453843/article/details/52431742

代码

//上传文件public static void main(String[] args) throws Exception {        Configuration configuration = new Configuration();        //123.56.xxx.xxx 为阿里云服务器公网 IP        FileSystem fs = FileSystem.get(URI.create("hdfs://123.56.xxx.xxx:9000/text.txt"), configuration, "root");        InputStream in = new FileInputStream("D://hdfs_demo1/123.txt");        OutputStream outputStream = fs.create(new Path("hdfs://123.56.xxx.xxx:9000/text.txt"), new Progressable() {            public void progress() {                System.out.print(".");            }        });        IOUtils.copyBytes(in, outputStream, 4096, true);    }

出现错误

Exception in thread "main" org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /text.txt could only be replicated to 0 nodes instead of minReplication (=1).  There are 1 datanode(s) running and 1 node(s) are excluded in this operation.    at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(BlockManager.java:1797)    at org.apache.hadoop.hdfs.server.namenode.FSDirWriteFileOp.chooseTargetForNewBlock(FSDirWriteFileOp.java:265)    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:2559)    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:846)    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:510)    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:503)    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:989)    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:868)    at org.apache.hadoop.ipc.Server$RpcCall.run(Server.java:814)    at java.security.AccessController.doPrivileged(Native Method)    at javax.security.auth.Subject.doAs(Subject.java:422)    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1886)    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2603)    at org.apache.hadoop.ipc.Client.getRpcResponse(Client.java:1493)    at org.apache.hadoop.ipc.Client.call(Client.java:1439)    at org.apache.hadoop.ipc.Client.call(Client.java:1349)    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:227)    at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:116)    at com.sun.proxy.$Proxy10.addBlock(Unknown Source)    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:444)    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:497)    at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:422)    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeMethod(RetryInvocationHandler.java:165)    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invoke(RetryInvocationHandler.java:157)    at org.apache.hadoop.io.retry.RetryInvocationHandler$Call.invokeOnce(RetryInvocationHandler.java:95)    at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:359)    at com.sun.proxy.$Proxy11.addBlock(Unknown Source)    at org.apache.hadoop.hdfs.DataStreamer.locateFollowingBlock(DataStreamer.java:1845)    at org.apache.hadoop.hdfs.DataStreamer.nextBlockOutputStream(DataStreamer.java:1645)    at org.apache.hadoop.hdfs.DataStreamer.run(DataStreamer.java:710)

解决方法

  • 防火墙关闭(我没有这个问题,但是很多人这个会影响)
  • 添加 configuration.set("dfs.client.use.datanode.hostname", "true");这句代码
  • 如果下载也出现问题如 org.apache.hadoop.hdfs.BlockMissingException: Could not obtain block: BP-115793501-172.17.162.27-1512710701892:blk_1073741825_1001 file=/hdfs.xml ,确定排除网上其他什么原因(datanode 没有启动之类的),也可以添加上面那行代码尝试。
阅读全文
0 0
原创粉丝点击