1

我已经在 Ubuntu 上安装了 GridDB。我使用两台计算机:第一台计算机用作 GridDB 服务器,第二台计算机用作 java 客户端,当我尝试从第二台计算机连接到 GridDB 时,它会抛出异常,但是当我在服务器端运行 java 代码时它工作得很好。有什么问题?我使用本教程

这是简单的java代码:

import java.util.Arrays;
import java.util.Properties;

import com.toshiba.mwcloud.gs.Collection;
import com.toshiba.mwcloud.gs.GSException;
import com.toshiba.mwcloud.gs.GridStore;
import com.toshiba.mwcloud.gs.GridStoreFactory;
import com.toshiba.mwcloud.gs.Query;
import com.toshiba.mwcloud.gs.RowKey;
import com.toshiba.mwcloud.gs.RowSet;


// Operaton on Collection data
public class Sample1 {

    static class Person {
        @RowKey String name;
        boolean status;
        long count;
        byte[] lob;
    }

    public static void main(String[] args) throws GSException {

        // Get a GridStore instance
        Properties props = new Properties();
        props.setProperty("notificationAddress", "239.0.0.1");
        props.setProperty("notificationPort", "31999");
        props.setProperty("clusterName", "defaultCluster");
        props.setProperty("user", "admin");
        props.setProperty("password", "admin");
        GridStore store = GridStoreFactory.getInstance().getGridStore(props);

        // Create a Collection (Delete if schema setting is NULL)
        Collection<String, Person> col = store.putCollection("col01", Person.class);


    }

}

这是例外,当我尝试从第二台计算机连接时:

com.toshiba.mwcloud.gs.common.GSConnectionException: [145028:JC_BAD_CONNECTION] Failed to connect (address=/127.0.1.1:10001, reason=Connection refused: connect)
    at com.toshiba.mwcloud.gs.subnet.NodeConnection.<init>(NodeConnection.java:142)
    at com.toshiba.mwcloud.gs.subnet.NodeConnectionPool.resolve(NodeConnectionPool.java:163)
    at com.toshiba.mwcloud.gs.subnet.NodeResolver.updateConnectionAndClusterInfo(NodeResolver.java:644)
    at com.toshiba.mwcloud.gs.subnet.NodeResolver.prepareConnectionAndClusterInfo(NodeResolver.java:529)
    at com.toshiba.mwcloud.gs.subnet.NodeResolver.getPartitionCount(NodeResolver.java:205)
    at com.toshiba.mwcloud.gs.subnet.GridStoreChannel$5.execute(GridStoreChannel.java:2106)
    at com.toshiba.mwcloud.gs.subnet.GridStoreChannel.executeStatement(GridStoreChannel.java:1675)
    at com.toshiba.mwcloud.gs.subnet.GridStoreChannel.executeResolver(GridStoreChannel.java:1912)
    at com.toshiba.mwcloud.gs.subnet.GridStoreChannel.resolvePartitionId(GridStoreChannel.java:2103)
    at com.toshiba.mwcloud.gs.subnet.SubnetGridStore.putContainer(SubnetGridStore.java:968)
    at com.toshiba.mwcloud.gs.subnet.SubnetGridStore.putCollection(SubnetGridStore.java:1024)
    at com.toshiba.mwcloud.gs.subnet.SubnetGridStore.putCollection(SubnetGridStore.java:787)
    at com.toshiba.mwcloud.gs.subnet.SubnetGridStore.putCollection(SubnetGridStore.java:98)
    at pac.Main.main(Main.java:39)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at com.toshiba.mwcloud.gs.subnet.NodeConnection.<init>(NodeConnection.java:129)
    ... 13 more
4

2 回答 2

1

239.0.0.1 是一个多播地址。并且通常需要对操作系统、路由器设置执行一些额外的步骤才能启用多播。

因此检查是否启用了多播是有意义的:https ://serverfault.com/questions/294207/how-can-i-test-multicast-udp-connectivity-between-two-servers

您还可以检查 GridDB 节点在集群中注册的 IP/端口是否可访问。可以使用以下命令获取 IP 地址:

$ gs_stat -u admin/admin
于 2020-01-16T10:08:28.687 回答
1

引起:java.net.ConnectException:连接被拒绝:连接

问题是服务器不接受来自第二台机器的连接。这可能是由于很多事情。最有可能的是:

  • 您的服务器未在其外部 IP 地址上侦听请求。(例如,DB 可能只监听 127.0.0.1。)在服务器上,检查哪些服务正在监听服务器的外部 IP 地址;例如https://www.tecmint.com/find-listening-ports-linux/

  • 您的客户端可能配置为与错误的服务器通信,或使用错误的端口。

  • 防火墙。(虽然正常的防火墙行为是丢弃连接数据包,导致不同的异常。)

还有其他可能性,但以上内容应该足以让您入门。


如果上述方法没有发现问题,您将需要采取以下措施:

  • 检查当您使用 TCP 诊断工具连接到该数据库服务器/端口时会发生什么。它是否在 TCP 级别连接?

  • 当客户端尝试连接到数据库时,使用网络数据包嗅探器查看 TCP 数据包发生了什么。

  • 检查您的路由表和 IP 表是否有奇怪的路由规则。如果您使用的是虚拟机,请检查管理程序级别。

于 2020-01-15T01:21:19.883 回答