Hadoop操作HDFSAPI 错误org.apache.hadoop.ipc.RemoteException(java.io.IOException)

客户端操作HDFS的API的时候,出现如下错误

org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /hdfsapiv2/order_created.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

出现上面的错误:需要修改HADOOP的配置文件hdfs-site.xml,配置完记得重启

   <property>
        <name>dfs.datanode.use.datanode.hostname</name>
        <value>true</value>
    </property>

同时程序也要设置

URI uri = new URI("hdfs://ruozedata001:9000");
Configuration config = new Configuration();
/**
 * dfs.client.use.datanode.hostname 客户端使用hostname
 * dfs.datanode.use.datanode.hostname  datanode使用hostname
 * 一定要设置
 */
config.set("dfs.client.use.datanode.hostname","true");
/**
 * 设置副本数
 */
config.set("dfs.replication","1");
/**
 * 指定用户
 */
fileSystem = FileSystem.get(uri,config,"ruoze");

最后如果是云主机的话,记得要打开datanode通讯端口,The datanode server address and port for data transfer. 50010

你可能感兴趣的:(hadoop)