HDFS的常用操作及其相关问题

在Hadoop的安装目录下,查看hdfs下的文件的命令:

./bin/hdfs dfs -ls /

创建新的文件目录:

./bin/hdfs dfs -mkdir /a

上传文件到指定的目录:

./bin/hdfs dfs -put a.txt /a

下载HDFS上的文件至本地:

./bin/hdfs dfs -get /input/a.txt ~

查看文件内容:

./bin/hdfs dfs -cat /input/a.txt

在IDEA中执行HDFS的相关操作可能出现的问题:

org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /a.txt could only be written to 0 of the 1 minReplication nodes. There are 1 datanode(s) running and 1 node(s) are excluded in this operation.

解决方法:在代码中添加如下代码

conf.set("dfs.client.use.datanode.hostname", "true");//添加此配置信息即可

添加此信息以后还报如下错误:

java.nio.channels.UnresolvedAddressException

需要在hosts文件中添加对应的配置信息

hosts文件的地址C:\Windows\System32\drivers\etc

在里边添加ip与主机名的映射关系


版权声明:本文为qq_48913319原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。