HDFS java API TROUBLESHOOTING

官方文档
https://hadoop.apache.org/docs/r2.9.2/hadoop-project-dist/hadoop-common/SingleCluster.html

配置免密登录,用于 nameNode 与 dataNode 通信

ssh-keygen -t rsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

验证ssh,不需要输入密码即可登录。登录后执行 exit 退出。

ssh localhost
exist


etc/hadoop/core-site.xml

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://192.168.3.127:8020</value>
    </property>
</configuration>


etc/hadoop/hdfs-site.xml

<configuration>
    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>

    <property>
        <name>dfs.name.dir</name>
        <value>file:/home/hdfs/name</value>
        <description>namenode上存储hdfs名字空间元数据 </description> 
    </property>

    <property>
        <name>dfs.data.dir</name>
        <value>file:/home/hdfs/data</value>
        <description>datanode上数据块的物理存储位置</description>
    </property>
</configuration>


开放端口

firewall-cmd --add-port=8020/tcp --permanent
firewall-cmd --add-port=50010/tcp --permanent
firewall-cmd --add-port=50070/tcp --permanent
firewall-cmd --reload

 

1. java.lang.IllegalArgumentException: URI has an authority component
在执行 `bin/hdfs namenode -format` 的时候报错。
检查 hdfs-site.xml 配置是否正确

<property>
<name>dfs.name.dir</name>
<value>file:/home/hdfs/name</value>
<description>namenode上存储hdfs名字空间元数据 </description> 
</property>

<property>
<name>dfs.data.dir</name>
<value>file:/home/hdfs/data</value>
<description>datanode上数据块的物理存储位置</description>
</property>

 

2. java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.
解压 hadoop-2.9.2.tar.gz 到 D:\app\

System.setProperty("hadoop.home.dir", "D:\\app\\hadoop-2.9.2");

 

3. java.io.FileNotFoundException: Could not locate Hadoop executable: D:\app\hadoop-2.9.2\bin\winutils.exe
下载 winutils.exe 放到 {HADOOP_HOME}\bin\ 下

 

4. Permission denied: user=xxx, access=WRITE, inode="/":root:supergroup:drwxr-xr-x

/**
* 解决无权限访问,设置远程hadoop的linux用户名称
*/
private static final String USER = "root";

fileSystem = FileSystem.get(new URI(HDFS_PATH), configuration, USER);

5. java.net.ConnectException: Connection timed out: no further information 与 org.apache.hadoop.ipc.RemoteException: File /hello-hadoop.md 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.

# 开放 dataNode端口
firewall-cmd --add-port=50010/tcp --permanent
firewall-cmd --reload

 

6. No FileSystem for scheme "hdfs"

 

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-hdfs</artifactId>
    <version>${org.apache.hadoop.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-common</artifactId>
    <version>${org.apache.hadoop.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-client</artifactId>
    <version>${org.apache.hadoop.version}</version>
</dependency>

 

有问题欢迎留言交流。

技术交流群:282575808

--------------------------------------

声明: 原创文章,未经允许,禁止转载!

--------------------------------------

posted @ 2019-07-23 19:03  景岳  阅读(357)  评论(0编辑  收藏  举报