通过Java接口远程访问ArangoDB

Remote access to ArangoDB through Java Interface

我开发了一个 Java 应用程序,它使用 ArangoDB 作为后端数据库(使用 ArangoDB Java-Driver/Interface 访问 ArangoDB)。

一切都很好,直到我的 ArangoDB 和应用程序驻留在同一台机器上。

一旦我将 ArangoDB 移动到远程机器(专用服务器),我的应用程序就无法访问它:(

我在一些属性文件中提供了我的远程机器详细信息(ArangoDB 服务器),并在创建 ArangoDriver 对象时将该文件位置提供给 ArangoConfigure 构造函数。但我仍然无法访问 ArangoDB :(

我的一小段代码如下:

protected static ArangoConfigure getConfiguration() {
        //ArangoConfigure configure = new ArangoConfigure();
        ArangoConfigure configure = new
ArangoConfigure("/Volumes/Official/ZLabs/arangodb.properties");
                configure.init();

        return configure;   }

    protected static ArangoDriver getArangoDriver(ArangoConfigure
configuration) {        return new ArangoDriver(configuration);     }

请在这方面帮助我。

等待您的回复。

谢谢和最好的问候, - 鲯鳅鱼

如果 Aranngodb Java 驱动程序无法打开或解析 /Volumes/Official/ZLabs/arangodb.properties 它会发出一条日志消息。

如果 arangodb 属性看起来像这样:

port=8529
host=192.168.22.17
user=root
password=OpenSesame
enableCURLLogger=false

您开始 walking up the OSI model 调试 TCP 连接问题,以规避由于防火墙、路由等可能导致的连接问题。 一是使用常用的telnet命令来测试服务器的可用性:

telnet 192.168.22.17 8529
Trying 192.168.22.17...

如果它永远坐在那里,你很可能有防火墙过滤掉你,你最终会得到:

telnet: Unable to connect to remote host: Connection timed out

如果它立即退出:

telnet: Unable to connect to remote host: Connection refused

服务器似乎没有应答。

然后在服务器端您可以检查服务是否绑定了您尝试连接的端口(8529):

netstat -alpnt |grep 8529
tcp        0      0 0.0.0.0:8529            0.0.0.0:*               LISTEN      19912/arangod   

如果您看到它绑定 127.0.0.1:8529,您将无法远程连接它,需要像这样更改 arangod.conf:

[server]
endpoint = tcp://0.0.0.0:8529

然后重启ArangoDB。然后,您应该能够看到类似这样的内容:

telnet 192.168.22.17 8529
Trying 192.168.22.17...
Connected to 192.168.22.17.
Escape character is '^]'. <start to type now: >
GET / HTTP/1.0

<server should reply:>
HTTP/1.1 301 Moved Permanently
Location: /_db/_system/_admin/aardvark/index.html
Content-Type: text/html
Server: ArangoDB
Connection: Close
Content-Length: 197

<html><head><title>Moved</title></head><body><h1>Moved</h1>
<p>This page has moved to <a href="/_db/_system/_admin/aardvark/index.html">/_db/_system/_admin/aardvark/index.html</a>.
</p></body></html>Connection closed by foreign host.

首先感谢@dothebart 的帮助。

@dothebart,在我发帖之前,我已经检查了你提到的所有细节。唯一遗漏的是 HTTP 连接,感谢您指出这一点。

实际上,下面的代码更改已经解决了我的问题。

前面的代码:

ArangoConfigure configure = new ArangoConfigure("/home/arango.properties");
configure.init();
ArangoDriver driver = new ArangoDriver(configuration);

修改后的代码:

ArangoConfigure configure = new ArangoConfigure("/home/arango.properties");
ArangoHost hostObj = new ArangoHost(<IP-Address>, 8529);
configure.setArangoHost(hostObj);
configure.setUser(<user-name>);
configure.setPassword(<password>);
configure.init();
ArangoDriver driver = new ArangoDriver(configuration);

再次设置主机、用户名和密码使其正常工作:(

文件里有所有的细节,那我为什么要再提供一次。我没看懂。

@dothebart 我找不到日志文件,请告诉我在哪里可以找到它。

类路径中似乎没有找到属性文件。

日志文件的路径应在项目的日志配置文件中配置。 例如,您的项目可能会使用 Logback (logback.xml) or another slf4j 实现。