简体   繁体   English

无法从 docker 容器访问在 macOS 上运行的数据节点

[英]Access to datanode running on macOS from a docker container can't be established

I'm not experienced with HDFS and I've run into a problem related to HDFS running on my macbook.我对 HDFS 没有经验,我遇到了与在我的 macbook 上运行的 HDFS 相关的问题。 I have a HDFS client which is launched in a docker container, and every time I try to put or get data to/from HDFS from this container I get the following error:我有一个 HDFS 客户端,它在 docker 容器中启动,每次我尝试从该容器向 HDFS 放入或获取数据时,我都会收到以下错误:

hdfs dfs -put /core-site.xml hdfs://host.docker.internal:9000/abcs
21/03/02 07:28:47 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
21/03/02 07:28:48 INFO hdfs.DFSClient: Exception in createBlockOutputStream
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
    at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:530)
    at org.apache.hadoop.hdfs.DFSOutputStream.createSocketForPipeline(DFSOutputStream.java:1610)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.createBlockOutputStream(DFSOutputStream.java:1408)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1361)
    at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:588)
21/03/02 07:28:48 INFO hdfs.DFSClient: Abandoning BP-1485605719-127.0.0.1-1614607405999:blk_1073741832_1008
21/03/02 07:28:48 INFO hdfs.DFSClient: Excluding datanode 127.0.0.1:9866
21/03/02 07:28:48 WARN hdfs.DFSClient: DataStreamer Exception
org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /abcs/core-site.xml._COPYING_ 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.

It can be clearly seen that my client(container) receives the wrong IP address of the DataNode (127.0.0.1:9866), it should be something like 192.168.65.2:9866 ie host.docker.internal.可以清楚地看到我的客户端(容器)收到了错误的DataNode(127.0.0.1:9866)的IP地址,应该是192.168.65.2:9866,即host.Z05B6053C41A2130AFD6FC3B158BDA4E6。 or domain name of my laptop (ex. my-laptop)或我的笔记本电脑的域名(例如 my-laptop)

My core-site.xml: (of course my-laptop is binded to 127.0.0.1 in etc/hosts)我的 core-site.xml:(当然 my-laptop 绑定到 etc/hosts 中的 127.0.0.1)

<configuration>
    <property>         
        <name>fs.defaultFS</name>         
        <value>hdfs://my-laptop:9000</value>     
    </property>
    <property>
          <name>hadoop.tmp.dir</name>
          <value>/Users/Ian_Rakhmatullin/localHadoopTmp</value>
  </property>
</configuration>

hdfs-site.xml: hdfs-site.xml:

<configuration>
    <property>         
        <name>dfs.replication</name>        
         <value>1</value>    
     </property>
     <property>
        <name>dfs.permissions.enabled</name>
        <value>false</value>
    </property>
    <property>
        <name>dfs.client.use.datanode.hostname</name>
        <value>true</value>
    </property>
     <property>
        <name>dfs.datanode.use.datanode.hostname</name>
        <value>true</value>
    </property>
    <property>
        <name>dfs.datanode.address</name>
        <value>my-laptop:9866</value>
    </property>
    <property>
        <name>dfs.datanode.http.address</name>
        <value>my-laptop:9864</value>
    </property>
    <property>
        <name>dfs.datanode.ipc.address</name>
        <value>my-laptop:9867</value>
    </property>
</configuration>

One more thing that confuses me is that through HDFS webUI I can see that DataNode is running on localhost:9866 (127.0.0.1:9866) , but I expect "my-laptop:9866" as well.让我感到困惑的另一件事是,通过 HDFS webUI,我可以看到 DataNode 正在localhost:9866 (127.0.0.1:9866)上运行,但我也期望“my-laptop:9866”。

Does anyone have any thoughts how to resolve this issue?有没有人有任何想法如何解决这个问题? Thank you.谢谢你。

Seems like I've solved this problem, by following these steps:好像我已经通过以下步骤解决了这个问题:

  1. Add dfs.datanode.hostname property in your hdfs在 hdfs 中添加 dfs.datanode.hostname 属性

hdfs-site xml: hdfs 站点 xml:

    <property>         
        <name>dfs.replication</name>        
         <value>1</value>    
    </property>
    <property>
        <name>dfs.permissions.enabled</name>
        <value>false</value>
    </property>
    <property>
        <name>dfs.client.use.datanode.hostname</name>
        <value>true</value>
    </property>
    <property>
        <name>dfs.datanode.use.datanode.hostname</name>
        <value>true</value>
    </property> 
    <property>
        <name>dfs.datanode.hostname</name>
        <value>my-laptop</value>
    </property> 

core-site xml the same as it is in my question.核心站点 xml 与我的问题相同。

  1. Add dfs.client.use.datanode.hostname to your hdfs-site.xml for a hdfs client;将 dfs.client.use.datanode.hostname 添加到您的 hdfs-site.xml 用于 hdfs 客户端;
    <property>
        <name>dfs.client.use.datanode.hostname</name>
        <value>true</value>
    </property>
  1. Map DNS name (my-laptop in my case) to the IP address of your docker host (host.docker.internal in my case -> 192.168.65.2) in container's etc/hosts Map DNS name (my-laptop in my case) to the IP address of your docker host (host.docker.internal in my case -> 192.168.65.2) in container's etc/hosts
192.168.65.2 my-laptop

With this approach Namenode will return host name for your Datanode to the hdfs client, and then, the client will use your mapping to host.docker.internal.通过这种方法,Namenode 会将您的 Datanode 的主机名返回给 hdfs 客户端,然后,客户端将使用您的映射到 host.docker.internal。 And this is what I needed.这就是我所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到 jenkins docker 容器内的 docker 容器 MacOS - Can't connect to docker inside jenkins docker container MacOS 使用 --network=host 在 MacOS 上运行 docker 容器时如何访问主机上的端口? - How to access a port on the host machine when running docker container on MacOS with --network=host? 我无法在 MacOS 上使用 Docker 在 http://localhost:8080 访问 Jenkins - I can't access Jenkins at http://localhost:8080 with Docker on MacOS 如何从网络上的 docker 容器访问在本地主机上运行的网络服务器? - How to access webserver running on localhost from a docker container on a network? 如何从其他主机访问在MacOSX上运行的docker容器? - How to access a docker container running on MacOSX from another host? 从Docker容器登录macOS中的syslog / console? - Log to syslog / console in macOS from Docker container? Docker 无法连接到 docker daemon macOS - Docker can't connect to docker daemon macOS 无法在 OSX 上的端口 80 上访问 docker 容器 - Can't access docker container on port 80 on OSX 在以--network host模式运行时,为什么不能从容器主机访问我的服务? - Why can't I access my service from my container host when running with `--network host` mode? 如何以非 root 用户身份从 docker 容器内部访问 /var/run/docker.sock? (MacOS 主机) - How to access /var/run/docker.sock from inside a docker container as a non-root user? (MacOS Host)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM