首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >DataStax Python驱动程序错误地在本地主机上发现卡桑德拉

DataStax Python驱动程序错误地在本地主机上发现卡桑德拉
EN

Stack Overflow用户
提问于 2017-11-22 19:23:52
回答 1查看 1.4K关注 0票数 1

我有一个小小的大学项目,我开发了一个简单的Python应用程序,带有Bokeh前端和Cassandra后端。我一直在一个Cassandra节点上对其进行原型化和开发,然后扩展到三个节点,一个是本地节点,两个是虚拟化节点。因此,开发是在本地主机上进行的,然后我迁移到使用一个名为vboxnet0的只有主机的网络,该网络具有IP地址:

  • 192.168.56.1为师父
  • 192.168.56.101/102为奴隶。

卡桑德拉版本为3.11.1

Bokeh服务器版本为0.12.10 (运行在“旋风”4.4.3上)

我已经相应地更改了代码,所以我的应用程序代码以:

代码语言:javascript
运行
复制
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from cassandra.query import dict_factory`

def pandas_factory(colnames, rows):
    return pd.DataFrame(rows, columns=colnames)
auth_provider = PlainTextAuthProvider(username='', password='')
cluster = Cluster(contact_points=['192.168.56.1'], port=9042, auth_provider=auth_provider)
session = cluster.connect()
session.row_factory = pandas_factory
session.default_fetch_size = None

Cassandra是在本地主机上运行的而不是

代码语言:javascript
运行
复制
username@hostname:~> cqlsh
Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})

然而Python驱动程序认为它在127.0.0.1上发现了Cassandra主机,并试图连接到它:

代码语言:javascript
运行
复制
username@hostname:~/Folder/subfolder> bokeh serve Appname > ~/bokeh.output
2017-11-22 19:24:49,230 Starting Bokeh server version 0.12.10 (running on Tornado 4.4.3)
2017-11-22 19:24:49,233 Bokeh app running at: http://localhost:5006/Appname
2017-11-22 19:24:49,233 Starting Bokeh server with process id: 5819
2017-11-22 19:25:03,281 Using datacenter 'datacenter1' for DCAwareRoundRobinPolicy (via host '192.168.56.1'); if incorrect, please specify a local_dc to the constructor, or limit contact points to local cluster nodes
2017-11-22 19:25:03,281 New Cassandra host <Host: 127.0.0.1 datacenter1> discovered
2017-11-22 19:25:03,282 Found multiple hosts with the same rpc_address (127.0.0.1). Excluding peer 192.168.56.101
2017-11-22 19:25:03,368 Failed to create connection pool for new host 127.0.0.1:
Traceback (most recent call last):
  File "cassandra/cluster.py", line 2343, in cassandra.cluster.Session.add_or_renew_pool.run_add_or_renew_pool (cassandra/cluster.c:44919)
  File "cassandra/pool.py", line 332, in cassandra.pool.HostConnection.__init__ (cassandra/pool.c:6757)
  File "cassandra/cluster.py", line 1119, in cassandra.cluster.Cluster.connection_factory (cassandra/cluster.c:16094)
  File "cassandra/connection.py", line 330, in cassandra.connection.Connection.factory (cassandra/connection.c:5963)
  File "/usr/lib64/python3.6/site-packages/cassandra/io/asyncorereactor.py", line 307, in __init__
    self._connect_socket()
  File "cassandra/connection.py", line 369, in cassandra.connection.Connection._connect_socket (cassandra/connection.c:7477)
ConnectionRefusedError: [Errno 111] Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused
2017-11-22 19:25:03,403 Host 127.0.0.1 has been marked down
2017-11-22 19:25:04,406 Error attempting to reconnect to 127.0.0.1, scheduling retry in 2.0 seconds: [Errno 111] Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused
2017-11-22 19:25:06,414 Error attempting to reconnect to 127.0.0.1, scheduling retry in 4.0 seconds: [Errno 111] Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused
2017-11-22 19:28:14,994 Error attempting to reconnect to 127.0.0.1, scheduling retry in 8.0 seconds: [Errno 111] Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused
2017-11-22 19:28:16,489 Host 127.0.0.1 may be up; will prepare queries and open connection pool
2017-11-22 19:28:16,808 Failed to create connection pool for new host 127.0.0.1:

然后它就会继续下去。在前面,它看起来不错,应用程序工作正常,192.168.56.1被正确查询,但这只是恼人的事情不对劲,我不知道它是一个错误还是我自己的错。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-24 00:51:40

首先,卡桑德拉不使用主从关系。所有节点都是平等的,因为您的任何节点都可以充当协调器。根据请求选择协调器,客户端将选择要使用的最佳协调器。然后,协调器将与负责您正在读取/写入的数据的其他节点进行协调,并返回到客户端。您在客户端中指定的联系人就是它所说的联系人。它只用于与Cassandraa集群建立初始连接。这样做后,客户端将为Cassandra集群中的每个节点保留一个连接(因为任何节点都是您请求的潜在协调者)。

回答你的问题。您的cassandra.yaml文件出错了。

代码语言:javascript
运行
复制
2017-11-22 19:25:03,282 Found multiple hosts with the same rpc_address (127.0.0.1). Excluding peer 192.168.56.101

您需要将rpc_address设置为机器的地址。确保在集群中的每个节点上都这样做。按照以下步骤确保没有遗漏任何配置:started/configuring.html#main-runtime-properties

还要确保为所有节点将种子设置为相同的ip/ips。种子仅仅是集群中一个/多个节点的ip,这些节点在启动时将连接到该节点。建议每个DC有两个种子,对于所有节点都应该是相同的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47442426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档