All hosts tried to complete the request failed
I used google compute engine to create a 3 node cassandra cluster. After running the "nodetool state" I get:
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
So everything is working fine.
Also the cqlsh command works well.
My problem is that I am running the following:
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();
}
}
Then I get:
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)
In cassandra.yaml:
start_native_transport: true
rpc_address = 0.0.0.0
native_transport_port: 9042
listen_address: 10.240.145.130
If I need to edit the cassandra.yaml file, how can I do this if I am using Google's compute engine?
thank
+3
source to share
2 answers
I have opened TCP ports 9042 and 9160 on my Centos 7, so
[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
for router I have redirected ports this way
and just for me to forward port 7000 too like this
and then i checked the ports from http://www.canyouseeme.org and here is the result
and
and finnaly I have connected Dbeaver :)
I hope this helps some people in the near future :)
0
source to share