[英]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_address
和rpc_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;博士;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.