1

I have done a setup of a three node Cassandra cluster. This one is on aws, and the server port are open. The three servers are well connected to each other and work perfectly. I have set

authenticator: AllowAllAuthenticator

in my cassandra.yaml file

I would like to make the connection with go cql, here is the connection code

cluster := gocql.NewCluster("x.xxx.xxx.xxx")
cluster.Keyspace = "keyspace_name"
cluster.Consistency = gocql.Quorum
cluster.ProtoVersion = 4
cluster.ConnectTimeout = time.Second * 10

session, err := cluster.CreateSession()
if err != nil {
    fmt.Println(err)
}

but go cql sends me back this message.

2020/09/26 09:53:44 gocql: unable to dial control conn x.xxx.xxx: dial tcp 127.0.0.1:9042: connectex: No connections could be made because the target machine actively refused them.
2020/09/26 09:53:44 gocql: unable to create session: control: unable to connect to initial hosts: dial tcp x.xxx.xxx.xxx:9042: connectex: No connections could be made because the target machine actively refused them.
panic: runtime error: invalid memory address or nil pointer dereference
Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
Jesver
  • 83
  • 1
  • 6
  • 1
    Why are you connecting to local host? Was that intended? – erik258 Sep 30 '21 at 19:10
  • 1
    The error says you are trying to connect to localhost(127.0.0.1), can you make sure you are using the correct hostname? – null Sep 30 '21 at 19:11
  • @danielfarrell no It is a mistake, it connects well to server and or it is wanted that golang its in local and cassandra on a db, it is the time of the dev of the site. – Jesver Sep 30 '21 at 20:06

1 Answers1

1

There's a good chance that you're using the private IP address in your app to connect to the nodes but those are not accessible remotely because by definition, they are private addresses.

You need to make sure that you've configured your nodes to use:

listen_address: <ec2_private_ip>
rpc_address: <ec2_public_ip>

Nodes communicate with each other using the listen_address whereas clients connect to the cluster using the rpc_address which is why it needs to be configured with the publicly-accessible IP addresses of the EC2 instances.

Once you've got the nodes configured correctly, configure your app to use the public IPs as contact points in:

cluster := gocql.NewCluster("public_ip1,public_ip2,...")

This should allow your app to connect to the cluster. Cheers!

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
  • @EricRamirez Thank you for your reply, but could it be that aws asks for an authentication key? – Jesver Oct 01 '21 at 05:28
  • The error you posted doesn't have anything to do with authentication -- it's a networking issue. The node(s) is not listening for CQL connections on the IP you've configured. Cheers! – Erick Ramirez Oct 01 '21 at 08:49
  • @EricRamirez I put all the nodes in the gocql.NewCluster() but it still doesn't work, the error is the same, but my ports are open and cassandra is well configured. – Jesver Oct 01 '21 at 15:44