core-site.xml 配置信息
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
from hdfs.client import Client
client = Client("http://localhost:9000", root="/", timeout=100, session=False)
result = client.list("/")
print result
如果访问core的配置的信息是无法访问,会有以下报错
It looks like you are making an HTTP request to a Hadoop IPC port. This is not the correct port for the web interface on this daemon.
这里要使用的是web可访问的管理页面的地址
hadoop3的 NameNode管理页面
http://localhost:9870可
如果启动了hdfs可直接浏览器打开
代码改为
from hdfs.client import Client
client = Client("http://localhost:9870", root="/", timeout=100, session=False)
result = client.list("/")
print result
如果要使用rpc 9000的端口的话
from snakebite.client import Client
client = Client("localhost", 9000, use_trash=False)
result = list(client.ls(['/']))
print result
本文介绍了在配置Hadoop的core-site.xml时,将默认名称节点设置为localhost:9000,并展示了如何通过Python的hdfs库访问HDFS。当尝试通过HTTP请求连接时,出现错误提示应使用Web接口的正确端口9870。修复方法是更改客户端连接地址为9870端口。同时,提供了使用snakebite库通过RPC方式连接9000端口的代码示例。

1898

被折叠的 条评论
为什么被折叠?



