【问题标题】:How to connect Cassandra from gcloud cluster using python如何使用 python 从 gcloud 集群连接 Cassandra
【发布时间】:2020-05-02 06:12:35
【问题描述】:

我们尝试使用 Jupyter notebook 使用 bash 脚本连接集群:

!gcloud compute --project "project_name" ssh --zone "us-central1-a" "cassandra-abc-m"

之后我们尝试使用:

import cql
con= cql.connect(host="127.0.0.1",port=9160,keyspace="testKS")

cur=con.cursor()
result=cur.execute("select * from TestCF")

如何将两者互连? 请帮助我。

【问题讨论】:

    标签: python-3.x cassandra gcloud spark-cassandra-connector


    【解决方案1】:

    据我了解,您正在通过 SSH 连接到 Google Compute (GCP) 实例(运行 Cassandra),然后尝试运行 Python 脚本以连接到本地节点。我在您的cql.connect 行中发现了两个问题。

    首先,Cassandra 不使用端口 9160 进行 CQL。 CQL 使用端口 9042。我发现这一点让人们非常困惑,我建议不要设置 port= 根本。驱动程序将使用默认值,这应该可以工作。

    其次,如果您将 Cassandra 部署到 GCP 实例,那么您可能更改了 listen_addressrpc_address这意味着 Cassandra 无法绑定到 127.0.0.1。您需要使用 yaml 的 rpc_address(或 broadcast_rpc_address)属性中定义的值。

    $ grep rpc_address cassandra.yaml
    rpc_address: 10.19.17.5
    

    就我而言,如果我想在本地或远程连接,我需要指定 10.19.17.5。

    tl;dr;

    1. 不要指定端口。
    2. 连接到您面向外部的 IP 地址,因为 127.0.0.1 将永远无法工作。

    【讨论】:

      猜你喜欢
      • 2013-06-24
      • 1970-01-01
      • 2013-10-19
      • 2016-08-27
      • 2017-11-08
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      相关资源
      最近更新 更多