DataStax Python Cassandra 驱动程序错误地发现本地主机上的 Cassandra

克日谢克·塞特拉克

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

  • 192.168.56.1 为主
  • 192.168.56.101/102 为奴隶。

Cassandra 版本为 3.11.1
Bokeh 服务器版本为 0.12.10(在 Tornado 4.4.3 上运行)


我相应地更改了代码,因此我的应用程序代码开头为:

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不在本地主机上运行:

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 主机并尝试连接到它:

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 被正确查询,但这只是令人讨厌的东西不对,我不知道这是错误还是我自己的错。

西蒙·丰塔纳·奥斯卡森

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

回答你的问题。您的 cassandra.yaml 文件是错误的。

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 设置为机器的地址。确保在集群中的每个节点上执行此操作。按照以下步骤确保您没有遗漏任何配置:http : //cassandra.apache.org/doc/latest/getting_started/configuring.html#main-runtime-properties

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Cassandra模型的CQL(datastax驱动程序:python)

Datastax Cassandra驱动程序(python)导入失败

Cassandra使用datastax cassandra读取操作错误

Cassandra准备的语句错误与datastax php驱动程序

Datastax Python cassandra驱动程序构建在Ubuntu上失败

cassandra datastax驱动程序抛出的写入超时

Cassandra Datastax驱动程序-连接池

Cassandra DataStax驱动程序:如何分页浏览

Datastax Cassandra Java驱动程序的Accessor是否使用分页?

datastax cassandra java驱动程序PlainTextAuthProvider示例

Datastax-Cassandra PHP驱动程序-执行CQL脚本

Datastax Java Cassandra驱动程序:使用WHERE的多个AND语句?

Datastax C#驱动程序中的Cassandra timeuuid

带分页的Datastax Cassandra Java驱动程序RetryPolicy

Nodejs - Apache Cassandra(使用 Datastax 驱动程序)

Datastax Cassandra QueryBuilder插入错误(java)

Datastax Cassandra无根

无法使用 Cassandra Datastax Java 驱动程序连接到 Cassandra 节点之一

如何使用Datastax Java驱动程序有效地使用批写入Cassandra?

使用 Datastax Cassandra 驱动程序时出现无效类型错误

使用datastax python-driver从Cassandra获取正确的时间戳

将Datastax Enterprise Cassandra迁移到Apache Cassandra或Datastax社区?

Cassandra Datastax最佳合并选项

Datastax cassandra 似乎缓存了 preparestatent

pyspark datastax cassandra 连接器不断连接到本地主机

Python Cassandra驱动程序Readtimeout

Cassandra Python 驱动程序 ReadTimeout

如何在Cassandra中使用Datastax Java驱动程序有效地使用准备好的语句?

如何使用datastax驱动程序创建Cassandra连接池