我使用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文件,如果我使用谷歌计算引擎,我该怎么做?
由于
答案 0 :(得分:5)
这似乎是一个防火墙问题。在允许9160和9042上的流量后,最终建立连接。