【问题标题】:All host(s) tried for query failed尝试查询的所有主机均失败
【发布时间】:2015-01-28 16:25:00
【问题描述】:

我使用 Google 计算引擎建立了一个由三个 cassandra 节点组成的集群。 运行“nodetool status”后,我得到:

antoniogallo88@cassandra-7m0w:~$ nodetool status
Datacenter: europe-west1
========================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address         Load       Tokens  Owns (effective)  Host ID                               Rack
UN  10.240.41.185   56.28 KB   256     33.2%             edf4c2c8-f746-4c86-8b1e-4d4317788de9  b
UN  10.240.145.130  56.31 KB   256     30.6%             76025d1d-b5e4-4510-afd9-e0c52ae4aa2b  b
UN  10.240.194.231  60.94 KB   256     36.2%             1c5594d6-4a62-4cb7-bb4e-ab15545af6a0  b

所以,一切正常。

cqlsh 命令也运行良好。

我的问题是当我运行以下命令时:

package com.example.cassandra;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Host;
import com.datastax.driver.core.Metadata;

    public class SimpleClient {
       private Cluster cluster;

       public void connect(String node, int port) {
          cluster = Cluster.builder()
               // .addContactPoints("10.240.41.185", "10.240.145.130", "10.240.194.231").withPort(port).build();
                  .addContactPoints(node).withPort(port).build();

          Metadata metadata = cluster.getMetadata();
          System.out.printf("Connected to cluster: %s\n", 
                metadata.getClusterName());
          for ( Host host : metadata.getAllHosts() ) {
             System.out.printf("Datatacenter: %s; Host: %s; Rack: %s\n",
                   host.getDatacenter(), host.getAddress(), host.getRack());
          }
       }

       public void close() {
          cluster.close();;
       }

       public static void main(String[] args) {
          SimpleClient client = new SimpleClient();
          client.connect("10.240.41.185", 9042);
          client.close();
       }
    }

然后我得到:

SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /10.240.41.185:9042 (com.datastax.driver.core.TransportException: [/10.240.41.185:9042] Cannot connect))
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:193)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1148)
    at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:313)
    at com.example.cassandra.SimpleClient.connect(SimpleClient.java:15)
    at com.example.cassandra.SimpleClient.main(SimpleClient.java:30)

在 cassandra.yaml 中:

    start_native_transport: true
    rpc_address = 0.0.0.0
    native_transport_port: 9042
listen_address: 10.240.145.130

如果我必须编辑 cassandra.yaml 文件,如果我使用的是谷歌计算引擎,我该怎么做?

谢谢

【问题讨论】:

  • 在 Cassandra 2.0.x 中,nodetool 和 cqlsh 都使用 thrift(端口 9160)与服务器通信。因此,请仔细检查您的 hodes 是否接受端口 9042 上的连接
  • 只是防火墙问题。在允许9160和9042上的流量后,模块建立了连接。
  • 好吧,我期待这样的事情:)

标签: cassandra cluster-computing yaml google-compute-engine


【解决方案1】:

这似乎是一个防火墙问题。在 9160 和 9042 都允许流量后,终于建立了连接。

【讨论】:

    【解决方案2】:

    我在我的 Centos 7 上打开了 TCP 端口 9042 和 9160,就像这样

    [root@localhost ~]# firewall-cmd --get-active-zones
    public
      interfaces: enp12s0
    [root@localhost ~]# firewall-cmd --zone=public --add-port=9042/tcp --permanent
    success
    [root@localhost ~]# firewall-cmd --zone=public --add-port=9160/tcp --permanent
    success
    [root@localhost ~]# firewall-cmd --reload
    success
    

    用于路由器 我像这样转发了端口

    和

    只是为了确保我也像这样转发了端口 7000

    然后我用http://www.canyouseeme.org检查了端口,结果如下

    和

    最后我连接了 Dbeaver :)

    我希望这会在不久的将来帮助一些人:)

    【讨论】:

      猜你喜欢
      • 2016-02-13
      • 2021-09-16
      • 2019-02-25
      • 2021-01-30
      • 2015-01-03
      • 2019-01-18
      • 2020-08-18
      • 1970-01-01
      • 2019-08-07
      相关资源
      最近更新 更多