我正在尝试使用Golang gocql驱动程序从远程计算机将数据写入Click to Deploy cassandra群集,但是无法连接。

这是我的cassandra.yaml配置,

native_transport: true
listen_address: <public ip>
broadcast_address: <public ip>
rpc_address: 0.0.0.0
native_transport_port : 9042

这是我正在远程尝试使用的Golang代码
import (
    "fmt"
    "github.com/gocql/gocql"
)

func main() {
// connect to the cluster
    cluster := gocql.NewCluster(<public ip of cassandra nodes>)

    cluster.Keyspace = "demo"
    session, _ := cluster.CreateSession()
    defer session.Close()
    if err := session.Query("INSERT INTO users (lastname, firstname) VALUES ('Karthic', 'Rao')").Exec(); err != nil {
    fmt.Printf("ERror writing : ", err.Error())
    }
}

这是错误,connect: failed to connect to "<public ip>:9042": dial tcp <public ip> :9042: i/o timeout
关于如何解决此问题以在cassandra节点上进行I/O的任何想法?

最佳答案

您只需在GCE防火墙上打开CQL native 传输端口(tcp:9042)即可远程连接到群集节点。您可以使用telnet <public ip> 9042命令测试端口是否打开并正在监听。还要确保到端口9042的传出通信在您的远程网络/防火墙上没有被阻止。

如果防火墙配置正确,并且您可以通过telnet到端口,但仍收到上述错误,则说明gocql设置有问题。

关于go - 连接到Click to Deploy Cassandra实例的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32201384/

10-09 03:45