简体   繁体   English

如何使用python从gcloud集群连接Cassandra

[英]How to connect Cassandra from gcloud cluster using python

We try to connect cluster using bash script using Jupyter notebook :我们尝试使用 Jupyter notebook 使用 bash 脚本连接集群:

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

After that we try to connect using :之后,我们尝试使用连接:

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

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

How to inter-connect both?两者如何互连? Kindly help me for it.请帮助我。

As I understand the question, you are SSHing out to a Google Compute (GCP) instance (running Cassandra) and are then trying to run a Python script to connect to the local node.据我了解,您正在通过 SSH 连接到 Google Compute (GCP) 实例(运行 Cassandra),然后尝试运行 Python 脚本以连接到本地节点。 I see two problems in your cql.connect line.我在您的cql.connect行中看到两个问题。

First, Cassandra does not use port 9160 for CQL.首先,Cassandra 不为 CQL 使用端口 9160。 CQL uses port 9042. I find this point confuses people so much, that I recommend not setting port= at all . CQL使用端口9042,我觉得这一点迷惑的人这么多,我建议您不要设置port=可言 The driver will use the default, which should work.驱动程序将使用默认值,这应该可以工作。

Secondly, if you deployed Cassandra to a GCP instance, then you probably changed listen_address and rpc_address .其次,如果您将 Cassandra 部署到 GCP 实例,那么您可能更改了listen_addressrpc_address This means Cassandra cannot bind to 127.0.0.1 .这意味着 Cassandra 不能绑定到 127.0.0.1 You need to use the value defined in the yaml's rpc_address (or broadcast_rpc_address ) property.您需要使用 yaml 的rpc_address (或broadcast_rpc_address )属性中定义的值。

$ grep rpc_address cassandra.yaml
rpc_address: 10.19.17.5

In my case, I need to specify 10.19.17.5 if I want to connect either locally or remote.就我而言,如果我想在本地或远程连接,我需要指定 10.19.17.5。

tl;dr; tl;博士;

  1. Don't specify the port.不要指定端口。
  2. Connect to your external-facing IP address, as 127.0.0.1 will never work.连接到您面向外部的 IP 地址,因为 127.0.0.1 永远不会工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python3: cassandra.cluster.NoHostAvailable: (“Unable to connect to any servers using keyspace 'test'”, ['127.0.0.1']) when using execute_async future - Python3: cassandra.cluster.NoHostAvailable: (“Unable to connect to any servers using keyspace 'test'”, ['127.0.0.1']) when using execute_async future 无法在python上连接到cassandra(使用cassandra-driver - cannot connect to cassandra on python(using cassandra-driver 如何从远程python服务连接到CDH群集 - how to connect to CDH cluster from Remote python service 无法从 Python 代码连接到 Cassandra - Unable to Connect to Cassandra from Python code dataproc 在 python 中创建集群 gcloud 等效命令 - dataproc create cluster gcloud equivalent command in python 如何将 mongodb(云)集群数据库与 python 连接 - how to connect mongodb(cloud) cluster database with python 如何使用python从cassandra输出中提取值? - How can i extract values from cassandra output using python? Cassandra Python 使用 python 驱动器从字符串执行多个语句? - Cassandra Python executing multiple statement from string using python drive? 将 Cassandra 与 Python 连接的有效方法(抑制警告) - Effective way to connect Cassandra with Python (supress warnings) 如何将文件从python上传到HPC集群? - How to upload a file from python to HPC cluster?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM