连接到Click to Deploy Cassandra实例的问题

huangapple go评论79阅读模式
英文:

Issue connecting to Click to Deploy Cassandra instance

问题

我正在尝试使用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() {
    // 连接到集群
    cluster := gocql.NewCluster(<cassandra节点的公共IP>)
    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("写入错误: %s", err.Error())
    }
}

这是错误信息:

connect: failed to connect to "<public ip>:9042": dial tcp <public ip>:9042: i/o timeout

有关如何修复此问题以在Cassandra节点上进行I/O的任何想法吗?

英文:

I'm trying to write data into Click To Deploy cassandra cluster using Golang gocql driver from a remote machine , But it fails to connect .

Here is my cassandra.yaml configuration ,

native_transport: true
listen_address: &lt;public ip&gt;
broadcast_address: &lt;public ip&gt;
rpc_address: 0.0.0.0
native_transport_port : 9042

And here is the Golang Code using which I'm remotely trying to connect

import (
    &quot;fmt&quot;
    &quot;github.com/gocql/gocql&quot;
)

func main() {
// connect to the cluster
 	cluster := gocql.NewCluster(&lt;public ip of cassandra nodes&gt;)

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

Here is the error ,
connect: failed to connect to &quot;&lt;public ip&gt;:9042&quot;: dial tcp &lt;public ip&gt; :9042: i/o timeout

Any idea on how to fix this to make i/o on the cassandra nodes ?

答案1

得分: 1

你只需要在你的GCE防火墙上打开CQL本机传输端口(tcp:9042),就可以远程连接到你的集群节点。你可以使用"telnet <公共IP> 9042"命令测试端口是否打开并监听。同时确保你的远程网络/防火墙没有阻止对端口9042的出站流量。

如果防火墙配置正确,你可以telnet到端口,但仍然收到上述错误信息,则说明你的gocql设置有问题。

英文:

You just need to open CQL native transport port (tcp:9042) on your GCE firewall to be able to connect to your cluster nodes remotely. You can use telnet &lt;public ip&gt; 9042 command to test if the port is open and listening. Also make sure the outgoing traffics to the port 9042 is not blocked on your remote network/firewall.

If the firewall is configured properly and you could telnet to the port but still receiving the mentioned error, then something is wrong with your gocql setup.

huangapple
  • 本文由 发表于 2015年8月25日 18:19:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/32201384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定