在 docker 实例中连接到 Neo4j 的奇怪的 neo4j-shell 问题 [英] Strange neo4j-shell issue connecting to Neo4j in a docker instance

查看:60
本文介绍了在 docker 实例中连接到 Neo4j 的奇怪的 neo4j-shell 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在连接到在 docker 实例中运行的 Neo4j 实例时遇到了一个非常奇怪的问题.但首先,这是我的设置:

一切都在 MacOS 上运行.我使用 boot2docker,所以实际的 Docker 实例在 VirtualBox 中运行.我可以用 Neo4j 2.1.5 和 Neo4j 2.2.0-M04 重现这个问题.此外,我通过自制软件在本地安装了 Neo4j,它是 2.1.7 版.安装它以提供一个neo4j-shell.docker 实例可以通过 192.168.59.104 从外部访问.docker 实例本身有一个 172.17.0.x IP 地址.

问题:我尝试像这样连接neo4j-shell:neo4j-shell -v -host 192.168.59.104 -port 1337 -name shell.几分钟后,它失败了:

错误(-v 用于扩展信息):连接被拒绝java.rmi.ConnectException:连接拒绝主机:172.17.0.2;嵌套异常是:java.net.ConnectException:操作超时在 sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)在 sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)在 sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)在 sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)在 java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)在 java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)在 com.sun.proxy.$Proxy1.welcome(来源不明)在 org.neo4j.shell.impl.AbstractClient.sayHi(AbstractClient.java:215)在 org.neo4j.shell.impl.RemoteClient.findRemoteServer(RemoteClient.java:63)在 org.neo4j.shell.impl.RemoteClient.(RemoteClient.java:55)在 org.neo4j.shell.impl.RemoteClient.(RemoteClient.java:43)在 org.neo4j.shell.ShellLobby.newClient(ShellLobby.java:165)在 org.neo4j.shell.StartClient.startRemote(StartClient.java:297)在 org.neo4j.shell.StartClient.start(StartClient.java:175)在 org.neo4j.shell.StartClient.main(StartClient.java:120)引起:java.net.ConnectException:操作超时在 java.net.PlainSocketImpl.socketConnect(Native Method)在 java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)在 java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)在 java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)在 java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)在 java.net.Socket.connect(Socket.java:589)在 java.net.Socket.connect(Socket.java:538)在 java.net.Socket.(Socket.java:434)在 java.net.Socket.(Socket.java:211)在 sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)在 sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)在 sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)……还有 14 个

有趣的是,它通过尝试连接 172.17.0.2 而不是提供的 IP 地址而失败.

到目前为止我做了什么:

  • 仔细检查neo4j.properties 是否正确
    • remote_shell_host=0.0.0.0 已设置
    • remote_shell_port=1337 已设置
  • 使用 docker ps 检查端口是否正确公开:<前>容器 ID 图像命令创建状态端口名称099cfd1b8018 daneroo/neo4j:latest "/bin/bash -c/launc 3 分钟前向上 3 分钟 0.0.0.0:1337->1337/tcp, 0.0.0.0:7474->7474/tcp neo4j

  • 一些 Google 和 SO 搜索,但没有任何成功.
  • 不同的 neo4j 版本和 docker 镜像
  • 使用 telnet 192.168.59.104 1337 进行基本连接检查.这是成功的.
  • 在今天的 neo4j 聚会上与 Mark Needham 见面

那么,我错过了什么吗?从理论上讲,每次您可以通过 Neo4j 实例无法看到的另一个 IP 地址访问 Neo4j 时,都会发生这种情况(例如,如果您在家中在 IP 为 192.168.xy 的机器上运行 Neo4j 实例,并尝试通过您的公共地址访问它)您此时拥有的 IP).在 Neo4j 环境之外运行的客户端在哪里获取内部 IP 地址?有没有办法解决这个问题?

解决方案

我认为这可能与 shell 用于与 Neo4j 通信的 RMI 协议有关.Afaik RMI 还使用一些额外的端口,它可能会重定向初始请求.您可能想尝试在 neo4j-wrapper.conf 中设置 Java 中的系统属性:-Djava.rmi.server.hostname=192.168.59.104

见:

I have a really strange problem connecting to a Neo4j instance running in a docker instance. But first things first, here is my set up:

Everything runs on a MacOS. I use boot2docker, so the actual Docker instances run in a VirtualBox. I am able to reproduce this issue with Neo4j 2.1.5 and with Neo4j 2.2.0-M04. Additionally, I installed Neo4j locally via homebrew and it is version 2.1.7. It is installed to have a neo4j-shell available. The docker instances are accessible from the outside via 192.168.59.104. The docker instance itself has a 172.17.0.x IP address.

The problem: I try to connect with neo4j-shell like this: neo4j-shell -v -host 192.168.59.104 -port 1337 -name shell. After a couple of minutes, it fails with:

ERROR (-v for expanded information):
    Connection refused
java.rmi.ConnectException: Connection refused to host: 172.17.0.2; nested exception is:
    java.net.ConnectException: Operation timed out
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
    at com.sun.proxy.$Proxy1.welcome(Unknown Source)
    at org.neo4j.shell.impl.AbstractClient.sayHi(AbstractClient.java:215)
    at org.neo4j.shell.impl.RemoteClient.findRemoteServer(RemoteClient.java:63)
    at org.neo4j.shell.impl.RemoteClient.<init>(RemoteClient.java:55)
    at org.neo4j.shell.impl.RemoteClient.<init>(RemoteClient.java:43)
    at org.neo4j.shell.ShellLobby.newClient(ShellLobby.java:165)
    at org.neo4j.shell.StartClient.startRemote(StartClient.java:297)
    at org.neo4j.shell.StartClient.start(StartClient.java:175)
    at org.neo4j.shell.StartClient.main(StartClient.java:120)
Caused by: java.net.ConnectException: Operation timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at java.net.Socket.<init>(Socket.java:434)
    at java.net.Socket.<init>(Socket.java:211)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
    ... 14 more

The interesting part is, that it fails by trying to connect 172.17.0.2 instead of the provided IP address.

What I did so far:

  • Double check neo4j.properties are correct
    • remote_shell_host=0.0.0.0 is set
    • remote_shell_port=1337 is set
  • check the ports are exposed properly with docker ps:

    CONTAINER ID        IMAGE                  COMMAND                CREATED             STATUS              PORTS                                            NAMES
    099cfd1b8018        daneroo/neo4j:latest   "/bin/bash -c /launc   3 minutes ago       Up 3 minutes        0.0.0.0:1337->1337/tcp, 0.0.0.0:7474->7474/tcp   neo4j
    

  • Some Google and SO searches, but without any success.
  • Different neo4j versions and docker images
  • Basic connection checks with telnet 192.168.59.104 1337. This is successful.
  • Catch up with Mark Needham at todays neo4j meetup

So, do I miss something? In theory this should happen every time you can access the Neo4j through another IP address than the Neo4j instance can see (e.g. if you run a Neo4j instance at home on a machine with the IP 192.168.x.y and you try to access it via your public IP you have at this time). Where is the client, running outside the Neo4j environment, getting the internal IP address from? Is there a way to work around this issue?

解决方案

I think it might be related to the RMI protocol that the shell uses to communicate with Neo4j. Afaik RMI also uses some additional ports and it might redirect the initial request. there is a system property in Java that you might want to try to set in neo4j-wrapper.conf: -Djava.rmi.server.hostname=192.168.59.104

see:

这篇关于在 docker 实例中连接到 Neo4j 的奇怪的 neo4j-shell 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆