无法使用DataStax Python驱动程序远程连接到Cassandra [英] Unable to connect to Cassandra remotely using DataStax Python driver

查看:252
本文介绍了无法使用DataStax Python驱动程序远程连接到Cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法远程连接到Cassandra(在EC2节点上运行)(从我的笔记本电脑)。当我使用Cassandra的DataStax Python驱动程序:

 从cassandra.cluster导入集群
cluster = 10.XXX'],port = 9042)
cluster.connect()



get:

 跟踪(最近一次调用):
文件/ Users / user / virtualenvs / test / lib /python2.7/site-packages/IPython/core/interactiveshell.py,第3035行,在run_code
exec(code_obj,self.user_global_ns,self.user_ns)
文件< ipython输入-23-dc85f20fd4f5,行1,in< module>
session = cluster.connect()
文件/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py,行755,在connect
self.control_connection.connect()
文件/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py,行1868,在连接
self._set_new_connection(self._reconnect_internal())
文件/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py,行号1903,在_reconnect_internal
raise NoHostAvailable(无法连接到任何服务器,错误)
NoHostAvailable:('无法连接到任何服务器',{'10 .XXX':OperationTimedOut('errors = None,last_host = None' ,)})

但是Cassandra正在运行,因为 nodetool status 给我:

  UN 127.0.0.1 124.18 KB 256 100.0%4d973e17-ae08-3aa1-81d2-605b92753694 rack1 

Cassandra似乎也在9042号港口上侦听:

  netstat -nltp | grep 9042 

tcp6 0 0 0.0.0.0:9042 ::: * LISTEN -

我可以从笔记本电脑到Cassandra:

  $ telnet 10.XXX 9042 
尝试10。 XXX ..
已连接到ip-10-XXX。
转义字符是'^]'。

我的cassandra.yaml相关亮点:

  start_native_transport:true 
rpc_address:0.0.0.0
rpc_port:9160
broadcast_rpc_address:10.XXX



/var/log/cassandra/system.log 显示没有用。



编辑
我也可以使用 cqlsh 127.0.0.1 9042 连接到Cassandra服务器和 cqlsh 10.XXX 9042 从我的笔记本电脑没有任何问题。



>:
解决。看起来像一个地方,我测试我的脚本(PyCharm中的Python控制台)是,由于某种原因,唯一的地方,我的脚本不工作。在PyCharm或Python / iPython交互模式下作为脚本运行时没有问题。我会离开这个问题,因为它包含一个相当完整的清单,用于Python-to-Cassandra连接疑难解答。

解决方案

简单的调试方法为:
在另一台安装了cassandra的机器上,使用cassandra cli命令cqlsh 10.XXX连接远程cassandra服务器。如果失败,那么您应该修改cassandra远程模式的cassandra配置文件。


I'm having trouble connecting to Cassandra (running on an EC2 node) remotely (from my laptop). When I use the DataStax Python driver for Cassandra:

from cassandra.cluster import Cluster
cluster = Cluster(['10.X.X.X'], port=9042)
cluster.connect()

I get:

Traceback (most recent call last):
  File "/Users/user/virtualenvs/test/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-23-dc85f20fd4f5>", line 1, in <module>
    session = cluster.connect()
  File "/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py", line 755, in connect
    self.control_connection.connect()
  File "/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py", line 1868, in connect
    self._set_new_connection(self._reconnect_internal())
  File "/Users/user/virtualenvs/test/lib/python2.7/site-packages/cassandra/cluster.py", line 1903, in _reconnect_internal
    raise NoHostAvailable("Unable to connect to any servers", errors)
NoHostAvailable: ('Unable to connect to any servers', {'10.X.X.X': OperationTimedOut('errors=None, last_host=None',)})

But Cassandra is running because nodetool status gives me:

UN 127.0.0.1 124.18 KB 256 100.0% 4d973e17-ae08-3aa1-81d2-605b92753694 rack1

Cassandra also seems to be listening on port 9042:

netstat -nltp | grep 9042

tcp6       0      0 0.0.0.0:9042            :::*                    LISTEN      -

And I can telnet from my laptop to Cassandra:

$ telnet 10.X.X.X 9042
Trying 10.X.X.X...
Connected to ip-10-X-X-X.
Escape character is '^]'.

Relevant highlights from my cassandra.yaml:

start_native_transport: true
rpc_address: 0.0.0.0
rpc_port: 9160
broadcast_rpc_address: 10.X.X.X

/var/log/cassandra/system.log shows nothing useful.

edit: I can also connect to Cassandra using cqlsh 127.0.0.1 9042 on the server, and cqlsh 10.X.X.X 9042 from my laptop without any problems.

edit: Solved. Looks like the one place where I tested my script (a Python console inside PyCharm) is, for some reason, the only place where my script does not work. No problems running as a script in PyCharm or in Python/iPython interactive mode. I will leave the question, as it contains a fairly complete checklist for Python-to-Cassandra connection troubleshooting.

解决方案

Here is a simple debug method for you: On another machine which has cassandra installed, using cassandra cli command "cqlsh 10.X.X.X" to connect the remote cassandra server. If failed , then you should modify cassandra configuration file for the cassandra remote mode.

这篇关于无法使用DataStax Python驱动程序远程连接到Cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆