更新时间:2024-10-31 GMT+08:00
在本地Windows环境中调测HDFS程序
操作场景
在代码完成开发后,您可以在Windows开发环境中运行应用。本地和集群业务平面网络互通时,您可以直接在本地进行调测。
HDFS应用程序运行完成后,可直接通过运行结果查看应用程序运行情况,也可以通过HDFS日志获取应用运行情况。
在本地Windows环境中调测HDFS程序
- 在开发环境中(例如IntelliJ IDEA中),分别选中以下两个工程运行程序:
- 选中HdfsExample.java,右键工程,选择 运行应用工程。
- 选中ColocationExample.java,右键工程,选择 运行应用工程。
- 在HDFS任务运行过程中禁止重启HDFS服务,否则可能会导致任务失败。
- 在运行Colocation工程时,HDFS的配置项fs.defaultFS不能配置为viewfs://ClusterX。
设置系统的环境变量说明
Hadoop在安全认证的时候,需要获取客户端所在主机的域名(Default Realm,从环境变量USERDNSDOMAIN中获取)。如果该主机没有域名,则运行样例程序会有如下报错:
此时需要用户设置系统的环境变量USERDNSDOMAIN以规避该问题,具体如下:
查看调测结果
- 查看运行结果获取应用运行情况
- HdfsExample Windows样例程序运行结果如下所示。
... 1308 [main] INFO org.apache.hadoop.security.UserGroupInformation - Login successful for user hdfsDevelop using keytab file 1308 [main] INFO com.huawei.hadoop.security.LoginUtil - Login success!!!!!!!!!!!!!! 2040 [main] WARN org.apache.hadoop.hdfs.shortcircuit.DomainSocketFactory - The short-circuit local reads feature cannot be used because UNIX Domain sockets are not available on Windows. 3006 [main] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to create path /user/hdfs-examples 3131 [main] WARN org.apache.hadoop.util.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 3598 [main] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to write. 4408 [main] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to append. 5015 [main] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - result is : hi, I am bigdata. It is successful if you can see me.I append this content. 5015 [main] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to read. 5077 [main] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to delete the file /user/hdfs-examples\test.txt 5186 [main] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to delete path /user/hdfs-examples 5311 [hdfs_example_0] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to create path /user/hdfs-examples/hdfs_example_0 5311 [hdfs_example_1] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to create path /user/hdfs-examples/hdfs_example_1 5669 [hdfs_example_1] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to write. 5669 [hdfs_example_0] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to write. 7258 [hdfs_example_1] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to append. 7741 [hdfs_example_0] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to append. 7896 [hdfs_example_1] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - result is : hi, I am bigdata. It is successful if you can see me.I append this content. 7896 [hdfs_example_1] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to read. 7959 [hdfs_example_1] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to delete the file /user/hdfs-examples/hdfs_example_1\test.txt 8068 [hdfs_example_1] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to delete path /user/hdfs-examples/hdfs_example_1 8364 [hdfs_example_0] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - result is : hi, I am bigdata. It is successful if you can see me.I append this content. 8364 [hdfs_example_0] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to read. 8426 [hdfs_example_0] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to delete the file /user/hdfs-examples/hdfs_example_0\test.txt 8535 [hdfs_example_0] INFO com.huawei.bigdata.hdfs.examples.HdfsExample - success to delete path /user/hdfs-examples/hdfs_example_0 ...
在Windows环境运行样例代码时可能会出现下面的异常,但是不影响业务:
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.
- ColocationExample Windows样例程序运行结果如下所示。
... 945 [main] INFO org.apache.hadoop.security.UserGroupInformation - Login successful for user hdfsDeveloper using keytab file user.keytab 945 [main] INFO com.huawei.hadoop.security.LoginUtil - Login success!!!!!!!!!!!!!! 945 [main] INFO com.huawei.hadoop.security.LoginUtil - JaasConfiguration loginContextName=Client principal=hdfsDeveloper useTicketCache=false keytabFile=XXX\sample_project\src\hdfs-example-security\conf\user.keytab 946 [main] INFO com.huawei.hadoop.security.KerberosUtil - Get default realm successfully, the realm is : HADOOP.COM ... Create Group has finished. Put file is running... Put file has finished. Delete file is running... Delete file has finished. Delete Group is running... Delete Group has finished. 4946 [main-EventThread] INFO org.apache.zookeeper.ClientCnxn - EventThread shut down for connection: 0x440751cb41a4d415 4946 [main] INFO org.apache.zookeeper.ZooKeeper - Connection: 0x440751cb41a4d415 closed ...
- HdfsExample Windows样例程序运行结果如下所示。
- 查看HDFS日志获取应用运行情况
您可以查看HDFS的NameNode日志了解应用运行情况,并根据日志信息调整应用程序。
父主题: 调测HDFS应用