无法从docker容器外部访问namenode

b1uwtaje  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(462)

我停靠了一个hadoop应用程序,并尝试从容器外部访问namenode,原因很明显。
我用dockerfile暴露了端口,使用:

EXPOSE 2122 9000

我从容器开始:

$ docker run -dit --rm --privileged --pid=host -p 2122:2122 -p 9000:9000 --name hnode ns/hnode

2122是我用于ssh的端口。我已经安装了ssh服务器,尝试了它,并且我能够从容器外部通过ssh进行连接。
我还向hadoop添加了使用这个ssh端口的选项 ENV HADOOP_SSH_OPTS="-p 2122" .
使用以下core-site.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>fs.default.name</name>
        <value>hdfs://localhost:9000</value>
    </property>
</configuration>

当我尝试从容器内部远程连接9000时,一切正常:

[hadoop@1f5c7934fe45 hadoop]$ telnet localhost 9000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

   |��☼►☻↑      ")org.apache.hadoop.ipc.RPC$VersionMismatch*>Server IPC version 9 cannot communicate with client version 130♫: @☺Connection closed by foreign host.

你清楚地看到它是另一端的namenode。
但是,当我尝试使用主机ip从容器内部telnet namenode使用的9000端口时,我得到:

[hadoop@1f5c7934fe45 hadoop]$ telnet 172.17.0.2 9000
Trying 172.17.0.2...
telnet: connect to address 172.17.0.2: Connection refused

即使ssh正在工作:

[hadoop@1f5c7934fe45 hadoop]$ telnet 172.17.0.2 2122
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4

Protocol mismatch.
Connection closed by foreign host.

为什么ssh可以工作,但hadoop的namenode却不行?

twh00eeo

twh00eeo1#

实际上,我只需要将主机的ip放在core-site.xml中,而不是localhost中:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>
    <property>
        <name>fs.default.name</name>
        <value>hdfs://172.17.0.2:9000</value>
    </property>
</configuration>

这样,我就可以用外部路由从内部远程连接namenode:

[hadoop@1f5c7934fe45 hadoop]$ telnet 172.17.0.2 9000
Trying 172.17.0.2...
Connected to 172.17.0.2.
Escape character is '^]'.

   |��☼►☻↑      ")org.apache.hadoop.ipc.RPC$VersionMismatch*>Server IPC version 9 cannot communicate with client version 100♫: @☺Connection closed by foreign host.

甚至从外面:

λ curl 192.168.56.1:9000
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.

我知道这些是错误,但是它们确认守护进程已应答并且可以访问。

相关问题