1

我已经完成了一个三节点 Cassandra 集群的设置。这个在aws上,服务器端口是开放的。三台服务器相互连接良好,工作完美。我已经设定

authenticator: AllowAllAuthenticator

在我的cassandra.yaml档案中

我想用go cql建立连接,这里是连接代码

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)
}

但是 go cql 将这条消息发回给我。

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
4

1 回答 1

1

您很有可能在应用程序中使用私有 IP 地址连接到节点,但这些节点无法远程访问,因为根据定义,它们是私有地址。

您需要确保已将节点配置为使用:

listen_address: <ec2_private_ip>
rpc_address: <ec2_public_ip>

节点使用 相互通信,listen_address而客户端使用 连接到集群,rpc_address这就是为什么需要使用 EC2 实例的可公开访问的 IP 地址对其进行配置的原因。

正确配置节点后,将应用配置为使用公共 IP 作为联系点:

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

这应该允许您的应用程序连接到集群。干杯!

于 2021-09-30T23:16:16.903 回答